diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index 3a7f69401..da5efb711 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -49,7 +49,9 @@ class FakeLaunchConfiguration(object): class FakeAutoScalingGroup(object): def __init__(self, name, availability_zones, desired_capacity, max_size, - min_size, launch_config_name, vpc_zone_identifier): + min_size, launch_config_name, vpc_zone_identifier, + default_cooldown, health_check_period, health_check_type, + load_balancers, placement_group, termination_policies): self.name = name self.availability_zones = availability_zones self.max_size = max_size @@ -59,11 +61,20 @@ class FakeAutoScalingGroup(object): self.launch_config_name = launch_config_name self.vpc_zone_identifier = vpc_zone_identifier + self.default_cooldown = default_cooldown if default_cooldown else DEFAULT_COOLDOWN + self.health_check_period = health_check_period + self.health_check_type = health_check_type if health_check_type else "EC2" + self.load_balancers = load_balancers + self.placement_group = placement_group + self.termination_policies = termination_policies + self.instances = [] self.set_desired_capacity(desired_capacity) def update(self, availability_zones, desired_capacity, max_size, min_size, - launch_config_name, vpc_zone_identifier): + launch_config_name, vpc_zone_identifier, default_cooldown, + health_check_period, health_check_type, load_balancers, + placement_group, termination_policies): self.availability_zones = availability_zones self.max_size = max_size self.min_size = min_size @@ -142,7 +153,10 @@ class AutoScalingBackend(BaseBackend): def create_autoscaling_group(self, name, availability_zones, desired_capacity, max_size, min_size, - launch_config_name, vpc_zone_identifier): + launch_config_name, vpc_zone_identifier, + default_cooldown, health_check_period, + health_check_type, load_balancers, + placement_group, termination_policies): group = FakeAutoScalingGroup( name=name, availability_zones=availability_zones, @@ -151,16 +165,27 @@ class AutoScalingBackend(BaseBackend): min_size=min_size, launch_config_name=launch_config_name, vpc_zone_identifier=vpc_zone_identifier, + default_cooldown=default_cooldown, + health_check_period=health_check_period, + health_check_type=health_check_type, + load_balancers=load_balancers, + placement_group=placement_group, + termination_policies=termination_policies, ) self.autoscaling_groups[name] = group return group def update_autoscaling_group(self, name, availability_zones, desired_capacity, max_size, min_size, - launch_config_name, vpc_zone_identifier): + launch_config_name, vpc_zone_identifier, + default_cooldown, health_check_period, + health_check_type, load_balancers, + placement_group, termination_policies): group = self.autoscaling_groups[name] group.update(availability_zones, desired_capacity, max_size, - min_size, launch_config_name, vpc_zone_identifier) + min_size, launch_config_name, vpc_zone_identifier, + default_cooldown, health_check_period, health_check_type, + load_balancers, placement_group, termination_policies) return group def describe_autoscaling_groups(self, names): diff --git a/moto/autoscaling/responses.py b/moto/autoscaling/responses.py index aa5d5f1a4..fe7f46b8f 100644 --- a/moto/autoscaling/responses.py +++ b/moto/autoscaling/responses.py @@ -58,6 +58,12 @@ class AutoScalingResponse(BaseResponse): min_size=self._get_int_param('MinSize'), launch_config_name=self._get_param('LaunchConfigurationName'), vpc_zone_identifier=self._get_param('VPCZoneIdentifier'), + default_cooldown=self._get_int_param('DefaultCooldown'), + health_check_period=self._get_int_param('HealthCheckGracePeriod'), + health_check_type=self._get_param('HealthCheckType'), + load_balancers=self._get_multi_param('LoadBalancerNames.member'), + placement_group=self._get_param('PlacementGroup'), + termination_policies=self._get_multi_param('TerminationPolicies.member'), ) template = Template(CREATE_AUTOSCALING_GROUP_TEMPLATE) return template.render() @@ -77,6 +83,12 @@ class AutoScalingResponse(BaseResponse): min_size=self._get_int_param('MinSize'), launch_config_name=self._get_param('LaunchConfigurationName'), vpc_zone_identifier=self._get_param('VPCZoneIdentifier'), + default_cooldown=self._get_int_param('DefaultCooldown'), + health_check_period=self._get_int_param('HealthCheckGracePeriod'), + health_check_type=self._get_param('HealthCheckType'), + load_balancers=self._get_multi_param('LoadBalancerNames.member'), + placement_group=self._get_param('PlacementGroup'), + termination_policies=self._get_multi_param('TerminationPolicies.member'), ) template = Template(UPDATE_AUTOSCALING_GROUP_TEMPLATE) return template.render() @@ -201,7 +213,7 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """ {{ group.name }} - ELB + {{ group.health_check_type }} 2013-05-06T17:47:15.107Z {{ group.launch_config_name }} @@ -212,23 +224,38 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """{{ availability_zone }} {% endfor %} - - my-test-asg-loadbalancer - + {% if group.load_balancers %} + + {% for load_balancer in group.load_balancers %} + {{ load_balancer }} + {% endfor %} + + {% else %} + + {% endif %} {{ group.min_size }} {% if group.vpc_zone_identifier %} {{ group.vpc_zone_identifier }} {% else %} {% endif %} - 120 - 300 + {{ group.health_check_period }} + {{ group.default_cooldown }} arn:aws:autoscaling:us-east-1:803981987763:autoScalingGroup:ca861182-c8f9-4ca7-b1eb-cd35505f5ebb :autoScalingGroupName/my-test-asg-lbs + {% if group.termination_policies %} - Default + {% for policy in group.termination_policies %} + {{ policy }} + {% endfor %} + {% else %} + + {% endif %} {{ group.max_size }} + {% if group.placement_group %} + {{ group.placement_group }} + {% endif %} {% endfor %} diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index ede0b6720..676833a96 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -1,9 +1,7 @@ import boto from boto.ec2.autoscale.launchconfig import LaunchConfiguration from boto.ec2.autoscale.group import AutoScalingGroup -from nose.plugins.attrib import attr -import sure # flake8: noqa -from unittest import skipIf +import sure # noqa from moto import mock_autoscaling, mock_ec2 from tests.helpers import requires_boto_gte @@ -22,11 +20,17 @@ def test_create_autoscaling_group(): group = AutoScalingGroup( name='tester_group', availability_zones=['us-east-1c', 'us-east-1b'], + default_cooldown=60, desired_capacity=2, + health_check_period=100, + health_check_type="EC2", max_size=2, min_size=2, launch_config=config, + load_balancers=["test_lb"], + placement_group="test_placement", vpc_zone_identifier='subnet-1234abcd', + termination_policies=["OldestInstance", "NewestInstance"], ) conn.create_auto_scaling_group(group) @@ -38,6 +42,12 @@ def test_create_autoscaling_group(): group.min_size.should.equal(2) group.vpc_zone_identifier.should.equal('subnet-1234abcd') group.launch_config_name.should.equal('tester') + group.default_cooldown.should.equal(60) + group.health_check_period.should.equal(100) + group.health_check_type.should.equal("EC2") + list(group.load_balancers).should.equal(["test_lb"]) + group.placement_group.should.equal("test_placement") + list(group.termination_policies).should.equal(["OldestInstance", "NewestInstance"]) @mock_autoscaling @@ -70,6 +80,12 @@ def test_create_autoscaling_groups_defaults(): list(group.availability_zones).should.equal([]) group.desired_capacity.should.equal(2) group.vpc_zone_identifier.should.equal('') + group.default_cooldown.should.equal(300) + group.health_check_period.should.equal(None) + group.health_check_type.should.equal("EC2") + list(group.load_balancers).should.equal([]) + group.placement_group.should.equal(None) + list(group.termination_policies).should.equal([]) @mock_autoscaling