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 <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann 2012-10-01 15:44:23 -04:00
parent 3cdac9f3d0
commit 658ea8ed33
2 changed files with 33 additions and 3 deletions

View File

@ -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='?',

View File

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