Transform instance.volume_detach notification
Transform instance.volume_detach notification Implements: bp versioned-notification-transformation-pike Change-Id: I2d9af7c146681b2a20a1f1d8360c81d2e7d96796
This commit is contained in:
committed by
Matt Riedemann
parent
d34de60971
commit
7fe677d71b
76
doc/notification_samples/instance-volume_detach-end.json
Normal file
76
doc/notification_samples/instance-volume_detach-end.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"event_type": "instance.volume_detach.end",
|
||||
"payload": {
|
||||
"nova_object.data": {
|
||||
"architecture": null,
|
||||
"availability_zone": "nova",
|
||||
"created_at": "2012-10-29T13:42:11Z",
|
||||
"deleted_at": null,
|
||||
"display_name": "some-server",
|
||||
"display_description":"some-server",
|
||||
"fault": null,
|
||||
"flavor": {
|
||||
"nova_object.name": "FlavorPayload",
|
||||
"nova_object.data": {
|
||||
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
|
||||
"name": "test_flavor",
|
||||
"projects": null,
|
||||
"root_gb": 1,
|
||||
"vcpus": 1,
|
||||
"ephemeral_gb": 0,
|
||||
"memory_mb": 512,
|
||||
"disabled": false,
|
||||
"rxtx_factor": 1.0,
|
||||
"extra_specs": {
|
||||
"hw:watchdog_action": "disabled"
|
||||
},
|
||||
"swap": 0,
|
||||
"is_public": true,
|
||||
"vcpu_weight": 0
|
||||
},
|
||||
"nova_object.version": "1.3",
|
||||
"nova_object.namespace": "nova"
|
||||
},
|
||||
"host": "compute",
|
||||
"host_name": "some-server",
|
||||
"image_uuid": "a2459075-d96c-40d5-893e-577ff92e721c",
|
||||
"ip_addresses": [{
|
||||
"nova_object.data": {
|
||||
"address": "192.168.1.3",
|
||||
"device_name": "tapce531f90-19",
|
||||
"label": "private-network",
|
||||
"meta": {},
|
||||
"port_uuid": "ce531f90-199f-48c0-816c-13e38010b442",
|
||||
"version": 4,
|
||||
"mac": "fa:16:3e:4c:2c:30"
|
||||
},
|
||||
"nova_object.name": "IpPayload",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.version": "1.0"
|
||||
}],
|
||||
"kernel_id": "",
|
||||
"launched_at": "2012-10-29T13:42:11Z",
|
||||
"metadata": {},
|
||||
"locked":false,
|
||||
"node": "fake-mini",
|
||||
"volume_id": "a07f71dc-8151-4e7d-a0cc-cd24a3f11113",
|
||||
"os_type": null,
|
||||
"power_state":"running",
|
||||
"progress": 0,
|
||||
"ramdisk_id": "",
|
||||
"reservation_id": "r-6w6ruqaz",
|
||||
"state": "active",
|
||||
"task_state": null,
|
||||
"tenant_id": "6f70656e737461636b20342065766572",
|
||||
"terminated_at": null,
|
||||
"auto_disk_config": "MANUAL",
|
||||
"user_id": "fake",
|
||||
"uuid": "0ab886d0-7443-4107-9265-48371bfa662b"
|
||||
},
|
||||
"nova_object.name": "InstanceActionVolumePayload",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.version": "1.0"
|
||||
},
|
||||
"priority": "INFO",
|
||||
"publisher_id": "nova-compute:compute"
|
||||
}
|
||||
76
doc/notification_samples/instance-volume_detach-start.json
Normal file
76
doc/notification_samples/instance-volume_detach-start.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"event_type": "instance.volume_detach.start",
|
||||
"payload": {
|
||||
"nova_object.data": {
|
||||
"architecture": null,
|
||||
"availability_zone": "nova",
|
||||
"created_at": "2012-10-29T13:42:11Z",
|
||||
"deleted_at": null,
|
||||
"display_name": "some-server",
|
||||
"display_description":"some-server",
|
||||
"fault": null,
|
||||
"flavor": {
|
||||
"nova_object.name": "FlavorPayload",
|
||||
"nova_object.data": {
|
||||
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
|
||||
"name": "test_flavor",
|
||||
"projects": null,
|
||||
"root_gb": 1,
|
||||
"vcpus": 1,
|
||||
"ephemeral_gb": 0,
|
||||
"memory_mb": 512,
|
||||
"disabled": false,
|
||||
"rxtx_factor": 1.0,
|
||||
"extra_specs": {
|
||||
"hw:watchdog_action": "disabled"
|
||||
},
|
||||
"swap": 0,
|
||||
"is_public": true,
|
||||
"vcpu_weight": 0
|
||||
},
|
||||
"nova_object.version": "1.3",
|
||||
"nova_object.namespace": "nova"
|
||||
},
|
||||
"host": "compute",
|
||||
"host_name": "some-server",
|
||||
"image_uuid": "a2459075-d96c-40d5-893e-577ff92e721c",
|
||||
"ip_addresses": [{
|
||||
"nova_object.data": {
|
||||
"address": "192.168.1.3",
|
||||
"device_name": "tapce531f90-19",
|
||||
"label": "private-network",
|
||||
"meta": {},
|
||||
"port_uuid": "ce531f90-199f-48c0-816c-13e38010b442",
|
||||
"version": 4,
|
||||
"mac": "fa:16:3e:4c:2c:30"
|
||||
},
|
||||
"nova_object.name": "IpPayload",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.version": "1.0"
|
||||
}],
|
||||
"kernel_id": "",
|
||||
"launched_at": "2012-10-29T13:42:11Z",
|
||||
"metadata": {},
|
||||
"locked":false,
|
||||
"node": "fake-mini",
|
||||
"volume_id": "a07f71dc-8151-4e7d-a0cc-cd24a3f11113",
|
||||
"os_type": null,
|
||||
"power_state":"running",
|
||||
"progress": 0,
|
||||
"ramdisk_id": "",
|
||||
"reservation_id": "r-6w6ruqaz",
|
||||
"state": "active",
|
||||
"task_state": null,
|
||||
"tenant_id": "6f70656e737461636b20342065766572",
|
||||
"terminated_at": null,
|
||||
"auto_disk_config": "MANUAL",
|
||||
"user_id": "fake",
|
||||
"uuid": "0ab886d0-7443-4107-9265-48371bfa662b"
|
||||
},
|
||||
"nova_object.name": "InstanceActionVolumePayload",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.version": "1.0"
|
||||
},
|
||||
"priority": "INFO",
|
||||
"publisher_id": "nova-compute:compute"
|
||||
}
|
||||
@@ -4885,6 +4885,11 @@ class ComputeManager(manager.Manager):
|
||||
like rebuild, when we don't want to destroy BDM
|
||||
|
||||
"""
|
||||
compute_utils.notify_about_volume_attach_detach(
|
||||
context, instance, self.host,
|
||||
action=fields.NotificationAction.VOLUME_DETACH,
|
||||
phase=fields.NotificationPhase.START,
|
||||
volume_id=volume_id)
|
||||
bdm = objects.BlockDeviceMapping.get_by_volume_and_instance(
|
||||
context, volume_id, instance.uuid)
|
||||
|
||||
@@ -4900,6 +4905,11 @@ class ComputeManager(manager.Manager):
|
||||
info = dict(volume_id=volume_id)
|
||||
self._notify_about_instance_usage(
|
||||
context, instance, "volume.detach", extra_usage_info=info)
|
||||
compute_utils.notify_about_volume_attach_detach(
|
||||
context, instance, self.host,
|
||||
action=fields.NotificationAction.VOLUME_DETACH,
|
||||
phase=fields.NotificationPhase.END,
|
||||
volume_id=volume_id)
|
||||
|
||||
if destroy_bdm:
|
||||
bdm.destroy()
|
||||
|
||||
@@ -364,6 +364,8 @@ class InstanceActionVolumeSwapNotification(base.NotificationBase):
|
||||
@base.notification_sample('instance-volume_attach-start.json')
|
||||
@base.notification_sample('instance-volume_attach-end.json')
|
||||
@base.notification_sample('instance-volume_attach-error.json')
|
||||
@base.notification_sample('instance-volume_detach-start.json')
|
||||
@base.notification_sample('instance-volume_detach-end.json')
|
||||
@nova_base.NovaObjectRegistry.register_notification
|
||||
class InstanceActionVolumeNotification(base.NotificationBase):
|
||||
# Version 1.0: Initial version
|
||||
|
||||
@@ -691,6 +691,7 @@ class TestInstanceNotificationSample(
|
||||
|
||||
def _detach_volume_from_server(self, server, volume_id):
|
||||
self.api.delete_server_volume(server['id'], volume_id)
|
||||
self._wait_for_notification('instance.volume_detach.end')
|
||||
|
||||
def _volume_swap_server(self, server, attachement_id, volume_id):
|
||||
self.api.put_server_volume(server['id'], attachement_id, volume_id)
|
||||
@@ -791,8 +792,25 @@ class TestInstanceNotificationSample(
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
|
||||
fake_notifier.reset()
|
||||
self._detach_volume_from_server(server, self.cinder.SWAP_OLD_VOL)
|
||||
|
||||
# 0. volume_detach-start
|
||||
# 1. volume_detach-end
|
||||
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
self._verify_notification(
|
||||
'instance-volume_detach-start',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
|
||||
self._verify_notification(
|
||||
'instance-volume_detach-end',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
|
||||
def _test_rescue_server(self, server):
|
||||
pass
|
||||
|
||||
|
||||
@@ -852,6 +852,15 @@ class ComputeVolumeTestCase(BaseTestCase):
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_attach', phase='start',
|
||||
volume_id=uuids.volume_id),
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_attach', phase='end',
|
||||
volume_id=uuids.volume_id),
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_detach', phase='start',
|
||||
volume_id=uuids.volume_id),
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_detach', phase='end',
|
||||
volume_id=uuids.volume_id),
|
||||
])
|
||||
|
||||
mock_get.assert_called_once_with(self.context, uuids.volume_id,
|
||||
|
||||
@@ -2451,8 +2451,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
@mock.patch.object(driver_bdm_volume, 'detach')
|
||||
@mock.patch('nova.compute.manager.ComputeManager.'
|
||||
'_notify_about_instance_usage')
|
||||
def _test_detach_volume(self, notify_inst_usage, detach,
|
||||
bdm_get, destroy_bdm=True):
|
||||
@mock.patch('nova.compute.utils.notify_about_volume_attach_detach')
|
||||
def _test_detach_volume(self, mock_notify_attach_detach, notify_inst_usage,
|
||||
detach, bdm_get, destroy_bdm=True):
|
||||
# TODO(lyarwood): Move into ../virt/test_block_device.py
|
||||
volume_id = uuids.volume
|
||||
inst_obj = mock.Mock()
|
||||
@@ -2488,6 +2489,15 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
else:
|
||||
self.assertFalse(bdm_destroy.called)
|
||||
|
||||
mock_notify_attach_detach.assert_has_calls([
|
||||
mock.call(self.context, inst_obj, 'fake-mini',
|
||||
action='volume_detach', phase='start',
|
||||
volume_id=volume_id),
|
||||
mock.call(self.context, inst_obj, 'fake-mini',
|
||||
action='volume_detach', phase='end',
|
||||
volume_id=volume_id),
|
||||
])
|
||||
|
||||
def test_detach_volume_evacuate(self):
|
||||
"""For evacuate, terminate_connection is called with original host."""
|
||||
# TODO(lyarwood): Move into ../virt/test_block_device.py
|
||||
@@ -2522,8 +2532,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
@mock.patch('nova.objects.BlockDeviceMapping.get_by_volume_and_instance')
|
||||
@mock.patch('nova.compute.manager.ComputeManager.'
|
||||
'_notify_about_instance_usage')
|
||||
def _test_detach_volume_evacuate(self, conn_info_str, notify_inst_usage,
|
||||
bdm_get, expected=None):
|
||||
@mock.patch('nova.compute.utils.notify_about_volume_attach_detach')
|
||||
def _test_detach_volume_evacuate(self, conn_info_str,
|
||||
mock_notify_attach_detach,
|
||||
notify_inst_usage, bdm_get,
|
||||
expected=None):
|
||||
"""Re-usable code for detach volume evacuate test cases.
|
||||
|
||||
:param conn_info_str: String form of the stashed connector.
|
||||
@@ -2571,6 +2584,15 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
extra_usage_info={'volume_id': volume_id}
|
||||
)
|
||||
|
||||
mock_notify_attach_detach.assert_has_calls([
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_detach', phase='start',
|
||||
volume_id=volume_id),
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='volume_detach', phase='end',
|
||||
volume_id=volume_id),
|
||||
])
|
||||
|
||||
def _test_rescue(self, clean_shutdown=True):
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
self.context, vm_state=vm_states.ACTIVE)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The following volume attach and volume detach versioned notifications have
|
||||
been added to the nova-compute service:
|
||||
|
||||
* instance.volume_attach.start
|
||||
* instance.volume_attach.end
|
||||
* instance.volume_attach.error
|
||||
* instance.volume_detach.start
|
||||
* instance.volume_detach.end
|
||||
Reference in New Issue
Block a user