From f7ed2c2a16e8dded6bd2258ea0a5e5954a13bada Mon Sep 17 00:00:00 2001 From: gordon chung Date: Thu, 5 Feb 2015 15:27:38 -0500 Subject: [PATCH] start recording error notifications projects (specifically nova) send notifications on error topic when an error occurs. we should capture this in events. Change-Id: Ic42cbce948b8b409f83934146407b2480602921d Closes-Bug: #1364708 --- ceilometer/event/endpoint.py | 17 +++++++++++++++++ ceilometer/tests/test_notification.py | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ceilometer/event/endpoint.py b/ceilometer/event/endpoint.py index 422e36db1..a13976a95 100644 --- a/ceilometer/event/endpoint.py +++ b/ceilometer/event/endpoint.py @@ -58,6 +58,23 @@ class EventsNotificationEndpoint(object): 'info', ctxt, publisher_id, event_type, payload, metadata) self.process_notification(notification) + def error(self, ctxt, publisher_id, event_type, payload, metadata): + """Convert error message to Ceilometer Event. + + :param ctxt: oslo.messaging context + :param publisher_id: publisher of the notification + :param event_type: type of notification + :param payload: notification payload + :param metadata: metadata about the notification + """ + + # NOTE: the rpc layer currently rips out the notification + # delivery_info, which is critical to determining the + # source of the notification. This will have to get added back later. + notification = messaging.convert_to_old_notification_format( + 'error', ctxt, publisher_id, event_type, payload, metadata) + self.process_notification(notification) + def process_notification(self, notification): try: event = self.event_converter.to_event(notification) diff --git a/ceilometer/tests/test_notification.py b/ceilometer/tests/test_notification.py index 42f517045..84bfb79b1 100644 --- a/ceilometer/tests/test_notification.py +++ b/ceilometer/tests/test_notification.py @@ -240,6 +240,22 @@ class TestRealNotification(BaseRealNotification): fake_publisher_cls.return_value = self.publisher self._check_notification_service() + @mock.patch('ceilometer.publisher.test.TestPublisher') + def test_notification_service_error_topic(self, fake_publisher_cls): + fake_publisher_cls.return_value = self.publisher + self.srv.start() + notifier = messaging.get_notifier(self.transport, + 'compute.vagrant-precise') + notifier.error(context.RequestContext(), 'compute.instance.error', + TEST_NOTICE_PAYLOAD) + start = timeutils.utcnow() + while timeutils.delta_seconds(start, timeutils.utcnow()) < 600: + if len(self.publisher.events) >= self.expected_events: + break + eventlet.sleep(0) + self.srv.stop() + self.assertEqual(self.expected_events, len(self.publisher.events)) + @mock.patch('ceilometer.coordination.PartitionCoordinator') @mock.patch('ceilometer.publisher.test.TestPublisher') def test_ha_configured_agent_coord_disabled(self, fake_publisher_cls,