Merge "Transform instance.soft_delete notifications"

This commit is contained in:
Jenkins 2017-06-22 00:23:28 +00:00 committed by Gerrit Code Review
commit 4e46a0a748
6 changed files with 197 additions and 5 deletions

View File

@ -0,0 +1,75 @@
{
"event_type":"instance.soft_delete.end",
"payload":{
"nova_object.data":{
"architecture": "x86_64",
"availability_zone": "nova",
"created_at":"2012-10-29T13:42:11Z",
"deleted_at":"2012-10-29T13:42:11Z",
"display_name":"some-server",
"display_description":"some-server",
"fault":null,
"host":"compute",
"host_name":"some-server",
"ip_addresses": [{
"nova_object.name": "IpPayload",
"nova_object.namespace": "nova",
"nova_object.version": "1.0",
"nova_object.data": {
"mac": "fa:16:3e:4c:2c:30",
"address": "192.168.1.3",
"port_uuid": "ce531f90-199f-48c0-816c-13e38010b442",
"meta": {},
"version": 4,
"label": "private-network",
"device_name": "tapce531f90-19"
}
}],
"kernel_id":"",
"launched_at":"2012-10-29T13:42:11Z",
"image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
"metadata":{},
"locked":false,
"node":"fake-mini",
"os_type":null,
"progress":0,
"ramdisk_id":"",
"reservation_id":"r-npxv0e40",
"state":"soft-delete",
"task_state":null,
"power_state":"running",
"tenant_id":"6f70656e737461636b20342065766572",
"terminated_at":null,
"auto_disk_config":"MANUAL",
"flavor": {
"nova_object.name": "FlavorPayload",
"nova_object.data": {
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
"name": "test_flavor",
"root_gb": 1,
"vcpus": 1,
"ephemeral_gb": 0,
"memory_mb": 512,
"disabled": false,
"rxtx_factor": 1.0,
"extra_specs": {
"hw:watchdog_action": "disabled"
},
"projects": null,
"swap": 0,
"is_public": true,
"vcpu_weight": 0
},
"nova_object.version": "1.3",
"nova_object.namespace": "nova"
},
"user_id":"fake",
"uuid":"178b0921-8f85-4257-88b6-2e743b5a975c"
},
"nova_object.name":"InstanceActionPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.2"
},
"priority":"INFO",
"publisher_id":"nova-compute:compute"
}

View File

@ -0,0 +1,75 @@
{
"event_type":"instance.soft_delete.start",
"payload":{
"nova_object.data":{
"architecture": "x86_64",
"availability_zone": "nova",
"created_at":"2012-10-29T13:42:11Z",
"deleted_at":"2012-10-29T13:42:11Z",
"display_name":"some-server",
"display_description":"some-server",
"fault":null,
"host":"compute",
"host_name":"some-server",
"ip_addresses": [{
"nova_object.name": "IpPayload",
"nova_object.namespace": "nova",
"nova_object.version": "1.0",
"nova_object.data": {
"mac": "fa:16:3e:4c:2c:30",
"address": "192.168.1.3",
"port_uuid": "ce531f90-199f-48c0-816c-13e38010b442",
"meta": {},
"version": 4,
"label": "private-network",
"device_name": "tapce531f90-19"
}
}],
"kernel_id":"",
"launched_at":"2012-10-29T13:42:11Z",
"image_uuid": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
"metadata":{},
"locked":false,
"node":"fake-mini",
"os_type":null,
"progress":0,
"ramdisk_id":"",
"reservation_id":"r-npxv0e40",
"state":"active",
"task_state": "soft-deleting",
"power_state":"running",
"tenant_id":"6f70656e737461636b20342065766572",
"terminated_at":null,
"auto_disk_config":"MANUAL",
"flavor": {
"nova_object.name": "FlavorPayload",
"nova_object.data": {
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
"name": "test_flavor",
"root_gb": 1,
"vcpus": 1,
"ephemeral_gb": 0,
"memory_mb": 512,
"disabled": false,
"rxtx_factor": 1.0,
"extra_specs": {
"hw:watchdog_action": "disabled"
},
"projects": null,
"swap": 0,
"is_public": true,
"vcpu_weight": 0
},
"nova_object.version": "1.3",
"nova_object.namespace": "nova"
},
"user_id":"fake",
"uuid":"178b0921-8f85-4257-88b6-2e743b5a975c"
},
"nova_object.name":"InstanceActionPayload",
"nova_object.namespace":"nova",
"nova_object.version":"1.2"
},
"priority":"INFO",
"publisher_id":"nova-compute:compute"
}

View File

@ -2611,6 +2611,9 @@ class ComputeManager(manager.Manager):
try:
self._notify_about_instance_usage(context, instance,
"soft_delete.start")
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.SOFT_DELETE,
phase=fields.NotificationPhase.START)
try:
self.driver.soft_delete(instance)
except NotImplementedError:
@ -2626,6 +2629,9 @@ class ComputeManager(manager.Manager):
quotas.rollback()
quotas.commit()
self._notify_about_instance_usage(context, instance, "soft_delete.end")
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.SOFT_DELETE,
phase=fields.NotificationPhase.END)
@wrap_exception()
@reverts_task_state

View File

@ -348,8 +348,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
# @base.notification_sample('instance-resize_revert-end.json')
@base.notification_sample('instance-shelve_offload-start.json')
@base.notification_sample('instance-shelve_offload-end.json')
# @base.notification_sample('instance-soft_delete-start.json')
# @base.notification_sample('instance-soft_delete-end.json')
@base.notification_sample('instance-soft_delete-start.json')
@base.notification_sample('instance-soft_delete-end.json')
# @base.notification_sample('instance-trigger_crash_dump-start.json')
# @base.notification_sample('instance-trigger_crash_dump-end.json')
# @base.notification_sample('instance-unrescue-start.json')

View File

@ -641,6 +641,8 @@ class TestInstanceNotificationSample(
self.flags(reclaim_instance_interval=30)
self.api.delete_server(server['id'])
self._wait_for_state_change(self.api, server, 'SOFT_DELETED')
# we don't want to test soft_delete here
fake_notifier.reset()
self.api.post_server_action(server['id'], {'restore': {}})
self._wait_for_state_change(self.api, server, 'ACTIVE')
@ -658,8 +660,6 @@ class TestInstanceNotificationSample(
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
self.flags(reclaim_instance_interval=0)
def _test_reboot_server(self, server):
post = {'reboot': {'type': 'HARD'}}
self.api.post_server_action(server['id'], post)
@ -835,7 +835,26 @@ class TestInstanceNotificationSample(
pass
def _test_soft_delete_server(self, server):
pass
self.flags(reclaim_instance_interval=30)
self.api.delete_server(server['id'])
self._wait_for_state_change(self.api, server, 'SOFT_DELETED')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
self._verify_notification(
'instance-soft_delete-start',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
self._verify_notification(
'instance-soft_delete-end',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
self.flags(reclaim_instance_interval=0)
# Leave instance in normal, active state
self.api.post_server_action(server['id'], {'restore': {}})
@mock.patch('nova.volume.cinder.API.attach')
def _test_attach_volume_error(self, server, mock_attach):

View File

@ -3531,6 +3531,23 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
mock_attach_delete.assert_called_once_with(
self.context, uuids.attach_id)
def test_instance_soft_delete_notification(self):
inst_obj = fake_instance.fake_instance_obj(self.context,
vm_state=vm_states.ACTIVE)
with test.nested(
mock.patch.object(nova.compute.utils,
'notify_about_instance_action'),
mock.patch.object(self.compute, '_notify_about_instance_usage'),
mock.patch.object(objects.Instance, 'save'),
mock.patch.object(self.compute.driver, 'soft_delete')
) as (fake_notify, fake_notify_usage, fake_save, fake_soft_delete):
self.compute.soft_delete_instance(self.context, inst_obj, [])
fake_notify.assert_has_calls([
mock.call(self.context, inst_obj, 'fake-mini',
action='soft_delete', phase='start'),
mock.call(self.context, inst_obj, 'fake-mini',
action='soft_delete', phase='end')])
class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
def setUp(self):