Fix notification for NotImplemented record_events

With mongodb as storage backend, notification-to-sample will be broken by
NotImplementedError of record_events() method if we have set
"store_events" option as True in ceilometer.conf.

This patch catch the NotImplementedError and enable the
notification-to-sample process.

Change-Id: I7ace5a8581518fa56e58abca2e377b513ff38675
Closes-Bug: #1320420
This commit is contained in:
liu-sheng 2014-06-03 17:43:54 +08:00
parent 4ed4559f47
commit 48e30f52d4
2 changed files with 15 additions and 1 deletions

View File

@ -64,7 +64,12 @@ class EventsNotificationEndpoint(object):
LOG.debug(_('Saving event "%s"'), event.event_type)
problem_events = []
for dispatcher_ext in self.dispatcher_manager:
problem_events.extend(dispatcher_ext.obj.record_events(event))
try:
problem_events.extend(
dispatcher_ext.obj.record_events(event))
except NotImplementedError:
LOG.warn(_('Event is not implemented with the storage'
' backend'))
if models.Event.UNKNOWN_PROBLEM in [x[0] for x in problem_events]:
if not cfg.CONF.notification.ack_on_event_error:
return oslo.messaging.NotificationResult.REQUEUE

View File

@ -101,6 +101,15 @@ class TestEventEndpoint(tests_base.BaseTestCase):
self.endpoint.event_converter.to_event.return_value = mock.MagicMock(
event_type='test.test')
@mock.patch('ceilometer.event.endpoint.LOG')
def test_event_not_implemented(self, log):
self.mock_dispatcher.record_events.side_effect = NotImplementedError
message = {'event_type': "foo", 'message_id': "abc"}
ret = self.endpoint.process_notification(message)
log.warn.assert_called_once_with(
'Event is not implemented with the storage backend')
self.assertEqual(oslo.messaging.NotificationResult.HANDLED, ret)
def test_message_to_event(self):
self.endpoint.info(TEST_NOTICE_CTXT, 'compute.vagrant-precise',
'compute.instance.create.end',