From 77dd72da0a60463d85e04f519f456ace0c80225f Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Fri, 9 Aug 2013 09:06:28 +0000 Subject: [PATCH] s/alarm/alarm_id/ in alarm notification During the review cycle for the alarm notifier, the notification payload was changed from containing the entire alarm representation to just the alarm UUID. However, the field name remained as 'alarm' which could be confusing. Hence, we change this to alarm_id. Change-Id: I5d9409df92010c7c89ad1f108b074bbf8487bb90 --- ceilometer/alarm/notifier/__init__.py | 4 ++-- ceilometer/alarm/notifier/log.py | 4 ++-- ceilometer/alarm/notifier/rest.py | 6 +++--- ceilometer/alarm/notifier/test.py | 8 ++++++-- ceilometer/alarm/rpc.py | 2 +- ceilometer/alarm/service.py | 16 ++++++++-------- tests/alarm/test_notifier.py | 14 +++++++------- tests/alarm/test_rpc.py | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ceilometer/alarm/notifier/__init__.py b/ceilometer/alarm/notifier/__init__.py index bd8ffd01b..5ac58e48a 100644 --- a/ceilometer/alarm/notifier/__init__.py +++ b/ceilometer/alarm/notifier/__init__.py @@ -25,11 +25,11 @@ class AlarmNotifier(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod - def notify(self, action, alarm, previous, current, reason): + def notify(self, action, alarm_id, previous, current, reason): """Notify that an alarm has been triggered. :param action: The action that is being attended, as a parsed URL. - :param alarm: The triggered alarm. + :param alarm_id: The triggered alarm. :param previous: The previous state of the alarm. :param current: The current state of the alarm. :param reason: The reason the alarm changed its state. diff --git a/ceilometer/alarm/notifier/log.py b/ceilometer/alarm/notifier/log.py index d3bc59831..529a9ea13 100644 --- a/ceilometer/alarm/notifier/log.py +++ b/ceilometer/alarm/notifier/log.py @@ -27,6 +27,6 @@ class LogAlarmNotifier(notifier.AlarmNotifier): "Log alarm notifier.""" @staticmethod - def notify(action, alarm, previous, current, reason): + def notify(action, alarm_id, previous, current, reason): LOG.info("Notifying alarm %s from %s to %s with action %s because %s", - alarm, previous, current, action, reason) + alarm_id, previous, current, action, reason) diff --git a/ceilometer/alarm/notifier/rest.py b/ceilometer/alarm/notifier/rest.py index 487d50185..2bafabbea 100644 --- a/ceilometer/alarm/notifier/rest.py +++ b/ceilometer/alarm/notifier/rest.py @@ -53,10 +53,10 @@ class RestAlarmNotifier(notifier.AlarmNotifier): """Rest alarm notifier.""" @staticmethod - def notify(action, alarm, previous, current, reason): + def notify(action, alarm_id, previous, current, reason): LOG.info("Notifying alarm %s from %s to %s with action %s because %s", - alarm, previous, current, action, reason) - body = {'alarm': alarm, 'previous': previous, + alarm_id, previous, current, action, reason) + body = {'alarm_id': alarm_id, 'previous': previous, 'current': current, 'reason': reason} kwargs = {'data': jsonutils.dumps(body)} diff --git a/ceilometer/alarm/notifier/test.py b/ceilometer/alarm/notifier/test.py index b8a024ce3..8f1daa04d 100644 --- a/ceilometer/alarm/notifier/test.py +++ b/ceilometer/alarm/notifier/test.py @@ -26,5 +26,9 @@ class TestAlarmNotifier(notifier.AlarmNotifier): def __init__(self): self.notifications = [] - def notify(self, action, alarm, previous, current, reason): - self.notifications.append((action, alarm, previous, current, reason)) + def notify(self, action, alarm_id, previous, current, reason): + self.notifications.append((action, + alarm_id, + previous, + current, + reason)) diff --git a/ceilometer/alarm/rpc.py b/ceilometer/alarm/rpc.py index 0b3f119c3..afe6cc120 100644 --- a/ceilometer/alarm/rpc.py +++ b/ceilometer/alarm/rpc.py @@ -41,7 +41,7 @@ class RPCAlarmNotifier(rpc_proxy.RpcProxy): actions = getattr(alarm, Alarm.ALARM_ACTIONS_MAP[alarm.state]) msg = self.make_msg('notify_alarm', data={ 'actions': actions, - 'alarm': alarm.alarm_id, + 'alarm_id': alarm.alarm_id, 'previous': previous, 'current': alarm.state, 'reason': reason}) diff --git a/ceilometer/alarm/service.py b/ceilometer/alarm/service.py index 792ddb3bf..cb170b43a 100644 --- a/ceilometer/alarm/service.py +++ b/ceilometer/alarm/service.py @@ -128,12 +128,12 @@ class AlarmNotifierService(rpc_service.Service): 'ceilometer.alarm.' + cfg.CONF.alarm.notifier_rpc_topic, ) - def _handle_action(self, action, alarm, previous, current, reason): + def _handle_action(self, action, alarm_id, previous, current, reason): try: action = network_utils.urlsplit(action) except Exception: LOG.error( - _("Unable to parse action %(action)s for alarm %(alarm)s"), + _("Unable to parse action %(action)s for alarm %(alarm_id)s"), locals()) return @@ -142,17 +142,17 @@ class AlarmNotifierService(rpc_service.Service): except KeyError: scheme = action.scheme LOG.error( - _("Action %(scheme)s for alarm %(alarm)s is unknown, " + _("Action %(scheme)s for alarm %(alarm_id)s is unknown, " "cannot notify"), locals()) return try: LOG.debug("Notifying alarm %s with action %s", - alarm, action) - notifier.notify(action, alarm, previous, current, reason) + alarm_id, action) + notifier.notify(action, alarm_id, previous, current, reason) except Exception: - LOG.exception(_("Unable to notify alarm %s"), alarm) + LOG.exception(_("Unable to notify alarm %s"), alarm_id) return def notify_alarm(self, context, data): @@ -161,7 +161,7 @@ class AlarmNotifierService(rpc_service.Service): data should be a dict with the following keys: - actions, the URL of the action to run; this is a mapped to extensions automatically - - alarm, the alarm that has been triggered + - alarm_id, the ID of the alarm that has been triggered - previous, the previous state of the alarm - current, the new state the alarm has transitioned to - reason, the reason the alarm changed its state @@ -176,7 +176,7 @@ class AlarmNotifierService(rpc_service.Service): for action in actions: self._handle_action(action, - data.get('alarm'), + data.get('alarm_id'), data.get('previous'), data.get('current'), data.get('reason')) diff --git a/tests/alarm/test_notifier.py b/tests/alarm/test_notifier.py index 911b9986d..3d71b75e6 100644 --- a/tests/alarm/test_notifier.py +++ b/tests/alarm/test_notifier.py @@ -26,9 +26,9 @@ from ceilometer.openstack.common import context from ceilometer.tests import base -DATA_JSON = ('{"current": "ALARM", "alarm": "foobar",' +DATA_JSON = ('{"current": "ALARM", "alarm_id": "foobar",' ' "reason": "what ?", "previous": "OK"}') -NOTIFICATION = dict(alarm='foobar', +NOTIFICATION = dict(alarm_id='foobar', condition=dict(threshold=42), reason='what ?', previous='OK', @@ -52,7 +52,7 @@ class TestAlarmNotifier(base.TestCase): def test_notify_alarm(self): data = { 'actions': ['test://'], - 'alarm': 'foobar', + 'alarm_id': 'foobar', 'previous': 'OK', 'current': 'ALARM', 'reason': 'Everything is on fire', @@ -62,7 +62,7 @@ class TestAlarmNotifier(base.TestCase): self.assertEqual(len(notifications), 1) self.assertEqual(notifications[0], ( urlparse.urlsplit(data['actions'][0]), - data['alarm'], + data['alarm_id'], data['previous'], data['current'], data['reason'])) @@ -74,7 +74,7 @@ class TestAlarmNotifier(base.TestCase): self.service.notify_alarm(context.get_admin_context(), { 'actions': ['log://'], - 'alarm': 'foobar', + 'alarm_id': 'foobar', 'condition': {'threshold': 42}, }) @@ -178,7 +178,7 @@ class TestAlarmNotifier(base.TestCase): context.get_admin_context(), { 'actions': ['no-such-action-i-am-sure'], - 'alarm': 'foobar', + 'alarm_id': 'foobar', 'condition': {'threshold': 42}, }) self.assertTrue(LOG.error.called) @@ -190,7 +190,7 @@ class TestAlarmNotifier(base.TestCase): context.get_admin_context(), { 'actions': ['no-such-action-i-am-sure://'], - 'alarm': 'foobar', + 'alarm_id': 'foobar', 'condition': {'threshold': 42}, }) self.assertTrue(LOG.error.called) diff --git a/tests/alarm/test_rpc.py b/tests/alarm/test_rpc.py index 28dcffa75..98bcac778 100644 --- a/tests/alarm/test_rpc.py +++ b/tests/alarm/test_rpc.py @@ -81,7 +81,7 @@ class TestRPCAlarmNotifier(base.TestCase): actions = getattr(a, AlarmModel.ALARM_ACTIONS_MAP[a.state]) self.assertEqual(self.notified[i][0], cfg.CONF.alarm.notifier_rpc_topic) - self.assertEqual(self.notified[i][1]["args"]["data"]["alarm"], + self.assertEqual(self.notified[i][1]["args"]["data"]["alarm_id"], self.alarms[i].alarm_id) self.assertEqual(self.notified[i][1]["args"]["data"]["actions"], actions)