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
This commit is contained in:
Eoghan Glynn 2013-08-09 09:06:28 +00:00
parent 78def056db
commit 77dd72da0a
8 changed files with 30 additions and 26 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)}

View File

@ -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))

View File

@ -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})

View File

@ -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'))

View File

@ -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)

View File

@ -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)