From 8279b1ea2ec25507a6427a54ef03ad99955eb07b Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Thu, 26 May 2016 16:52:04 +0200 Subject: [PATCH] Handle multiple samples per versioned notification The notification_sample decorator is changed to handle attaching multiple sample files to a notification object. Change-Id: I4c3df17d93282f6946221da65d26d0ca3194d3df --- doc/ext/versioned_notifications.py | 7 ++++--- nova/notifications/objects/base.py | 5 ++++- nova/tests/unit/notifications/objects/test_notification.py | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/ext/versioned_notifications.py b/doc/ext/versioned_notifications.py index 38e0e4875e6f..b5460e0b7ee2 100644 --- a/doc/ext/versioned_notifications.py +++ b/doc/ext/versioned_notifications.py @@ -51,9 +51,10 @@ class VersionedNotificationDirective(Directive): payload_name = cls.fields['payload'].objname payload_cls = ovos[payload_name][0] - - notifications.append((full_name(cls), full_name(payload_cls), - cls.sample)) + for sample in cls.samples: + notifications.append((full_name(cls), + full_name(payload_cls), + sample)) return notifications def _build_markup(self, notifications): diff --git a/nova/notifications/objects/base.py b/nova/notifications/objects/base.py index 54f710deae6e..cd6e40b9a8ea 100644 --- a/nova/notifications/objects/base.py +++ b/nova/notifications/objects/base.py @@ -149,6 +149,9 @@ def notification_sample(sample): root. """ def wrap(cls): - cls.sample = sample + if not getattr(cls, 'samples', None): + cls.samples = [sample] + else: + cls.samples.append(sample) return cls return wrap diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index e6ce561113fa..2494c48c7e0d 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -64,6 +64,8 @@ class TestNotificationBase(test.NoDBTestCase): 'extra_field': fields.StringField(), # filled by ctor } + @notification.notification_sample('test-update-1.json') + @notification.notification_sample('test-update-2.json') @base.NovaObjectRegistry.register_if(False) class TestNotification(notification.NotificationBase): VERSION = '1.0' @@ -246,6 +248,11 @@ class TestNotificationBase(test.NoDBTestCase): 'nova_object.version': '1.0', 'nova_object.namespace': 'nova'}) + def test_sample_decorator(self): + self.assertEqual(2, len(self.TestNotification.samples)) + self.assertIn('test-update-1.json', self.TestNotification.samples) + self.assertIn('test-update-2.json', self.TestNotification.samples) + notification_object_data = { 'EventType': '1.1-8291570eed00192197c7fa02ac677cd4',