Transform aggregate.update_metadata notification
The aggregate.update_metadata.start and aggregate.update_metadata.end notifications has been transformed to the versioned notification framework. Co-Authored-By: Takashi Natsume <natsume.takashi@lab.ntt.co.jp> Change-Id: Iab73b1351a50869620334f692aaefb566ba4ddf8 Implements: bp versioned-notification-transformation-rocky
This commit is contained in:
parent
3043c5b7ea
commit
9413fc0f1f
13
doc/notification_samples/aggregate-update_metadata-end.json
Normal file
13
doc/notification_samples/aggregate-update_metadata-end.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"priority": "INFO",
|
||||||
|
"payload": {
|
||||||
|
"$ref": "common_payloads/AggregatePayload.json#",
|
||||||
|
"nova_object.data": {
|
||||||
|
"metadata": {
|
||||||
|
"availability_zone": "AZ-1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"event_type": "aggregate.update_metadata.end",
|
||||||
|
"publisher_id": "nova-api:fake-mini"
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"priority": "INFO",
|
||||||
|
"payload": {
|
||||||
|
"$ref": "common_payloads/AggregatePayload.json#"
|
||||||
|
},
|
||||||
|
"event_type": "aggregate.update_metadata.start",
|
||||||
|
"publisher_id": "nova-api:fake-mini"
|
||||||
|
}
|
@ -50,6 +50,8 @@ class AggregatePayload(base.NotificationPayloadBase):
|
|||||||
@base.notification_sample('aggregate-add_host-end.json')
|
@base.notification_sample('aggregate-add_host-end.json')
|
||||||
@base.notification_sample('aggregate-remove_host-start.json')
|
@base.notification_sample('aggregate-remove_host-start.json')
|
||||||
@base.notification_sample('aggregate-remove_host-end.json')
|
@base.notification_sample('aggregate-remove_host-end.json')
|
||||||
|
@base.notification_sample('aggregate-update_metadata-start.json')
|
||||||
|
@base.notification_sample('aggregate-update_metadata-end.json')
|
||||||
@nova_base.NovaObjectRegistry.register_notification
|
@nova_base.NovaObjectRegistry.register_notification
|
||||||
class AggregateNotification(base.NotificationBase):
|
class AggregateNotification(base.NotificationBase):
|
||||||
# Version 1.0: Initial version
|
# Version 1.0: Initial version
|
||||||
|
@ -347,6 +347,11 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
|
|||||||
compute_utils.notify_about_aggregate_update(self._context,
|
compute_utils.notify_about_aggregate_update(self._context,
|
||||||
"updatemetadata.start",
|
"updatemetadata.start",
|
||||||
payload)
|
payload)
|
||||||
|
compute_utils.notify_about_aggregate_action(
|
||||||
|
context=self._context,
|
||||||
|
aggregate=self,
|
||||||
|
action=fields.NotificationAction.UPDATE_METADATA,
|
||||||
|
phase=fields.NotificationPhase.START)
|
||||||
to_add = {}
|
to_add = {}
|
||||||
for key, value in updates.items():
|
for key, value in updates.items():
|
||||||
if value is None:
|
if value is None:
|
||||||
@ -365,6 +370,11 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
|
|||||||
compute_utils.notify_about_aggregate_update(self._context,
|
compute_utils.notify_about_aggregate_update(self._context,
|
||||||
"updatemetadata.end",
|
"updatemetadata.end",
|
||||||
payload)
|
payload)
|
||||||
|
compute_utils.notify_about_aggregate_action(
|
||||||
|
context=self._context,
|
||||||
|
aggregate=self,
|
||||||
|
action=fields.NotificationAction.UPDATE_METADATA,
|
||||||
|
phase=fields.NotificationPhase.END)
|
||||||
self.obj_reset_changes(fields=['metadata'])
|
self.obj_reset_changes(fields=['metadata'])
|
||||||
|
|
||||||
@base.remotable
|
@base.remotable
|
||||||
|
@ -105,3 +105,34 @@ class TestAggregateNotificationSample(
|
|||||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
|
actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
|
||||||
|
|
||||||
self.admin_api.delete_aggregate(aggregate['id'])
|
self.admin_api.delete_aggregate(aggregate['id'])
|
||||||
|
|
||||||
|
def test_aggregate_update_metadata(self):
|
||||||
|
aggregate_req = {
|
||||||
|
"aggregate": {
|
||||||
|
"name": "my-aggregate",
|
||||||
|
"availability_zone": "nova"}}
|
||||||
|
aggregate = self.admin_api.post_aggregate(aggregate_req)
|
||||||
|
|
||||||
|
set_metadata_req = {
|
||||||
|
"set_metadata": {
|
||||||
|
"metadata": {
|
||||||
|
"availability_zone": "AZ-1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fake_notifier.reset()
|
||||||
|
self.admin_api.post_aggregate_action(aggregate['id'], set_metadata_req)
|
||||||
|
|
||||||
|
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||||
|
self._verify_notification(
|
||||||
|
'aggregate-update_metadata-start',
|
||||||
|
replacements={
|
||||||
|
'uuid': aggregate['uuid'],
|
||||||
|
'id': aggregate['id']},
|
||||||
|
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
|
||||||
|
self._verify_notification(
|
||||||
|
'aggregate-update_metadata-end',
|
||||||
|
replacements={
|
||||||
|
'uuid': aggregate['uuid'],
|
||||||
|
'id': aggregate['id']},
|
||||||
|
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||||
|
@ -122,7 +122,13 @@ class _TestAggregateObject(object):
|
|||||||
|
|
||||||
@mock.patch('nova.objects.aggregate._metadata_delete_from_db')
|
@mock.patch('nova.objects.aggregate._metadata_delete_from_db')
|
||||||
@mock.patch('nova.objects.aggregate._metadata_add_to_db')
|
@mock.patch('nova.objects.aggregate._metadata_add_to_db')
|
||||||
def test_update_metadata_api(self, mock_api_metadata_add,
|
@mock.patch('nova.compute.utils.notify_about_aggregate_action')
|
||||||
|
@mock.patch('oslo_versionedobjects.base.VersionedObject.'
|
||||||
|
'obj_from_primitive')
|
||||||
|
def test_update_metadata_api(self,
|
||||||
|
mock_obj_from_primitive,
|
||||||
|
mock_notify,
|
||||||
|
mock_api_metadata_add,
|
||||||
mock_api_metadata_delete):
|
mock_api_metadata_delete):
|
||||||
fake_notifier.NOTIFICATIONS = []
|
fake_notifier.NOTIFICATIONS = []
|
||||||
agg = aggregate.Aggregate()
|
agg = aggregate.Aggregate()
|
||||||
@ -130,6 +136,8 @@ class _TestAggregateObject(object):
|
|||||||
agg.id = 123
|
agg.id = 123
|
||||||
agg.metadata = {'foo': 'bar'}
|
agg.metadata = {'foo': 'bar'}
|
||||||
agg.obj_reset_changes()
|
agg.obj_reset_changes()
|
||||||
|
mock_obj_from_primitive.return_value = agg
|
||||||
|
|
||||||
agg.update_metadata({'todelete': None, 'toadd': 'myval'})
|
agg.update_metadata({'todelete': None, 'toadd': 'myval'})
|
||||||
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
|
||||||
msg = fake_notifier.NOTIFICATIONS[0]
|
msg = fake_notifier.NOTIFICATIONS[0]
|
||||||
@ -138,6 +146,11 @@ class _TestAggregateObject(object):
|
|||||||
msg.payload['meta_data'])
|
msg.payload['meta_data'])
|
||||||
msg = fake_notifier.NOTIFICATIONS[1]
|
msg = fake_notifier.NOTIFICATIONS[1]
|
||||||
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
self.assertEqual('aggregate.updatemetadata.end', msg.event_type)
|
||||||
|
mock_notify.assert_has_calls([
|
||||||
|
mock.call(context=self.context, aggregate=agg,
|
||||||
|
action='update_metadata', phase='start'),
|
||||||
|
mock.call(context=self.context, aggregate=agg,
|
||||||
|
action='update_metadata', phase='end')])
|
||||||
self.assertEqual({'todelete': None, 'toadd': 'myval'},
|
self.assertEqual({'todelete': None, 'toadd': 'myval'},
|
||||||
msg.payload['meta_data'])
|
msg.payload['meta_data'])
|
||||||
self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
|
self.assertEqual({'foo': 'bar', 'toadd': 'myval'}, agg.metadata)
|
||||||
|
Loading…
Reference in New Issue
Block a user