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 <natsume.takashi@lab.ntt.co.jp>
Change-Id: I37b19573b6d0e1131c446fcec361f01fa2560f82
Implements: bp versioned-notification-transformation-rocky
This commit is contained in:
Gábor Antal 2017-05-04 16:32:18 +02:00 committed by Takashi NATSUME
parent 202c147f3c
commit 6322cb6a18
10 changed files with 86 additions and 4 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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

View File

@ -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),

View File

@ -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

View File

@ -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

View File

@ -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']

View File

@ -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])

View File

@ -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',

View File

@ -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