Skip to content

Commit

Permalink
Merge pull request #565 from zalando-stups/fix-ami-for-elastigroups
Browse files Browse the repository at this point in the history
add discovery of other standard STUPS AMIs for Elastigroups
  • Loading branch information
pc-alves authored May 24, 2019
2 parents 235c2a4 + f285988 commit e9f8472
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions senza/components/elastigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def component_elastigroup(definition, configuration, args, info, force, account_
extract_user_data(configuration, elastigroup_config, info, force, account_info)
extract_load_balancer_name(configuration, elastigroup_config)
extract_public_ips(configuration, elastigroup_config)
extract_image_id(elastigroup_config)
extract_image_id(configuration, elastigroup_config)
extract_security_group_ids(configuration, elastigroup_config, args)
extract_instance_types(configuration, elastigroup_config)
extract_autoscaling_capacity(configuration, elastigroup_config)
Expand Down Expand Up @@ -497,7 +497,7 @@ def extract_public_ips(configuration, elastigroup_config):
]


def extract_image_id(elastigroup_config: dict):
def extract_image_id(configuration, elastigroup_config: dict):
"""
This function identifies whether a senza formatted AMI mapping is configured,
if so it transforms it into a Spotinst Elastigroup AMI API configuration
Expand All @@ -506,7 +506,8 @@ def extract_image_id(elastigroup_config: dict):
launch_spec_config = elastigroup_config["compute"]["launchSpecification"]

if "imageId" not in launch_spec_config.keys():
launch_spec_config["imageId"] = {"Fn::FindInMap": ["Images", {"Ref": "AWS::Region"}, "LatestTaupageImage"]}
image_key = configuration.get("Image", "LatestTaupageImage")
launch_spec_config["imageId"] = {"Fn::FindInMap": ["Images", {"Ref": "AWS::Region"}, image_key]}


def extract_security_group_ids(configuration, elastigroup_config: dict, args):
Expand Down
14 changes: 12 additions & 2 deletions tests/test_elastigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def test_component_elastigroup_defaults(monkeypatch):
assert {'tagKey': 'StackName', 'tagValue': 'foobar'} in tags
assert {'tagKey': 'StackVersion', 'tagValue': '0.1'} in tags
assert properties["group"]["compute"]["product"] == ELASTIGROUP_DEFAULT_PRODUCT
assert properties["group"]["compute"]["subnetIds"] == {"Fn::FindInMap": ["ServerSubnets", {"Ref": "AWS::Region"}, "Subnets"]}
assert properties["group"]["compute"]["subnetIds"] == {
"Fn::FindInMap": ["ServerSubnets", {"Ref": "AWS::Region"}, "Subnets"]}
assert properties["group"]["region"] == "reg1"
assert properties["group"]["strategy"] == ELASTIGROUP_DEFAULT_STRATEGY

Expand Down Expand Up @@ -666,19 +667,28 @@ def test_public_ips():
def test_extract_image_id():
test_cases = [
{ # default behavior - set latest taupage image
"input": {},
"given_config": {},
"expected_config": {"compute": {"launchSpecification": {
"imageId": {"Fn::FindInMap": ["Images", {"Ref": "AWS::Region"}, "LatestTaupageImage"]}
}}},
},
{ # leave imageId untouched
"input": {},
"given_config": {"compute": {"launchSpecification": {"imageId": "fake-id"}}},
"expected_config": {"compute": {"launchSpecification": {"imageId": "fake-id"}}},
},
{ # use specified image from the Senza mapping
"input": {"Image": "Foo"},
"given_config": {},
"expected_config": {"compute": {"launchSpecification": {
"imageId": {"Fn::FindInMap": ["Images", {"Ref": "AWS::Region"}, "Foo"]}
}}},
}
]
for test_case in test_cases:
got = test_case["given_config"]
extract_image_id(got)
extract_image_id(test_case["input"], got)
assert test_case["expected_config"] == got


Expand Down

0 comments on commit e9f8472

Please sign in to comment.