Skip to content

Commit

Permalink
Merge pull request #274 from drummerwolli/feature/optional_metrictype
Browse files Browse the repository at this point in the history
make metrictype optional
  • Loading branch information
hjacobs committed Jul 26, 2016
2 parents a1dd640 + ccc5c30 commit 46c3172
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
23 changes: 12 additions & 11 deletions senza/components/auto_scaling_group.py
Expand Up @@ -179,17 +179,18 @@ def component_auto_scaling_group(definition, configuration, args, info, force, a
}
}

metric_type = as_conf["MetricType"]
metricfns = {
"CPU": metric_cpu,
"NetworkIn": metric_network,
"NetworkOut": metric_network
}
# lowercase cpu is an acceptable metric, be compatible
if metric_type.lower() not in map(lambda t: t.lower(), metricfns.keys()):
raise click.UsageError('Auto scaling MetricType "{}" not supported.'.format(metric_type))
metricfn = metricfns[metric_type]
definition = metricfn(asg_name, definition, as_conf, args, info, force)
if "MetricType" in as_conf:
metric_type = as_conf["MetricType"]
metricfns = {
"CPU": metric_cpu,
"NetworkIn": metric_network,
"NetworkOut": metric_network
}
# lowercase cpu is an acceptable metric, be compatible
if metric_type.lower() not in map(lambda t: t.lower(), metricfns.keys()):
raise click.UsageError('Auto scaling MetricType "{}" not supported.'.format(metric_type))
metricfn = metricfns[metric_type]
definition = metricfn(asg_name, definition, as_conf, args, info, force)
else:
asg_properties["MaxSize"] = 1
asg_properties["MinSize"] = 1
Expand Down
26 changes: 26 additions & 0 deletions tests/test_components.py
Expand Up @@ -556,6 +556,32 @@ def test_component_auto_scaling_group_metric_type():
assert result["Resources"]["FooNetworkAlarmLow"]["Properties"]["AlarmDescription"] == expected_low_desc


def test_component_auto_scaling_group_optional_metric_type():
definition = {"Resources": {}}
configuration = {
'Name': 'Foo',
'InstanceType': 't2.micro',
'Image': 'foo',
'AutoScaling': {
'Minimum': 2,
'Maximum': 10,
}
}

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

info = {
'StackName': 'FooStack',
'StackVersion': 'FooVersion'
}

result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())

assert "FooCPUAlarmHigh" not in result["Resources"]
assert "FooNetworkAlarmHigh" not in result["Resources"]


def test_to_iso8601_duration():
with pytest.raises(click.UsageError):
to_iso8601_duration("")
Expand Down

0 comments on commit 46c3172

Please sign in to comment.