From 658ea8ed33c183c7ccfffe33227f3151878a723e Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 1 Oct 2012 15:44:23 -0400 Subject: [PATCH] Fix quantum notification subscriptions Correct a problem with the way the notification event_type names were constructed in get_event_types() and ignore delete events for now since they do not include the relevant metadata. Change-Id: I313727203a215118d3b9faabdd3f7600efb7be32 Signed-off-by: Doug Hellmann --- ceilometer/network/notifications.py | 18 +++++++++++++++--- tests/network/test_notifications.py | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index 5c7c67c6a6..2ad53e9355 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -23,6 +23,7 @@ from ceilometer import counter from ceilometer import plugin from ceilometer.openstack.common import cfg +from ceilometer.openstack.common import log as logging OPTS = [ @@ -34,14 +35,24 @@ OPTS = [ cfg.CONF.register_opts(OPTS) +LOG = logging.getLogger(__name__) + class NetworkNotificationBase(plugin.NotificationBase): + resource_name = None + def get_event_types(self): return [ - '%s.create.end' % (self.resource_name, event), - '%s.update.end' % (self.resource_name, event), - '%s.delete.start' % (self.resource_name, event), + '%s.create.end' % (self.resource_name), + '%s.update.end' % (self.resource_name), + # FIXME(dhellmann): Quantum delete notifications do + # not include the same metadata as the other messages, + # so we ignore them for now. This isn't ideal, since + # it may mean we miss charging for some amount of time, + # but it is better than throwing away the existing + # metadata for a resource when it is deleted. + ##'%s.delete.start' % (self.resource_name), ] @staticmethod @@ -56,6 +67,7 @@ class NetworkNotificationBase(plugin.NotificationBase): ] def process_notification(self, message): + LOG.info('network notification %r', message) message['payload'] = message['payload'][self.resource_name] return [ counter.Counter(source='?', diff --git a/tests/network/test_notifications.py b/tests/network/test_notifications.py index 71d9268e68..99f66e0df9 100644 --- a/tests/network/test_notifications.py +++ b/tests/network/test_notifications.py @@ -153,3 +153,21 @@ class TestNotifications(unittest.TestCase): v = notifications.Port() counters = v.process_notification(NOTIFICATION_PORT_UPDATE) self.assertEqual(len(counters), 2) + + +class TestEventTypes(unittest.TestCase): + + def test_network(self): + v = notifications.Network() + events = v.get_event_types() + assert events + + def test_subnet(self): + v = notifications.Subnet() + events = v.get_event_types() + assert events + + def test_port(self): + v = notifications.Port() + events = v.get_event_types() + assert events