Merge pull request #434 from milesoc/master
Add tag support on create/read for autoscaling groups
This commit is contained in:
commit
96cf5eabc4
@ -113,7 +113,8 @@ class FakeAutoScalingGroup(object):
|
|||||||
def __init__(self, name, availability_zones, desired_capacity, max_size,
|
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,
|
default_cooldown, health_check_period, health_check_type,
|
||||||
load_balancers, placement_group, termination_policies, autoscaling_backend):
|
load_balancers, placement_group, termination_policies,
|
||||||
|
autoscaling_backend, tags):
|
||||||
self.autoscaling_backend = autoscaling_backend
|
self.autoscaling_backend = autoscaling_backend
|
||||||
self.name = name
|
self.name = name
|
||||||
self.availability_zones = availability_zones
|
self.availability_zones = availability_zones
|
||||||
@ -133,6 +134,7 @@ class FakeAutoScalingGroup(object):
|
|||||||
|
|
||||||
self.instance_states = []
|
self.instance_states = []
|
||||||
self.set_desired_capacity(desired_capacity)
|
self.set_desired_capacity(desired_capacity)
|
||||||
|
self.tags = tags if tags else []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||||
@ -156,6 +158,7 @@ class FakeAutoScalingGroup(object):
|
|||||||
load_balancers=load_balancer_names,
|
load_balancers=load_balancer_names,
|
||||||
placement_group=None,
|
placement_group=None,
|
||||||
termination_policies=properties.get("TerminationPolicies", []),
|
termination_policies=properties.get("TerminationPolicies", []),
|
||||||
|
tags=properties.get("Tags", []),
|
||||||
)
|
)
|
||||||
return group
|
return group
|
||||||
|
|
||||||
@ -261,7 +264,7 @@ class AutoScalingBackend(BaseBackend):
|
|||||||
launch_config_name, vpc_zone_identifier,
|
launch_config_name, vpc_zone_identifier,
|
||||||
default_cooldown, health_check_period,
|
default_cooldown, health_check_period,
|
||||||
health_check_type, load_balancers,
|
health_check_type, load_balancers,
|
||||||
placement_group, termination_policies):
|
placement_group, termination_policies, tags):
|
||||||
|
|
||||||
def make_int(value):
|
def make_int(value):
|
||||||
return int(value) if value is not None else value
|
return int(value) if value is not None else value
|
||||||
@ -286,6 +289,7 @@ class AutoScalingBackend(BaseBackend):
|
|||||||
placement_group=placement_group,
|
placement_group=placement_group,
|
||||||
termination_policies=termination_policies,
|
termination_policies=termination_policies,
|
||||||
autoscaling_backend=self,
|
autoscaling_backend=self,
|
||||||
|
tags=tags,
|
||||||
)
|
)
|
||||||
self.autoscaling_groups[name] = group
|
self.autoscaling_groups[name] = group
|
||||||
return group
|
return group
|
||||||
|
@ -60,6 +60,7 @@ class AutoScalingResponse(BaseResponse):
|
|||||||
load_balancers=self._get_multi_param('LoadBalancerNames.member'),
|
load_balancers=self._get_multi_param('LoadBalancerNames.member'),
|
||||||
placement_group=self._get_param('PlacementGroup'),
|
placement_group=self._get_param('PlacementGroup'),
|
||||||
termination_policies=self._get_multi_param('TerminationPolicies.member'),
|
termination_policies=self._get_multi_param('TerminationPolicies.member'),
|
||||||
|
tags=self._get_list_prefix('Tags.member'),
|
||||||
)
|
)
|
||||||
template = self.response_template(CREATE_AUTOSCALING_GROUP_TEMPLATE)
|
template = self.response_template(CREATE_AUTOSCALING_GROUP_TEMPLATE)
|
||||||
return template.render()
|
return template.render()
|
||||||
@ -235,7 +236,17 @@ DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE = """<DescribeAutoScalingGroupsResponse xml
|
|||||||
<AutoScalingGroups>
|
<AutoScalingGroups>
|
||||||
{% for group in groups %}
|
{% for group in groups %}
|
||||||
<member>
|
<member>
|
||||||
<Tags/>
|
<Tags>
|
||||||
|
{% for tag in group.tags %}
|
||||||
|
<member>
|
||||||
|
<ResourceType>{{ tag.resource_type }}</ResourceType>
|
||||||
|
<ResourceId>{{ tag.resource_id }}</ResourceId>
|
||||||
|
<PropagateAtLaunch>{{ tag.propagate_at_launch }}</PropagateAtLaunch>
|
||||||
|
<Key>{{ tag.key }}</Key>
|
||||||
|
<Value>{{ tag.value }}</Value>
|
||||||
|
</member>
|
||||||
|
{% endfor %}
|
||||||
|
</Tags>
|
||||||
<SuspendedProcesses/>
|
<SuspendedProcesses/>
|
||||||
<AutoScalingGroupName>{{ group.name }}</AutoScalingGroupName>
|
<AutoScalingGroupName>{{ group.name }}</AutoScalingGroupName>
|
||||||
<HealthCheckType>{{ group.health_check_type }}</HealthCheckType>
|
<HealthCheckType>{{ group.health_check_type }}</HealthCheckType>
|
||||||
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
import boto
|
import boto
|
||||||
from boto.ec2.autoscale.launchconfig import LaunchConfiguration
|
from boto.ec2.autoscale.launchconfig import LaunchConfiguration
|
||||||
from boto.ec2.autoscale.group import AutoScalingGroup
|
from boto.ec2.autoscale.group import AutoScalingGroup
|
||||||
|
from boto.ec2.autoscale import Tag
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
from moto import mock_autoscaling, mock_ec2
|
from moto import mock_autoscaling, mock_ec2
|
||||||
@ -18,6 +19,7 @@ def test_create_autoscaling_group():
|
|||||||
)
|
)
|
||||||
conn.create_launch_configuration(config)
|
conn.create_launch_configuration(config)
|
||||||
|
|
||||||
|
|
||||||
group = AutoScalingGroup(
|
group = AutoScalingGroup(
|
||||||
name='tester_group',
|
name='tester_group',
|
||||||
availability_zones=['us-east-1c', 'us-east-1b'],
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
||||||
@ -32,6 +34,13 @@ def test_create_autoscaling_group():
|
|||||||
placement_group="test_placement",
|
placement_group="test_placement",
|
||||||
vpc_zone_identifier='subnet-1234abcd',
|
vpc_zone_identifier='subnet-1234abcd',
|
||||||
termination_policies=["OldestInstance", "NewestInstance"],
|
termination_policies=["OldestInstance", "NewestInstance"],
|
||||||
|
tags=[Tag(
|
||||||
|
resource_id='tester_group',
|
||||||
|
key='test_key',
|
||||||
|
value='test_value',
|
||||||
|
propagate_at_launch=True
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
conn.create_auto_scaling_group(group)
|
conn.create_auto_scaling_group(group)
|
||||||
|
|
||||||
@ -50,6 +59,12 @@ def test_create_autoscaling_group():
|
|||||||
list(group.load_balancers).should.equal(["test_lb"])
|
list(group.load_balancers).should.equal(["test_lb"])
|
||||||
group.placement_group.should.equal("test_placement")
|
group.placement_group.should.equal("test_placement")
|
||||||
list(group.termination_policies).should.equal(["OldestInstance", "NewestInstance"])
|
list(group.termination_policies).should.equal(["OldestInstance", "NewestInstance"])
|
||||||
|
len(list(group.tags)).should.equal(1)
|
||||||
|
tag = list(group.tags)[0]
|
||||||
|
tag.resource_id.should.equal('tester_group')
|
||||||
|
tag.key.should.equal('test_key')
|
||||||
|
tag.value.should.equal('test_value')
|
||||||
|
tag.propagate_at_launch.should.equal(True)
|
||||||
|
|
||||||
|
|
||||||
@mock_autoscaling
|
@mock_autoscaling
|
||||||
@ -88,6 +103,7 @@ def test_create_autoscaling_groups_defaults():
|
|||||||
list(group.load_balancers).should.equal([])
|
list(group.load_balancers).should.equal([])
|
||||||
group.placement_group.should.equal(None)
|
group.placement_group.should.equal(None)
|
||||||
list(group.termination_policies).should.equal([])
|
list(group.termination_policies).should.equal([])
|
||||||
|
list(group.tags).should.equal([])
|
||||||
|
|
||||||
|
|
||||||
@mock_autoscaling
|
@mock_autoscaling
|
||||||
|
Loading…
Reference in New Issue
Block a user