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 35c37d5715
commit 8f7c2affbf
6 changed files with 76 additions and 1 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

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

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

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