Fix: Adding alarm arn to describe alarms response (#3409)
* Fix: adding alarm arn to describe alarms response * Fix:Delete subscriptions on delete topic * modified tests Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
parent
68e3d394ab
commit
9970be2309
@ -9,7 +9,7 @@ from moto.logs import logs_backends
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.tz import tzutc
|
||||
from uuid import uuid4
|
||||
from .utils import make_arn_for_dashboard
|
||||
from .utils import make_arn_for_dashboard, make_arn_for_alarm
|
||||
from dateutil import parser
|
||||
|
||||
from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID
|
||||
@ -106,8 +106,10 @@ class FakeAlarm(BaseModel):
|
||||
insufficient_data_actions,
|
||||
unit,
|
||||
actions_enabled,
|
||||
region="us-east-1",
|
||||
):
|
||||
self.name = name
|
||||
self.alarm_arn = make_arn_for_alarm(region, DEFAULT_ACCOUNT_ID, name)
|
||||
self.namespace = namespace
|
||||
self.metric_name = metric_name
|
||||
self.metric_data_queries = metric_data_queries
|
||||
@ -280,6 +282,7 @@ class CloudWatchBackend(BaseBackend):
|
||||
insufficient_data_actions,
|
||||
unit,
|
||||
actions_enabled,
|
||||
region="us-east-1",
|
||||
):
|
||||
alarm = FakeAlarm(
|
||||
name,
|
||||
@ -299,7 +302,9 @@ class CloudWatchBackend(BaseBackend):
|
||||
insufficient_data_actions,
|
||||
unit,
|
||||
actions_enabled,
|
||||
region,
|
||||
)
|
||||
|
||||
self.alarms[name] = alarm
|
||||
return alarm
|
||||
|
||||
|
@ -80,6 +80,7 @@ class CloudWatchResponse(BaseResponse):
|
||||
insufficient_data_actions,
|
||||
unit,
|
||||
actions_enabled,
|
||||
self.region,
|
||||
)
|
||||
template = self.response_template(PUT_METRIC_ALARM_TEMPLATE)
|
||||
return template.render(alarm=alarm)
|
||||
@ -287,7 +288,7 @@ DESCRIBE_ALARMS_TEMPLATE = """<DescribeAlarmsResponse xmlns="http://monitoring.a
|
||||
<member>{{ action }}</member>
|
||||
{% endfor %}
|
||||
</AlarmActions>
|
||||
<AlarmArn>{{ alarm.arn }}</AlarmArn>
|
||||
<AlarmArn>{{ alarm.alarm_arn }}</AlarmArn>
|
||||
<AlarmConfigurationUpdatedTimestamp>{{ alarm.configuration_updated_timestamp }}</AlarmConfigurationUpdatedTimestamp>
|
||||
<AlarmDescription>{{ alarm.description }}</AlarmDescription>
|
||||
<AlarmName>{{ alarm.name }}</AlarmName>
|
||||
@ -395,7 +396,7 @@ DESCRIBE_METRIC_ALARMS_TEMPLATE = """<DescribeAlarmsForMetricResponse xmlns="htt
|
||||
<member>{{ action }}</member>
|
||||
{% endfor %}
|
||||
</AlarmActions>
|
||||
<AlarmArn>{{ alarm.arn }}</AlarmArn>
|
||||
<AlarmArn>{{ alarm.alarm_arn }}</AlarmArn>
|
||||
<AlarmConfigurationUpdatedTimestamp>{{ alarm.configuration_updated_timestamp }}</AlarmConfigurationUpdatedTimestamp>
|
||||
<AlarmDescription>{{ alarm.description }}</AlarmDescription>
|
||||
<AlarmName>{{ alarm.name }}</AlarmName>
|
||||
|
@ -3,3 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
def make_arn_for_dashboard(account_id, name):
|
||||
return "arn:aws:cloudwatch::{0}dashboard/{1}".format(account_id, name)
|
||||
|
||||
|
||||
def make_arn_for_alarm(region, account_id, alarm_name):
|
||||
return "arn:aws:cloudwatch:{0}:{1}:alarm:{2}".format(region, account_id, alarm_name)
|
||||
|
@ -3,6 +3,8 @@ from boto.ec2.cloudwatch.alarm import MetricAlarm
|
||||
from boto.s3.key import Key
|
||||
from datetime import datetime
|
||||
import sure # noqa
|
||||
from moto.cloudwatch.utils import make_arn_for_alarm
|
||||
from moto.core import ACCOUNT_ID
|
||||
|
||||
from moto import mock_cloudwatch_deprecated, mock_s3_deprecated
|
||||
|
||||
@ -51,6 +53,7 @@ def test_create_alarm():
|
||||
list(alarm.ok_actions).should.equal(["arn:ok"])
|
||||
list(alarm.insufficient_data_actions).should.equal(["arn:insufficient"])
|
||||
alarm.unit.should.equal("Seconds")
|
||||
assert "tester" in alarm.alarm_arn
|
||||
|
||||
|
||||
@mock_cloudwatch_deprecated
|
||||
|
@ -10,6 +10,8 @@ import pytz
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_cloudwatch
|
||||
from moto.cloudwatch.utils import make_arn_for_alarm
|
||||
from moto.core import ACCOUNT_ID
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
@ -140,6 +142,8 @@ def test_describe_alarms_for_metric():
|
||||
alarms = conn.describe_alarms_for_metric(MetricName="cpu", Namespace="blah")
|
||||
alarms.get("MetricAlarms").should.have.length_of(1)
|
||||
|
||||
assert "testalarm1" in alarms.get("MetricAlarms")[0].get("AlarmArn")
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_describe_alarms():
|
||||
|
Loading…
Reference in New Issue
Block a user