Skip to content

Commit

Permalink
add mustache-support for Template-Parameters/Arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxlife committed Jun 10, 2015
1 parent afb3b52 commit a925906
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions senza/cli.py
Expand Up @@ -178,6 +178,10 @@ def evaluate(definition, args, force: bool):
info = definition.pop("SenzaInfo")
info["StackVersion"] = args.version

template = yaml.dump(definition, default_flow_style=False)
definition = evaluate_template(template, info, [], args)
definition = yaml.load(definition)

components = definition.pop("SenzaComponents", [])

# merge base template with definition
Expand Down
36 changes: 36 additions & 0 deletions tests/test_cli.py
Expand Up @@ -82,6 +82,42 @@ def test_print_basic(monkeypatch):
assert 'subnet-123' in result.output


def test_print_replace_mustache(monkeypatch):
sg = MagicMock()
sg.name = 'app-master-mind'
sg.id = 'sg-007'

monkeypatch.setattr('boto.cloudformation.connect_to_region', lambda x: MagicMock())
monkeypatch.setattr('boto.ec2.connect_to_region', lambda x: MagicMock(get_all_images=lambda filters: images,
get_all_security_groups=lambda: [sg]))
data = {'SenzaInfo': {'StackName': 'test',
'Parameters': [{'ApplicationId': { 'Description': 'Application ID from kio'}}]},
'SenzaComponents': [{'Configuration': {'ServerSubnets': {'eu-west-1': ['subnet-123']},
'Type': 'Senza::Configuration'}},
{'AppServer': {'Image': 'AppImage',
'InstanceType': 't2.micro',
'SecurityGroups': ['app-{{Arguments.ApplicationId}}'],
'IamRoles': ['app-{{Arguments.ApplicationId}}'],
'TaupageConfig': {'runtime': 'Docker',
'source': 'foo/bar'},
'Type': 'Senza::TaupageAutoScalingGroup'}}]
}


runner = CliRunner()

with runner.isolated_filesystem():
with open('myapp.yaml', 'w') as fd:
yaml.dump(data, fd)

result = runner.invoke(cli, ['print', 'myapp.yaml', '--region=myregion', '123', 'master-mind'],
catch_exceptions=False)
assert 'AWSTemplateFormatVersion' in result.output
assert 'subnet-123' in result.output
assert 'app-master-mind' in result.output
assert 'sg-007' in result.output


def test_print_auto(monkeypatch):
images = [MagicMock(name='Taupage-AMI-123', id='ami-123')]

Expand Down

0 comments on commit a925906

Please sign in to comment.