From 3636a044a6ec04eea4ace7cbb3b377d2f412598e Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Mon, 26 Aug 2013 09:18:18 +0000 Subject: [PATCH] Network: process metering reports from Neutron blueprint https://blueprints.launchpad.net/ceilometer/+spec/ceilometer-quantum-bw-metering Change-Id: Idbcc5843e1840ff2659a58d991f4256f56c93a4d --- ceilometer/network/notifications.py | 19 +++++++++++++++++ setup.cfg | 1 + tests/network/test_notifications.py | 32 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index d96f9b6a..f4be7181 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -140,3 +140,22 @@ class FloatingIP(NetworkNotificationBase): resource_name = 'floatingip' counter_name = 'ip.floating' unit = 'ip' + + +class Bandwidth(NetworkNotificationBase): + """Listen for Neutron notifications in order to mediate with the + metering framework. + + """ + event_types = ['l3.meter'] + + def process_notification(self, message): + yield sample.Sample.from_notification( + name='bandwidth', + type=sample.TYPE_DELTA, + unit='B', + volume=message['payload']['bytes'], + user_id=None, + project_id=message['payload']['tenant_id'], + resource_id=message['payload']['label_id'], + message=message) diff --git a/setup.cfg b/setup.cfg index 05b290c6..3ab7b064 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,6 +49,7 @@ ceilometer.collector = port = ceilometer.network.notifications:Port router = ceilometer.network.notifications:Router floatingip = ceilometer.network.notifications:FloatingIP + bandwidth = ceilometer.network.notifications:Bandwidth http.request = ceilometer.middleware:HTTPRequest http.response = ceilometer.middleware:HTTPResponse diff --git a/tests/network/test_notifications.py b/tests/network/test_notifications.py index c6cda13f..e3b8bf29 100644 --- a/tests/network/test_notifications.py +++ b/tests/network/test_notifications.py @@ -202,6 +202,29 @@ NOTIFICATION_FLOATINGIP_EXISTS = { u'publisher_id': u'network.ubuntu-VirtualBox', u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'} +NOTIFICATION_L3_METER = { + u'_context_roles': [u'admin'], + u'_context_read_deleted': u'no', + u'event_type': u'l3.meter', + u'timestamp': u'2013-08-22 13:14:06.880304', + u'_context_tenant_id': None, + u'payload': {u'first_update': 1377176476, + u'bytes': 0, + u'label_id': u'383244a7-e99b-433a-b4a1-d37cf5b17d15', + u'last_update': 1377177246, + u'host': u'precise64', + u'tenant_id': u'admin', + u'time': 30, + u'pkts': 0}, + u'priority': u'INFO', + u'_context_is_admin': True, + u'_context_timestamp': u'2013-08-22 13:01:06.614635', + u'_context_user_id': None, + u'publisher_id': u'metering.precise64', + u'message_id': u'd7aee6e8-c7eb-4d47-9338-f60920d708e4', + u'_unique_id': u'd5a3bdacdcc24644b84e67a4c10e886a', + u'_context_project_id': None} + class TestNotifications(base.TestCase): def test_network_create(self): @@ -244,6 +267,12 @@ class TestNotifications(base.TestCase): self.assertEqual(len(samples), 1) self.assertEqual(samples[0].name, "ip.floating") + def test_metering_report(self): + v = notifications.Bandwidth() + samples = list(v.process_notification(NOTIFICATION_L3_METER)) + self.assertEqual(len(samples), 1) + self.assertEqual(samples[0].name, "bandwidth") + class TestEventTypes(base.TestCase): @@ -267,3 +296,6 @@ class TestEventTypes(base.TestCase): def test_floatingip(self): self.assertTrue(notifications.FloatingIP().event_types) + + def test_bandwidth(self): + self.assertTrue(notifications.Bandwidth().event_types)