From 0365edfa5fcdae079a7569df96d625b05f468337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harri=20H=C3=A4m=C3=A4l=C3=A4inen?= Date: Fri, 7 Feb 2014 13:53:42 +0200 Subject: [PATCH] Fixes invalid key in Neutron notifications The tenant id in notifications is read from variable _context_tenant_id rather than tenant_id. This caused KeyErrors when updating floating IPs. Change-Id: I883e049f28cd8de6d46a622572832bdbf382de24 Closes-Bug: 1276761 --- ceilometer/network/notifications.py | 4 +-- .../tests/network/test_notifications.py | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index 4dd917ca4..7b833f063 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -87,7 +87,7 @@ class NetworkNotificationBase(plugin.NotificationBase): unit=unit_value, volume=1, user_id=message['_context_user_id'], - project_id=message['payload']['tenant_id'], + project_id=message['_context_tenant_id'], resource_id=message['payload']['id'], message=message) @@ -100,7 +100,7 @@ class NetworkNotificationBase(plugin.NotificationBase): unit=unit_value, volume=1, user_id=message['_context_user_id'], - project_id=message['payload']['tenant_id'], + project_id=message['_context_tenant_id'], resource_id=message['payload']['id'], message=message) diff --git a/ceilometer/tests/network/test_notifications.py b/ceilometer/tests/network/test_notifications.py index 9e28b894a..c0c8b0c0e 100644 --- a/ceilometer/tests/network/test_notifications.py +++ b/ceilometer/tests/network/test_notifications.py @@ -202,6 +202,28 @@ NOTIFICATION_FLOATINGIP_EXISTS = { u'publisher_id': u'network.ubuntu-VirtualBox', u'message_id': u'9e839576-cc47-4c60-a7d8-5743681213b1'} + +NOTIFICATION_FLOATINGIP_UPDATE = { + u'_context_roles': [u'anotherrole', + u'Member'], + u'_context_read_deleted': u'no', + u'event_type': u'floatingip.update.start', + u'timestamp': u'2012-09-27 14:11:27.086575', + u'_context_tenant_id': u'82ed0c40ebe64d0bb3310027039c8ed2', + u'payload': {u'floatingip': + {u'fixed_ip_address': u'172.24.4.227', + u'id': u'a68c9390-829e-4732-bad4-e0a978498cc5', + u'port_id': u'e12150f2-885b-45bc-a248-af1c23787d55'}}, + u'priority': u'INFO', + u'_unique_id': u'e483db017b2341fd9ec314dcda88d3e9', + u'_context_is_admin': False, + u'_context_project_id': u'82ed0c40ebe64d0bb3310027039c8ed2', + u'_context_timestamp': u'2012-09-27 14:11:26.924779', + u'_context_user_id': u'b44b7ce67fc84414a5c1660a92a1b862', + 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', @@ -267,6 +289,12 @@ class TestNotifications(test.BaseTestCase): self.assertEqual(len(samples), 1) self.assertEqual(samples[0].name, "ip.floating") + def test_floatingip_update(self): + v = notifications.FloatingIP() + samples = list(v.process_notification(NOTIFICATION_FLOATINGIP_UPDATE)) + self.assertEqual(len(samples), 2) + self.assertEqual(samples[0].name, "ip.floating") + def test_metering_report(self): v = notifications.Bandwidth() samples = list(v.process_notification(NOTIFICATION_L3_METER))