Merge pull request #976 from carleton-stripe/asg-tags
Improve instance tag handling for ASGs
This commit is contained in:
commit
e079fab9e3
@ -9,6 +9,8 @@ from moto.elb.exceptions import LoadBalancerNotFoundError
|
|||||||
# http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AS_Concepts.html#Cooldown
|
# http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AS_Concepts.html#Cooldown
|
||||||
DEFAULT_COOLDOWN = 300
|
DEFAULT_COOLDOWN = 300
|
||||||
|
|
||||||
|
ASG_NAME_TAG = "aws:autoscaling:groupName"
|
||||||
|
|
||||||
|
|
||||||
class InstanceState(object):
|
class InstanceState(object):
|
||||||
|
|
||||||
@ -169,8 +171,8 @@ class FakeAutoScalingGroup(BaseModel):
|
|||||||
self.termination_policies = termination_policies
|
self.termination_policies = termination_policies
|
||||||
|
|
||||||
self.instance_states = []
|
self.instance_states = []
|
||||||
self.set_desired_capacity(desired_capacity)
|
|
||||||
self.tags = tags if tags else []
|
self.tags = tags if tags else []
|
||||||
|
self.set_desired_capacity(desired_capacity)
|
||||||
|
|
||||||
@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):
|
||||||
@ -261,12 +263,17 @@ class FakeAutoScalingGroup(BaseModel):
|
|||||||
# Need more instances
|
# Need more instances
|
||||||
count_needed = int(self.desired_capacity) - \
|
count_needed = int(self.desired_capacity) - \
|
||||||
int(curr_instance_count)
|
int(curr_instance_count)
|
||||||
|
|
||||||
|
propagated_tags = {t['key']: t['value'] for t in self.tags
|
||||||
|
if t['propagate_at_launch'] == 'true'}
|
||||||
|
propagated_tags[ASG_NAME_TAG] = self.name
|
||||||
reservation = self.autoscaling_backend.ec2_backend.add_instances(
|
reservation = self.autoscaling_backend.ec2_backend.add_instances(
|
||||||
self.launch_config.image_id,
|
self.launch_config.image_id,
|
||||||
count_needed,
|
count_needed,
|
||||||
self.launch_config.user_data,
|
self.launch_config.user_data,
|
||||||
self.launch_config.security_groups,
|
self.launch_config.security_groups,
|
||||||
instance_type=self.launch_config.instance_type,
|
instance_type=self.launch_config.instance_type,
|
||||||
|
tags={'instance': propagated_tags}
|
||||||
)
|
)
|
||||||
for instance in reservation.instances:
|
for instance in reservation.instances:
|
||||||
instance.autoscaling_group = self
|
instance.autoscaling_group = self
|
||||||
|
@ -8,7 +8,7 @@ from boto.ec2.autoscale import Tag
|
|||||||
import boto.ec2.elb
|
import boto.ec2.elb
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_autoscaling_deprecated
|
from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_autoscaling_deprecated, mock_ec2
|
||||||
from tests.helpers import requires_boto_gte
|
from tests.helpers import requires_boto_gte
|
||||||
|
|
||||||
|
|
||||||
@ -138,6 +138,30 @@ def test_list_many_autoscaling_groups():
|
|||||||
groups.should.have.length_of(51)
|
groups.should.have.length_of(51)
|
||||||
assert 'NextToken' not in response2.keys()
|
assert 'NextToken' not in response2.keys()
|
||||||
|
|
||||||
|
@mock_autoscaling
|
||||||
|
@mock_ec2
|
||||||
|
def test_list_many_autoscaling_groups():
|
||||||
|
conn = boto3.client('autoscaling', region_name='us-east-1')
|
||||||
|
conn.create_launch_configuration(LaunchConfigurationName='TestLC')
|
||||||
|
|
||||||
|
conn.create_auto_scaling_group(AutoScalingGroupName='TestGroup1',
|
||||||
|
MinSize=1,
|
||||||
|
MaxSize=2,
|
||||||
|
LaunchConfigurationName='TestLC',
|
||||||
|
Tags=[{
|
||||||
|
"ResourceId": 'TestGroup1',
|
||||||
|
"ResourceType": "auto-scaling-group",
|
||||||
|
"PropagateAtLaunch": True,
|
||||||
|
"Key": 'TestTagKey1',
|
||||||
|
"Value": 'TestTagValue1'
|
||||||
|
}])
|
||||||
|
|
||||||
|
ec2 = boto3.client('ec2', region_name='us-east-1')
|
||||||
|
instances = ec2.describe_instances()
|
||||||
|
|
||||||
|
tags = instances['Reservations'][0]['Instances'][0]['Tags']
|
||||||
|
tags.should.contain({u'Value': 'TestTagValue1', u'Key': 'TestTagKey1'})
|
||||||
|
tags.should.contain({u'Value': 'TestGroup1', u'Key': 'aws:autoscaling:groupName'})
|
||||||
|
|
||||||
@mock_autoscaling_deprecated
|
@mock_autoscaling_deprecated
|
||||||
def test_autoscaling_group_describe_filter():
|
def test_autoscaling_group_describe_filter():
|
||||||
|
Loading…
Reference in New Issue
Block a user