Fix autoscaling tags (#3010)
* ENH: Add unit test for propagation tags * BUG: Add missing translation of boolean PropagateAtLaunch tag values to strings * BUG: Should really be checking for "true" and not True * CLN: Black formatting
This commit is contained in:
parent
8daafaec58
commit
31ce74a842
@ -301,6 +301,14 @@ class FakeAutoScalingGroup(BaseModel):
|
|||||||
self.availability_zones = availability_zones
|
self.availability_zones = availability_zones
|
||||||
self.vpc_zone_identifier = vpc_zone_identifier
|
self.vpc_zone_identifier = vpc_zone_identifier
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __set_string_propagate_at_launch_booleans_on_tags(tags):
|
||||||
|
bool_to_string = {True: "true", False: "false"}
|
||||||
|
for tag in tags:
|
||||||
|
if "PropagateAtLaunch" in tag:
|
||||||
|
tag["PropagateAtLaunch"] = bool_to_string[tag["PropagateAtLaunch"]]
|
||||||
|
return tags
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(
|
def create_from_cloudformation_json(
|
||||||
cls, resource_name, cloudformation_json, region_name
|
cls, resource_name, cloudformation_json, region_name
|
||||||
@ -329,7 +337,9 @@ class FakeAutoScalingGroup(BaseModel):
|
|||||||
target_group_arns=target_group_arns,
|
target_group_arns=target_group_arns,
|
||||||
placement_group=None,
|
placement_group=None,
|
||||||
termination_policies=properties.get("TerminationPolicies", []),
|
termination_policies=properties.get("TerminationPolicies", []),
|
||||||
tags=properties.get("Tags", []),
|
tags=cls.__set_string_propagate_at_launch_booleans_on_tags(
|
||||||
|
properties.get("Tags", [])
|
||||||
|
),
|
||||||
new_instances_protected_from_scale_in=properties.get(
|
new_instances_protected_from_scale_in=properties.get(
|
||||||
"NewInstancesProtectedFromScaleIn", False
|
"NewInstancesProtectedFromScaleIn", False
|
||||||
),
|
),
|
||||||
@ -455,7 +465,7 @@ class FakeAutoScalingGroup(BaseModel):
|
|||||||
# boto3 and cloudformation use PropagateAtLaunch
|
# boto3 and cloudformation use PropagateAtLaunch
|
||||||
if "propagate_at_launch" in tag and tag["propagate_at_launch"] == "true":
|
if "propagate_at_launch" in tag and tag["propagate_at_launch"] == "true":
|
||||||
propagated_tags[tag["key"]] = tag["value"]
|
propagated_tags[tag["key"]] = tag["value"]
|
||||||
if "PropagateAtLaunch" in tag and tag["PropagateAtLaunch"]:
|
if "PropagateAtLaunch" in tag and tag["PropagateAtLaunch"] == "true":
|
||||||
propagated_tags[tag["Key"]] = tag["Value"]
|
propagated_tags[tag["Key"]] = tag["Value"]
|
||||||
return propagated_tags
|
return propagated_tags
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import sure # noqa
|
|||||||
|
|
||||||
from moto import (
|
from moto import (
|
||||||
mock_autoscaling_deprecated,
|
mock_autoscaling_deprecated,
|
||||||
|
mock_autoscaling,
|
||||||
mock_cloudformation,
|
mock_cloudformation,
|
||||||
mock_cloudformation_deprecated,
|
mock_cloudformation_deprecated,
|
||||||
mock_datapipeline_deprecated,
|
mock_datapipeline_deprecated,
|
||||||
@ -2496,3 +2497,57 @@ def test_stack_events_create_rule_as_target():
|
|||||||
|
|
||||||
log_groups["logGroups"][0]["logGroupName"].should.equal(rules["Rules"][0]["Arn"])
|
log_groups["logGroups"][0]["logGroupName"].should.equal(rules["Rules"][0]["Arn"])
|
||||||
log_groups["logGroups"][0]["retentionInDays"].should.equal(3)
|
log_groups["logGroups"][0]["retentionInDays"].should.equal(3)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudformation
|
||||||
|
@mock_autoscaling
|
||||||
|
def test_autoscaling_propagate_tags():
|
||||||
|
autoscaling_group_with_tags = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Resources": {
|
||||||
|
"AutoScalingGroup": {
|
||||||
|
"Type": "AWS::AutoScaling::AutoScalingGroup",
|
||||||
|
"Properties": {
|
||||||
|
"AutoScalingGroupName": "test-scaling-group",
|
||||||
|
"DesiredCapacity": 1,
|
||||||
|
"MinSize": 1,
|
||||||
|
"MaxSize": 50,
|
||||||
|
"LaunchConfigurationName": "test-launch-config",
|
||||||
|
"AvailabilityZones": ["us-east-1a"],
|
||||||
|
"Tags": [
|
||||||
|
{
|
||||||
|
"Key": "test-key-propagate",
|
||||||
|
"Value": "test",
|
||||||
|
"PropagateAtLaunch": True,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": "test-key-no-propagate",
|
||||||
|
"Value": "test",
|
||||||
|
"PropagateAtLaunch": False,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"DependsOn": "LaunchConfig",
|
||||||
|
},
|
||||||
|
"LaunchConfig": {
|
||||||
|
"Type": "AWS::AutoScaling::LaunchConfiguration",
|
||||||
|
"Properties": {"LaunchConfigurationName": "test-launch-config"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
boto3.client("cloudformation", "us-east-1").create_stack(
|
||||||
|
StackName="propagate_tags_test",
|
||||||
|
TemplateBody=json.dumps(autoscaling_group_with_tags),
|
||||||
|
)
|
||||||
|
|
||||||
|
autoscaling = boto3.client("autoscaling", "us-east-1")
|
||||||
|
|
||||||
|
autoscaling_group_tags = autoscaling.describe_auto_scaling_groups()[
|
||||||
|
"AutoScalingGroups"
|
||||||
|
][0]["Tags"]
|
||||||
|
propagation_dict = {
|
||||||
|
tag["Key"]: tag["PropagateAtLaunch"] for tag in autoscaling_group_tags
|
||||||
|
}
|
||||||
|
|
||||||
|
assert propagation_dict["test-key-propagate"]
|
||||||
|
assert not propagation_dict["test-key-no-propagate"]
|
||||||
|
Loading…
Reference in New Issue
Block a user