From 6322cb6a18868b0b1d09f82a2de1dbf051c8f599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Antal?= Date: Thu, 4 May 2017 16:32:18 +0200 Subject: [PATCH] Transform aggregate.update_prop notification The aggregate.update_prop.start and aggregate.update_prop.end notifications has been transformed to the versioned notification framework. Co-Authored-By: Takashi Natsume Change-Id: I37b19573b6d0e1131c446fcec361f01fa2560f82 Implements: bp versioned-notification-transformation-rocky --- .../aggregate-update_prop-end.json | 11 +++++++ .../aggregate-update_prop-start.json | 11 +++++++ nova/notifications/objects/aggregate.py | 2 ++ nova/notifications/objects/base.py | 4 ++- nova/objects/aggregate.py | 10 +++++++ nova/objects/fields.py | 3 +- nova/tests/functional/api/client.py | 4 +++ .../test_aggregate.py | 30 +++++++++++++++++++ .../objects/test_notification.py | 2 +- nova/tests/unit/objects/test_aggregate.py | 13 +++++++- 10 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 doc/notification_samples/aggregate-update_prop-end.json create mode 100644 doc/notification_samples/aggregate-update_prop-start.json diff --git a/doc/notification_samples/aggregate-update_prop-end.json b/doc/notification_samples/aggregate-update_prop-end.json new file mode 100644 index 000000000000..1a0001db64dd --- /dev/null +++ b/doc/notification_samples/aggregate-update_prop-end.json @@ -0,0 +1,11 @@ +{ + "priority": "INFO", + "payload": { + "$ref": "common_payloads/AggregatePayload.json#", + "nova_object.data": { + "name": "my-new-aggregate" + } + }, + "event_type": "aggregate.update_prop.end", + "publisher_id": "nova-api:fake-mini" +} diff --git a/doc/notification_samples/aggregate-update_prop-start.json b/doc/notification_samples/aggregate-update_prop-start.json new file mode 100644 index 000000000000..3783e4a45615 --- /dev/null +++ b/doc/notification_samples/aggregate-update_prop-start.json @@ -0,0 +1,11 @@ +{ + "priority": "INFO", + "payload": { + "$ref": "common_payloads/AggregatePayload.json#", + "nova_object.data": { + "name": "my-new-aggregate" + } + }, + "event_type": "aggregate.update_prop.start", + "publisher_id": "nova-api:fake-mini" +} diff --git a/nova/notifications/objects/aggregate.py b/nova/notifications/objects/aggregate.py index 8698ee890f94..38871dd6805c 100644 --- a/nova/notifications/objects/aggregate.py +++ b/nova/notifications/objects/aggregate.py @@ -52,6 +52,8 @@ class AggregatePayload(base.NotificationPayloadBase): @base.notification_sample('aggregate-remove_host-end.json') @base.notification_sample('aggregate-update_metadata-start.json') @base.notification_sample('aggregate-update_metadata-end.json') +@base.notification_sample('aggregate-update_prop-start.json') +@base.notification_sample('aggregate-update_prop-end.json') @nova_base.NovaObjectRegistry.register_notification class AggregateNotification(base.NotificationBase): # Version 1.0: Initial version diff --git a/nova/notifications/objects/base.py b/nova/notifications/objects/base.py index 06e8578888c8..761fe62d8607 100644 --- a/nova/notifications/objects/base.py +++ b/nova/notifications/objects/base.py @@ -61,7 +61,9 @@ class EventType(NotificationObject): # Version 1.12: UNLOCK is added to NotificationActionField enum # Version 1.13: REBUILD_SCHEDULED value is added to the # NotificationActionField enum - VERSION = '1.13' + # Version 1.14: UPDATE_PROP value is added to the NotificationActionField + # enum + VERSION = '1.14' fields = { 'object': fields.StringField(nullable=False), diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index 0f6ca130a278..85793f813b82 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -332,12 +332,22 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject): compute_utils.notify_about_aggregate_update(self._context, "updateprop.start", payload) + compute_utils.notify_about_aggregate_action( + context=self._context, + aggregate=self, + action=fields.NotificationAction.UPDATE_PROP, + phase=fields.NotificationPhase.START) updates.pop('id', None) db_aggregate = _aggregate_update_to_db(self._context, self.id, updates) compute_utils.notify_about_aggregate_update(self._context, "updateprop.end", payload) + compute_utils.notify_about_aggregate_action( + context=self._context, + aggregate=self, + action=fields.NotificationAction.UPDATE_PROP, + phase=fields.NotificationPhase.END) self._from_db_object(self._context, self, db_aggregate) @base.remotable diff --git a/nova/objects/fields.py b/nova/objects/fields.py index cf7c4caf51dc..3186a86d30ee 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -824,6 +824,7 @@ class NotificationAction(BaseNovaEnum): UPDATE_METADATA = 'update_metadata' LOCK = 'lock' UNLOCK = 'unlock' + UPDATE_PROP = 'update_prop' ALL = (UPDATE, EXCEPTION, DELETE, PAUSE, UNPAUSE, RESIZE, VOLUME_SWAP, SUSPEND, POWER_ON, REBOOT, SHUTDOWN, SNAPSHOT, INTERFACE_ATTACH, @@ -835,7 +836,7 @@ class NotificationAction(BaseNovaEnum): RESIZE_CONFIRM, RESIZE_PREP, RESIZE_REVERT, SHELVE_OFFLOAD, SOFT_DELETE, TRIGGER_CRASH_DUMP, UNRESCUE, UNSHELVE, ADD_HOST, REMOVE_HOST, ADD_MEMBER, UPDATE_METADATA, LOCK, UNLOCK, - REBUILD_SCHEDULED) + REBUILD_SCHEDULED, UPDATE_PROP) # TODO(rlrossit): These should be changed over to be a StateMachine enum from diff --git a/nova/tests/functional/api/client.py b/nova/tests/functional/api/client.py index 227bb078cc78..a00ff22f4026 100644 --- a/nova/tests/functional/api/client.py +++ b/nova/tests/functional/api/client.py @@ -493,3 +493,7 @@ class TestOpenStackClient(object): def delete_migration(self, server_id, migration_id): return self.api_delete( '/servers/%s/migrations/%s' % (server_id, migration_id)) + + def put_aggregate(self, aggregate_id, body): + return self.api_put( + '/os-aggregates/%s' % aggregate_id, body).body['aggregate'] diff --git a/nova/tests/functional/notification_sample_tests/test_aggregate.py b/nova/tests/functional/notification_sample_tests/test_aggregate.py index 95cb8775cf3c..ca6a701b294e 100644 --- a/nova/tests/functional/notification_sample_tests/test_aggregate.py +++ b/nova/tests/functional/notification_sample_tests/test_aggregate.py @@ -136,3 +136,33 @@ class TestAggregateNotificationSample( 'uuid': aggregate['uuid'], 'id': aggregate['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[1]) + + def test_aggregate_updateprops(self): + aggregate_req = { + "aggregate": { + "name": "my-aggregate", + "availability_zone": "nova"}} + aggregate = self.admin_api.post_aggregate(aggregate_req) + + update_req = { + "aggregate": { + "name": "my-new-aggregate"}} + self.admin_api.put_aggregate(aggregate['id'], update_req) + + # 0. aggregate-create-start + # 1. aggregate-create-end + # 2. aggregate-update_prop-start + # 3. aggregate-update_prop-end + self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self._verify_notification( + 'aggregate-update_prop-start', + replacements={ + 'uuid': aggregate['uuid'], + 'id': aggregate['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[2]) + self._verify_notification( + 'aggregate-update_prop-end', + replacements={ + 'uuid': aggregate['uuid'], + 'id': aggregate['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[3]) diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index 76eb5efd55ed..4253b630ad2f 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -370,7 +370,7 @@ notification_object_data = { 'AuditPeriodPayload': '1.0-2b429dd307b8374636703b843fa3f9cb', 'BandwidthPayload': '1.0-ee2616a7690ab78406842a2b68e34130', 'BlockDevicePayload': '1.0-29751e1b6d41b1454e36768a1e764df8', - 'EventType': '1.13-38edd755949d09025d66261f9ff46549', + 'EventType': '1.14-471d49b27dce4b38484451f5146b7c16', 'ExceptionNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'ExceptionPayload': '1.1-6c43008bd81885a63bc7f7c629f0793b', 'FlavorNotification': '1.0-a73147b93b520ff0061865849d3dfa56', diff --git a/nova/tests/unit/objects/test_aggregate.py b/nova/tests/unit/objects/test_aggregate.py index 3544f8bd5620..603d9904171c 100644 --- a/nova/tests/unit/objects/test_aggregate.py +++ b/nova/tests/unit/objects/test_aggregate.py @@ -17,6 +17,7 @@ from oslo_utils import timeutils from nova import exception from nova.objects import aggregate +from nova import test from nova.tests.unit import fake_notifier from nova.tests.unit.objects import test_objects from nova.tests import uuidsentinel @@ -96,8 +97,9 @@ class _TestAggregateObject(object): agg.destroy() api_delete_mock.assert_called_with(self.context, 123) + @mock.patch('nova.compute.utils.notify_about_aggregate_action') @mock.patch('nova.objects.aggregate._aggregate_update_to_db') - def test_save_to_api(self, api_update_mock): + def test_save_to_api(self, api_update_mock, mock_notify): api_update_mock.return_value = fake_aggregate agg = aggregate.Aggregate(context=self.context) agg.id = 123 @@ -111,6 +113,15 @@ class _TestAggregateObject(object): api_update_mock.assert_called_once_with(self.context, 123, {'name': 'fake-api-aggregate'}) + mock_notify.assert_has_calls([ + mock.call(context=self.context, + aggregate=test.MatchType(aggregate.Aggregate), + action='update_prop', phase='start'), + mock.call(context=self.context, + aggregate=test.MatchType(aggregate.Aggregate), + action='update_prop', phase='end')]) + self.assertEqual(2, mock_notify.call_count) + def test_save_and_create_no_hosts(self): agg = aggregate.Aggregate(context=self.context) agg.id = 123