Merge "s/alarm/alarm_id/ in alarm notification"

This commit is contained in:
Jenkins 2013-08-09 12:55:11 +00:00 committed by Gerrit Code Review
commit 046eefb194
8 changed files with 30 additions and 26 deletions

View File

@ -25,11 +25,11 @@ class AlarmNotifier(object):
__metaclass__ = abc.ABCMeta __metaclass__ = abc.ABCMeta
@abc.abstractmethod @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. """Notify that an alarm has been triggered.
:param action: The action that is being attended, as a parsed URL. :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 previous: The previous state of the alarm.
:param current: The current state of the alarm. :param current: The current state of the alarm.
:param reason: The reason the alarm changed its state. :param reason: The reason the alarm changed its state.

View File

@ -27,6 +27,6 @@ class LogAlarmNotifier(notifier.AlarmNotifier):
"Log alarm notifier.""" "Log alarm notifier."""
@staticmethod @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", 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.""" """Rest alarm notifier."""
@staticmethod @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", 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)
body = {'alarm': alarm, 'previous': previous, body = {'alarm_id': alarm_id, 'previous': previous,
'current': current, 'reason': reason} 'current': current, 'reason': reason}
kwargs = {'data': jsonutils.dumps(body)} kwargs = {'data': jsonutils.dumps(body)}

View File

@ -26,5 +26,9 @@ class TestAlarmNotifier(notifier.AlarmNotifier):
def __init__(self): def __init__(self):
self.notifications = [] self.notifications = []
def notify(self, action, alarm, previous, current, reason): def notify(self, action, alarm_id, previous, current, reason):
self.notifications.append((action, alarm, 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]) actions = getattr(alarm, Alarm.ALARM_ACTIONS_MAP[alarm.state])
msg = self.make_msg('notify_alarm', data={ msg = self.make_msg('notify_alarm', data={
'actions': actions, 'actions': actions,
'alarm': alarm.alarm_id, 'alarm_id': alarm.alarm_id,
'previous': previous, 'previous': previous,
'current': alarm.state, 'current': alarm.state,
'reason': reason}) 'reason': reason})

View File

@ -128,12 +128,12 @@ class AlarmNotifierService(rpc_service.Service):
'ceilometer.alarm.' + cfg.CONF.alarm.notifier_rpc_topic, '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: try:
action = network_utils.urlsplit(action) action = network_utils.urlsplit(action)
except Exception: except Exception:
LOG.error( LOG.error(
_("Unable to parse action %(action)s for alarm %(alarm)s"), _("Unable to parse action %(action)s for alarm %(alarm_id)s"),
locals()) locals())
return return
@ -142,17 +142,17 @@ class AlarmNotifierService(rpc_service.Service):
except KeyError: except KeyError:
scheme = action.scheme scheme = action.scheme
LOG.error( LOG.error(
_("Action %(scheme)s for alarm %(alarm)s is unknown, " _("Action %(scheme)s for alarm %(alarm_id)s is unknown, "
"cannot notify"), "cannot notify"),
locals()) locals())
return return
try: try:
LOG.debug("Notifying alarm %s with action %s", LOG.debug("Notifying alarm %s with action %s",
alarm, action) alarm_id, action)
notifier.notify(action, alarm, previous, current, reason) notifier.notify(action, alarm_id, previous, current, reason)
except Exception: except Exception:
LOG.exception(_("Unable to notify alarm %s"), alarm) LOG.exception(_("Unable to notify alarm %s"), alarm_id)
return return
def notify_alarm(self, context, data): def notify_alarm(self, context, data):
@ -161,7 +161,7 @@ class AlarmNotifierService(rpc_service.Service):
data should be a dict with the following keys: data should be a dict with the following keys:
- actions, the URL of the action to run; - actions, the URL of the action to run;
this is a mapped to extensions automatically 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 - previous, the previous state of the alarm
- current, the new state the alarm has transitioned to - current, the new state the alarm has transitioned to
- reason, the reason the alarm changed its state - reason, the reason the alarm changed its state
@ -176,7 +176,7 @@ class AlarmNotifierService(rpc_service.Service):
for action in actions: for action in actions:
self._handle_action(action, self._handle_action(action,
data.get('alarm'), data.get('alarm_id'),
data.get('previous'), data.get('previous'),
data.get('current'), data.get('current'),
data.get('reason')) data.get('reason'))

View File

@ -26,9 +26,9 @@ from ceilometer.openstack.common import context
from ceilometer.tests import base from ceilometer.tests import base
DATA_JSON = ('{"current": "ALARM", "alarm": "foobar",' DATA_JSON = ('{"current": "ALARM", "alarm_id": "foobar",'
' "reason": "what ?", "previous": "OK"}') ' "reason": "what ?", "previous": "OK"}')
NOTIFICATION = dict(alarm='foobar', NOTIFICATION = dict(alarm_id='foobar',
condition=dict(threshold=42), condition=dict(threshold=42),
reason='what ?', reason='what ?',
previous='OK', previous='OK',
@ -52,7 +52,7 @@ class TestAlarmNotifier(base.TestCase):
def test_notify_alarm(self): def test_notify_alarm(self):
data = { data = {
'actions': ['test://'], 'actions': ['test://'],
'alarm': 'foobar', 'alarm_id': 'foobar',
'previous': 'OK', 'previous': 'OK',
'current': 'ALARM', 'current': 'ALARM',
'reason': 'Everything is on fire', 'reason': 'Everything is on fire',
@ -62,7 +62,7 @@ class TestAlarmNotifier(base.TestCase):
self.assertEqual(len(notifications), 1) self.assertEqual(len(notifications), 1)
self.assertEqual(notifications[0], ( self.assertEqual(notifications[0], (
urlparse.urlsplit(data['actions'][0]), urlparse.urlsplit(data['actions'][0]),
data['alarm'], data['alarm_id'],
data['previous'], data['previous'],
data['current'], data['current'],
data['reason'])) data['reason']))
@ -74,7 +74,7 @@ class TestAlarmNotifier(base.TestCase):
self.service.notify_alarm(context.get_admin_context(), self.service.notify_alarm(context.get_admin_context(),
{ {
'actions': ['log://'], 'actions': ['log://'],
'alarm': 'foobar', 'alarm_id': 'foobar',
'condition': {'threshold': 42}, 'condition': {'threshold': 42},
}) })
@ -178,7 +178,7 @@ class TestAlarmNotifier(base.TestCase):
context.get_admin_context(), context.get_admin_context(),
{ {
'actions': ['no-such-action-i-am-sure'], 'actions': ['no-such-action-i-am-sure'],
'alarm': 'foobar', 'alarm_id': 'foobar',
'condition': {'threshold': 42}, 'condition': {'threshold': 42},
}) })
self.assertTrue(LOG.error.called) self.assertTrue(LOG.error.called)
@ -190,7 +190,7 @@ class TestAlarmNotifier(base.TestCase):
context.get_admin_context(), context.get_admin_context(),
{ {
'actions': ['no-such-action-i-am-sure://'], 'actions': ['no-such-action-i-am-sure://'],
'alarm': 'foobar', 'alarm_id': 'foobar',
'condition': {'threshold': 42}, 'condition': {'threshold': 42},
}) })
self.assertTrue(LOG.error.called) self.assertTrue(LOG.error.called)

View File

@ -81,7 +81,7 @@ class TestRPCAlarmNotifier(base.TestCase):
actions = getattr(a, AlarmModel.ALARM_ACTIONS_MAP[a.state]) actions = getattr(a, AlarmModel.ALARM_ACTIONS_MAP[a.state])
self.assertEqual(self.notified[i][0], self.assertEqual(self.notified[i][0],
cfg.CONF.alarm.notifier_rpc_topic) 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.alarms[i].alarm_id)
self.assertEqual(self.notified[i][1]["args"]["data"]["actions"], self.assertEqual(self.notified[i][1]["args"]["data"]["actions"],
actions) actions)