Merge pull request #674 from IlyaSukhanov/master

Preserve Namespace and MetricName when creating cloudwatch alarm.
This commit is contained in:
Steve Pulec 2016-08-27 21:05:31 -04:00 committed by GitHub
commit 18b6197bf2
4 changed files with 15 additions and 6 deletions

View File

@ -10,10 +10,12 @@ class Dimension(object):
class FakeAlarm(object):
def __init__(self, name, comparison_operator, evaluation_periods, period,
threshold, statistic, description, dimensions, alarm_actions,
def __init__(self, name, namespace, metric_name, comparison_operator, evaluation_periods,
period, threshold, statistic, description, dimensions, alarm_actions,
ok_actions, insufficient_data_actions, unit):
self.name = name
self.namespace = namespace
self.metric_name = metric_name
self.comparison_operator = comparison_operator
self.evaluation_periods = evaluation_periods
self.period = period
@ -43,10 +45,10 @@ class CloudWatchBackend(BaseBackend):
self.alarms = {}
self.metric_data = []
def put_metric_alarm(self, name, comparison_operator, evaluation_periods,
def put_metric_alarm(self, name, namespace, metric_name, comparison_operator, evaluation_periods,
period, threshold, statistic, description, dimensions,
alarm_actions, ok_actions, insufficient_data_actions, unit):
alarm = FakeAlarm(name, comparison_operator, evaluation_periods, period,
alarm = FakeAlarm(name, namespace, metric_name, comparison_operator, evaluation_periods, period,
threshold, statistic, description, dimensions, alarm_actions,
ok_actions, insufficient_data_actions, unit)
self.alarms[name] = alarm

View File

@ -7,6 +7,8 @@ class CloudWatchResponse(BaseResponse):
def put_metric_alarm(self):
name = self._get_param('AlarmName')
namespace = self._get_param('Namespace')
metric_name = self._get_param('MetricName')
comparison_operator = self._get_param('ComparisonOperator')
evaluation_periods = self._get_param('EvaluationPeriods')
period = self._get_param('Period')
@ -19,7 +21,8 @@ class CloudWatchResponse(BaseResponse):
insufficient_data_actions = self._get_multi_param("InsufficientDataActions.member")
unit = self._get_param('Unit')
cloudwatch_backend = cloudwatch_backends[self.region]
alarm = cloudwatch_backend.put_metric_alarm(name, comparison_operator,
alarm = cloudwatch_backend.put_metric_alarm(name, namespace, metric_name,
comparison_operator,
evaluation_periods, period,
threshold, statistic,
description, dimensions,

View File

@ -22,7 +22,7 @@ extras_require = {
setup(
name='moto',
version='0.4.25',
version='0.4.26',
description='A library that allows your python tests to easily'
' mock out the boto library',
author='Steve Pulec',

View File

@ -8,6 +8,8 @@ def alarm_fixture(name="tester", action=None):
action = action or ['arn:alarm']
return MetricAlarm(
name=name,
namespace="{0}_namespace".format(name),
metric="{0}_metric".format(name),
comparison='>=',
threshold=2.0,
period=60,
@ -32,6 +34,8 @@ def test_create_alarm():
alarms.should.have.length_of(1)
alarm = alarms[0]
alarm.name.should.equal('tester')
alarm.namespace.should.equal('tester_namespace')
alarm.metric.should.equal('tester_metric')
alarm.comparison.should.equal('>=')
alarm.threshold.should.equal(2.0)
alarm.period.should.equal(60)