Add snapshot id to the snapshot notifications
The versioned instance.snapshot.start and .end notifications now contain the id of the image that stores the instance snapshot. Change-Id: I1c8c038078bbe1a5914a92d44b3e977287294a88 Implements: bp versioned-notification-transformation-queens
This commit is contained in:
parent
f1317c016c
commit
581c537cf5
@ -78,11 +78,12 @@
|
||||
},
|
||||
"user_id":"fake",
|
||||
"uuid":"178b0921-8f85-4257-88b6-2e743b5a975c",
|
||||
"updated_at": "2012-10-29T13:42:11Z"
|
||||
"updated_at": "2012-10-29T13:42:11Z",
|
||||
"snapshot_image_id": "d2aae36f-785c-4518-8016-bc9534d9fc7f"
|
||||
},
|
||||
"nova_object.name":"InstanceActionPayload",
|
||||
"nova_object.name":"InstanceActionSnapshotPayload",
|
||||
"nova_object.namespace":"nova",
|
||||
"nova_object.version":"1.5"
|
||||
"nova_object.version":"1.6"
|
||||
},
|
||||
"priority":"INFO",
|
||||
"publisher_id":"nova-compute:compute"
|
||||
|
@ -78,11 +78,12 @@
|
||||
},
|
||||
"user_id":"fake",
|
||||
"uuid":"178b0921-8f85-4257-88b6-2e743b5a975c",
|
||||
"updated_at": "2012-10-29T13:42:11Z"
|
||||
"updated_at": "2012-10-29T13:42:11Z",
|
||||
"snapshot_image_id": "d2aae36f-785c-4518-8016-bc9534d9fc7f"
|
||||
},
|
||||
"nova_object.name":"InstanceActionPayload",
|
||||
"nova_object.name":"InstanceActionSnapshotPayload",
|
||||
"nova_object.namespace":"nova",
|
||||
"nova_object.version":"1.5"
|
||||
"nova_object.version":"1.6"
|
||||
},
|
||||
"priority":"INFO",
|
||||
"publisher_id":"nova-compute:compute"
|
||||
|
@ -3187,9 +3187,9 @@ class ComputeManager(manager.Manager):
|
||||
|
||||
self._notify_about_instance_usage(
|
||||
context, instance, "snapshot.start")
|
||||
compute_utils.notify_about_instance_action(context, instance,
|
||||
self.host, action=fields.NotificationAction.SNAPSHOT,
|
||||
phase=fields.NotificationPhase.START)
|
||||
compute_utils.notify_about_instance_snapshot(context, instance,
|
||||
self.host, phase=fields.NotificationPhase.START,
|
||||
snapshot_image_id=image_id)
|
||||
|
||||
def update_task_state(task_state,
|
||||
expected_state=expected_task_state):
|
||||
@ -3204,9 +3204,9 @@ class ComputeManager(manager.Manager):
|
||||
|
||||
self._notify_about_instance_usage(context, instance,
|
||||
"snapshot.end")
|
||||
compute_utils.notify_about_instance_action(context, instance,
|
||||
self.host, action=fields.NotificationAction.SNAPSHOT,
|
||||
phase=fields.NotificationPhase.END)
|
||||
compute_utils.notify_about_instance_snapshot(context, instance,
|
||||
self.host, phase=fields.NotificationPhase.END,
|
||||
snapshot_image_id=image_id)
|
||||
except (exception.InstanceNotFound,
|
||||
exception.UnexpectedDeletingTaskStateError):
|
||||
# the instance got deleted during the snapshot
|
||||
|
@ -493,6 +493,35 @@ def notify_about_volume_swap(context, instance, host, action, phase,
|
||||
payload=payload).emit(context)
|
||||
|
||||
|
||||
@rpc.if_notifications_enabled
|
||||
def notify_about_instance_snapshot(context, instance, host, phase,
|
||||
snapshot_image_id):
|
||||
"""Send versioned notification about the snapshot action executed on the
|
||||
instance
|
||||
|
||||
:param context: the request context
|
||||
:param instance: the instance from which a snapshot image is being created
|
||||
:param host: the host emitting the notification
|
||||
:param phase: the phase of the action
|
||||
:param snapshot_image_id: the ID of the snapshot
|
||||
"""
|
||||
payload = instance_notification.InstanceActionSnapshotPayload(
|
||||
instance=instance,
|
||||
fault=None,
|
||||
snapshot_image_id=snapshot_image_id)
|
||||
|
||||
instance_notification.InstanceActionSnapshotNotification(
|
||||
context=context,
|
||||
priority=fields.NotificationPriority.INFO,
|
||||
publisher=notification_base.NotificationPublisher(
|
||||
host=host, source=fields.NotificationSource.COMPUTE),
|
||||
event_type=notification_base.EventType(
|
||||
object='instance',
|
||||
action=fields.NotificationAction.SNAPSHOT,
|
||||
phase=phase),
|
||||
payload=payload).emit(context)
|
||||
|
||||
|
||||
def notify_about_server_group_update(context, event_suffix, sg_payload):
|
||||
"""Send a notification about server group update.
|
||||
|
||||
|
@ -504,3 +504,34 @@ class InstanceCreateNotification(base.NotificationBase):
|
||||
fields = {
|
||||
'payload': fields.ObjectField('InstanceCreatePayload')
|
||||
}
|
||||
|
||||
|
||||
@base.notification_sample('instance-snapshot-start.json')
|
||||
@base.notification_sample('instance-snapshot-end.json')
|
||||
@nova_base.NovaObjectRegistry.register_notification
|
||||
class InstanceActionSnapshotNotification(base.NotificationBase):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
fields = {
|
||||
'payload': fields.ObjectField('InstanceActionSnapshotPayload')
|
||||
}
|
||||
|
||||
|
||||
@nova_base.NovaObjectRegistry.register_notification
|
||||
class InstanceActionSnapshotPayload(InstanceActionPayload):
|
||||
# Version 1.6: Initial version. It starts at version 1.6 as
|
||||
# instance.snapshot.start and .end notifications are switched
|
||||
# from using InstanceActionPayload 1.5 to this new payload and
|
||||
# also it added a new field so we wanted to keep the version
|
||||
# number increasing to signal the change.
|
||||
VERSION = '1.6'
|
||||
fields = {
|
||||
'snapshot_image_id': fields.UUIDField(),
|
||||
}
|
||||
|
||||
def __init__(self, instance, fault, snapshot_image_id):
|
||||
super(InstanceActionSnapshotPayload, self).__init__(
|
||||
instance=instance,
|
||||
fault=fault)
|
||||
self.snapshot_image_id = snapshot_image_id
|
||||
|
@ -747,19 +747,21 @@ class TestInstanceNotificationSample(
|
||||
|
||||
def _test_snapshot_server(self, server):
|
||||
post = {'createImage': {'name': 'test-snap'}}
|
||||
self.api.post_server_action(server['id'], post)
|
||||
response = self.api.post_server_action(server['id'], post)
|
||||
self._wait_for_notification('instance.snapshot.end')
|
||||
|
||||
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
self._verify_notification(
|
||||
'instance-snapshot-start',
|
||||
replacements={
|
||||
'snapshot_image_id': response['image_id'],
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
|
||||
self._verify_notification(
|
||||
'instance-snapshot-end',
|
||||
replacements={
|
||||
'snapshot_image_id': response['image_id'],
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
|
@ -3317,20 +3317,21 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
@mock.patch.object(nova.compute.utils, 'notify_about_instance_action')
|
||||
def test_snapshot(self, mock_notify_action):
|
||||
@mock.patch.object(nova.compute.utils, 'notify_about_instance_snapshot')
|
||||
def test_snapshot(self, mock_notify_snapshot):
|
||||
inst_obj = self._get_snapshotting_instance()
|
||||
mock_context = mock.Mock()
|
||||
with mock.patch.object(self.context, 'elevated',
|
||||
return_value=mock_context) as mock_context_elevated:
|
||||
self.compute.snapshot_instance(self.context, image_id='fakesnap',
|
||||
self.compute.snapshot_instance(self.context,
|
||||
image_id=uuids.snapshot,
|
||||
instance=inst_obj)
|
||||
mock_context_elevated.assert_called_once_with()
|
||||
mock_notify_action.assert_has_calls([
|
||||
mock_notify_snapshot.assert_has_calls([
|
||||
mock.call(mock_context, inst_obj, 'fake-mini',
|
||||
action='snapshot', phase='start'),
|
||||
phase='start', snapshot_image_id=uuids.snapshot),
|
||||
mock.call(mock_context, inst_obj, 'fake-mini',
|
||||
action='snapshot', phase='end')])
|
||||
phase='end', snapshot_image_id=uuids.snapshot)])
|
||||
|
||||
def test_snapshot_no_image(self):
|
||||
inst_obj = self._get_snapshotting_instance()
|
||||
|
@ -388,6 +388,9 @@ notification_object_data = {
|
||||
'InstanceCreateNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
'InstanceCreatePayload': '1.7-a35b2f3aa64dcc262ebb830e78939bdb',
|
||||
'InstancePayload': '1.5-201d852973dbcb5caab89082a3140487',
|
||||
'InstanceActionSnapshotNotification':
|
||||
'1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
'InstanceActionSnapshotPayload': '1.6-6f96ad137957d802aac94c90337fd950',
|
||||
'InstanceStateUpdatePayload': '1.0-07e111c0fa0f6db0f79b0726d593e3da',
|
||||
'InstanceUpdateNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
'InstanceUpdatePayload': '1.6-9145c7cac4208eb841ceaaa9c10b2d9b',
|
||||
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The payload of the ``instance.snapshot.start`` and
|
||||
``instance.snapshot.end`` notifications have been extended with the
|
||||
``snapshot_image_id`` field that contains the image id of the snapshot
|
||||
created. This change also causes that the type of the payload object has
|
||||
been changed from ``InstanceActionPayload`` version 1.5 to
|
||||
``InstanceActionSnapshotPayload`` version 1.6. See the
|
||||
`notification dev reference`_ for the sample file of
|
||||
``instance.snapshot.start`` as an example.
|
||||
|
||||
.. _notification dev reference: https://docs.openstack.org/developer/nova/notifications.html
|
||||
|
Loading…
Reference in New Issue
Block a user