Skip to content

Commit

Permalink
Merge pull request #414 from zalando-stups/coreos
Browse files Browse the repository at this point in the history
#402 find latest AMI for CoreOS
  • Loading branch information
hjacobs authored Nov 3, 2016
2 parents 6cc75c6 + beea2d6 commit 12a8afa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions senza/components/coreos_auto_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests

from senza.components.subnet_auto_configuration import component_subnet_auto_configuration
from senza.utils import ensure_keys


def find_coreos_image(release_channel: str, region: str):
'''Find the latest CoreOS AMI'''

response = requests.get('https://coreos.com/dist/aws/aws-{}.json'.format(release_channel), timeout=5)
response.raise_for_status()
data = response.json()
return data[region]['hvm']


def component_coreos_auto_configuration(definition, configuration, args, info, force, account_info):
ami_id = find_coreos_image(configuration.get('ReleaseChannel') or 'stable', args.region)
configuration = ensure_keys(configuration, "Images", 'LatestCoreOSImage', args.region)
configuration["Images"]['LatestCoreOSImage'][args.region] = ami_id

component_subnet_auto_configuration(definition, configuration, args, info, force, account_info)

return definition
27 changes: 27 additions & 0 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
normalize_asg_success,
normalize_network_threshold,
to_iso8601_duration)
from senza.components.coreos_auto_configuration import component_coreos_auto_configuration
from senza.components.elastic_load_balancer import (component_elastic_load_balancer,
get_load_balancer_name)
from senza.components.elastic_load_balancer_v2 import component_elastic_load_balancer_v2
Expand Down Expand Up @@ -1094,3 +1095,29 @@ def test_component_subnet_auto_configuration(monkeypatch):
}
result = component_subnet_auto_configuration(definition, configuration, args, info, False, MagicMock())
assert ['subnet-1', 'subnet-2'] == result['Mappings']['ServerSubnets']['foo']['Subnets']


def test_component_coreos_auto_configuration(monkeypatch):
configuration = {
'ReleaseChannel': 'gamma'
}
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
definition = {"Resources": {}}

args = MagicMock()
args.region = "foo"

subnet1 = MagicMock()
subnet1.id = 'subnet-1'

ec2 = MagicMock()
ec2.subnets.filter.return_value = [subnet1]

get = MagicMock()
get.return_value.json.return_value = {'foo': {'hvm': 'ami-007'}}

monkeypatch.setattr('boto3.resource', lambda *args: ec2)
monkeypatch.setattr('requests.get', get)
result = component_coreos_auto_configuration(definition, configuration, args, info, False, MagicMock())
assert 'ami-007' == result['Mappings']['Images']['foo']['LatestCoreOSImage']

0 comments on commit 12a8afa

Please sign in to comment.