From c67ab38ea0816bc1f3dcdda845217bff18588c42 Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Sat, 21 Apr 2018 16:45:19 +0800 Subject: [PATCH] Add policy field to ServerGroup notification object In this patch, the ServerGroupPayload is updated to include the new ``policy`` field; the ``policies`` field is deprecated for removal but still put into the notification payload for backward compatibility. Related to blueprint complex-anti-affinity-policies Change-Id: Ie739ee8dec4685cd70e735ff83f7f30bc7e95a57 --- .../common_payloads/ServerGroupPayload.json | 4 +++- nova/notifications/objects/server_group.py | 9 ++++++++- nova/tests/unit/compute/test_compute_utils.py | 12 +++++++++--- .../unit/notifications/objects/test_notification.py | 2 +- ...yle-policy-in-notifications-3c6eefbb56224be2.yaml | 10 ++++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/use-new-style-policy-in-notifications-3c6eefbb56224be2.yaml diff --git a/doc/notification_samples/common_payloads/ServerGroupPayload.json b/doc/notification_samples/common_payloads/ServerGroupPayload.json index bf30d633691c..27053fcdbc81 100644 --- a/doc/notification_samples/common_payloads/ServerGroupPayload.json +++ b/doc/notification_samples/common_payloads/ServerGroupPayload.json @@ -1,5 +1,5 @@ { - "nova_object.version": "1.0", + "nova_object.version": "1.1", "nova_object.namespace": "nova", "nova_object.name": "ServerGroupPayload", "nova_object.data": { @@ -10,6 +10,8 @@ "policies": [ "anti-affinity" ], + "policy": "anti-affinity", + "rules": {}, "members": [], "hosts": null } diff --git a/nova/notifications/objects/server_group.py b/nova/notifications/objects/server_group.py index 81d2022a9069..f42d5930272a 100644 --- a/nova/notifications/objects/server_group.py +++ b/nova/notifications/objects/server_group.py @@ -27,17 +27,24 @@ class ServerGroupPayload(base.NotificationPayloadBase): 'policies': ('group', 'policies'), 'members': ('group', 'members'), 'hosts': ('group', 'hosts'), + 'policy': ('group', 'policy'), + 'rules': ('group', 'rules'), } # Version 1.0: Initial version - VERSION = '1.0' + # Version 1.1: Deprecate policies, add policy and add rules + VERSION = '1.1' fields = { 'uuid': fields.UUIDField(), 'name': fields.StringField(nullable=True), 'user_id': fields.StringField(nullable=True), 'project_id': fields.StringField(nullable=True), + # NOTE(yikun): policies is deprecated and should + # be removed on the next major version bump 'policies': fields.ListOfStringsField(nullable=True), 'members': fields.ListOfStringsField(nullable=True), 'hosts': fields.ListOfStringsField(nullable=True), + 'policy': fields.StringField(nullable=True), + 'rules': fields.DictOfStringsField(), } def __init__(self, group): diff --git a/nova/tests/unit/compute/test_compute_utils.py b/nova/tests/unit/compute/test_compute_utils.py index 311db73209ae..953de8e1caa7 100644 --- a/nova/tests/unit/compute/test_compute_utils.py +++ b/nova/tests/unit/compute/test_compute_utils.py @@ -1160,7 +1160,9 @@ class ServerGroupTestCase(test.TestCase): user_id=self.user_id, project_id=self.project_id, name="test-server-group", - policies=["anti-affinity"]) + policy="anti-affinity", + policies=["anti-affinity"], + rules={"max_server_per_host": 3}) def test_notify_about_server_group_action(self): compute_utils.notify_about_server_group_action(self.context, @@ -1174,6 +1176,8 @@ class ServerGroupTestCase(test.TestCase): 'nova_object.data': { 'name': u'test-server-group', 'policies': [u'anti-affinity'], + 'policy': u'anti-affinity', + 'rules': {"max_server_per_host": "3"}, 'project_id': u'fake', 'user_id': u'fake', 'uuid': uuids.server_group, @@ -1182,7 +1186,7 @@ class ServerGroupTestCase(test.TestCase): }, 'nova_object.name': 'ServerGroupPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.0' + 'nova_object.version': '1.1' } } self.assertEqual(notification, expected) @@ -1204,6 +1208,8 @@ class ServerGroupTestCase(test.TestCase): 'nova_object.data': { 'name': u'test-server-group', 'policies': [u'anti-affinity'], + 'policy': u'anti-affinity', + 'rules': {"max_server_per_host": "3"}, 'project_id': u'fake', 'user_id': u'fake', 'uuid': uuids.server_group, @@ -1212,7 +1218,7 @@ class ServerGroupTestCase(test.TestCase): }, 'nova_object.name': 'ServerGroupPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.0' + 'nova_object.version': '1.1' } } self.assertEqual(notification, expected) diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index 26a890f75984..905e6a2f0147 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -405,7 +405,7 @@ notification_object_data = { 'KeypairPayload': '1.0-6daebbbde0e1bf35c1556b1ecd9385c1', 'NotificationPublisher': '2.2-b6ad48126247e10b46b6b0240e52e614', 'ServerGroupNotification': '1.0-a73147b93b520ff0061865849d3dfa56', - 'ServerGroupPayload': '1.0-eb4bd1738b4670cfe1b7c30344c143c3', + 'ServerGroupPayload': '1.1-4ded2997ea1b07038f7af33ef5c45f7f', 'ServiceStatusNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'ServiceStatusPayload': '1.1-7b6856bd879db7f3ecbcd0ca9f35f92f', } diff --git a/releasenotes/notes/use-new-style-policy-in-notifications-3c6eefbb56224be2.yaml b/releasenotes/notes/use-new-style-policy-in-notifications-3c6eefbb56224be2.yaml new file mode 100644 index 000000000000..cdf870f23feb --- /dev/null +++ b/releasenotes/notes/use-new-style-policy-in-notifications-3c6eefbb56224be2.yaml @@ -0,0 +1,10 @@ +--- + +features: + - | + The new style ``policy`` field has been added to ``ServerGroupPayload``. + The ``server_group.create``, ``server_group.delete`` and + ``server_group.add_member`` versioned notifications will be updated to + include the new ``policy`` and ``rules``field. The ``policies`` field is + deprecated for removal but still put into the notification payload for + backward compatibility.