Add more autoscaling params
This commit is contained in:
parent
dc4c50d13d
commit
161a5744d1
@ -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):
|
||||
|
@ -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 = """<DescribeAutoScalingGroupsResponse xml
|
||||
<Tags/>
|
||||
<SuspendedProcesses/>
|
||||
<AutoScalingGroupName>{{ group.name }}</AutoScalingGroupName>
|
||||
<HealthCheckType>ELB</HealthCheckType>
|
||||
<HealthCheckType>{{ group.health_check_type }}</HealthCheckType>
|
||||
<CreatedTime>2013-05-06T17:47:15.107Z</CreatedTime>
|
||||
<EnabledMetrics/>
|
||||
<LaunchConfigurationName>{{ group.launch_config_name }}</LaunchConfigurationName>
|
||||
@ -212,23 +224,38 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """<DescribeAutoScalingGroupsResponse xml
|
||||
<member>{{ availability_zone }}</member>
|
||||
{% endfor %}
|
||||
</AvailabilityZones>
|
||||
<LoadBalancerNames>
|
||||
<member>my-test-asg-loadbalancer</member>
|
||||
</LoadBalancerNames>
|
||||
{% if group.load_balancers %}
|
||||
<LoadBalancerNames>
|
||||
{% for load_balancer in group.load_balancers %}
|
||||
<member>{{ load_balancer }}</member>
|
||||
{% endfor %}
|
||||
</LoadBalancerNames>
|
||||
{% else %}
|
||||
<LoadBalancerNames/>
|
||||
{% endif %}
|
||||
<MinSize>{{ group.min_size }}</MinSize>
|
||||
{% if group.vpc_zone_identifier %}
|
||||
<VPCZoneIdentifier>{{ group.vpc_zone_identifier }}</VPCZoneIdentifier>
|
||||
{% else %}
|
||||
<VPCZoneIdentifier/>
|
||||
{% endif %}
|
||||
<HealthCheckGracePeriod>120</HealthCheckGracePeriod>
|
||||
<DefaultCooldown>300</DefaultCooldown>
|
||||
<HealthCheckGracePeriod>{{ group.health_check_period }}</HealthCheckGracePeriod>
|
||||
<DefaultCooldown>{{ group.default_cooldown }}</DefaultCooldown>
|
||||
<AutoScalingGroupARN>arn:aws:autoscaling:us-east-1:803981987763:autoScalingGroup:ca861182-c8f9-4ca7-b1eb-cd35505f5ebb
|
||||
:autoScalingGroupName/my-test-asg-lbs</AutoScalingGroupARN>
|
||||
{% if group.termination_policies %}
|
||||
<TerminationPolicies>
|
||||
<member>Default</member>
|
||||
{% for policy in group.termination_policies %}
|
||||
<member>{{ policy }}</member>
|
||||
{% endfor %}
|
||||
</TerminationPolicies>
|
||||
{% else %}
|
||||
<TerminationPolicies/>
|
||||
{% endif %}
|
||||
<MaxSize>{{ group.max_size }}</MaxSize>
|
||||
{% if group.placement_group %}
|
||||
<PlacementGroup>{{ group.placement_group }}</PlacementGroup>
|
||||
{% endif %}
|
||||
</member>
|
||||
{% endfor %}
|
||||
</AutoScalingGroups>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user