From 08ab5d45e526f36bf7b8788128a9cc565de275b4 Mon Sep 17 00:00:00 2001 From: Pradeep Kilambi Date: Thu, 23 Apr 2015 12:11:57 -0400 Subject: [PATCH] Fix None TypeError in neutron process notifications Occasionally there is not enough info in event payload to look up the resource info. Which leads to resources being empty. Default to the right type instead of passing on the None. Change-Id: I0d87913146b804d555a2e2b4a0d6d4e904175d06 Closes-Bug: #1447686 --- ceilometer/network/notifications.py | 2 +- .../tests/network/test_notifications.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ceilometer/network/notifications.py b/ceilometer/network/notifications.py index 35978a7be1..1523710880 100644 --- a/ceilometer/network/notifications.py +++ b/ceilometer/network/notifications.py @@ -82,7 +82,7 @@ class NetworkNotificationBase(plugin_base.NotificationBase): resource['id'] = message['payload']['id'] resources = [resource] else: - resources = message['payload'].get(self.resource_name + 's') + resources = message['payload'].get(self.resource_name + 's', []) resource_message = message.copy() for resource in resources: diff --git a/ceilometer/tests/network/test_notifications.py b/ceilometer/tests/network/test_notifications.py index 4c2335153e..fce784836d 100644 --- a/ceilometer/tests/network/test_notifications.py +++ b/ceilometer/tests/network/test_notifications.py @@ -1194,6 +1194,30 @@ NOTIFICATION_IPSEC_SITE_CONN_UPDATE = { "publisher_id": "network.ubuntu", "message_id": "4c0e6ecb-2e40-4975-aee2-d88045c747bf"} +NOTIFICATION_EMPTY_PAYLOAD = { + "_context_roles": ["heat_stack_owner", "admin"], + "_context_request_id": "req-e56a8a5e-5d42-43e8-9677-2d36e6e17d5e", + "event_type": "health_monitor.create.end", + "timestamp": "2014-09-15 17:22:11.323644", + "_context_tenant_id": "a820f2d6293b4a7587d1c582767f43fb", + "_context_user": "1c1f7c80efc24a16b835ae1c0802d0a1", + "_unique_id": "f112a185e1d1424eba3a13df9e0f0277", + "_context_tenant_name": "demo", + "_context_user_id": "1c1f7c80efc24a16b835ae1c0802d0a1", + "payload": { + "health_monitor": {}}, + "_context_project_name": "demo", + "_context_read_deleted": "no", + "_context_auth_token": "e6daf56d7d1787e1fbefff0ecf29703f", + "_context_tenant": "a820f2d6293b4a7587d1c582767f43fb", + "priority": "INFO", + "_context_is_admin": True, + "_context_project_id": "a820f2d6293b4a7587d1c582767f43fb", + "_context_timestamp": "2014-09-15 17:22:11.187163", + "_context_user_name": "admin", + "publisher_id": "network.ubuntu", + "message_id": "65067e3f-830d-4fbb-87e2-f0e51fda83d2"} + class TestNotifications(test.BaseTestCase): def test_network_create(self): @@ -1421,6 +1445,12 @@ class TestNotifications(test.BaseTestCase): self.assertEqual(2, len(samples)) self.assertEqual("network.services.vpn.ikepolicy", samples[0].name) + def test_empty_event_payload(self): + v = notifications.HealthMonitor(mock.Mock()) + samples = list(v.process_notification( + NOTIFICATION_EMPTY_PAYLOAD)) + self.assertEqual(0, len(samples)) + class TestEventTypes(test.BaseTestCase):