Transform instance.unshelve notifications

The instance.unshelve.start and instance.unshelve.end
notifications are transformed to the versioned framework.

Change-Id: Ie3fe83a6b18a1a09a8d8aab75b41297c62cdb74b
Implements: bp versioned-notification-transformation-ocata
This commit is contained in:
stewie925 2016-10-05 09:27:36 -07:00
parent cb9f0a2096
commit 39bf87a24c
6 changed files with 170 additions and 4 deletions

View File

@ -0,0 +1,62 @@
{
"event_type":"instance.unshelve.end",
"payload":{
"nova_object.data":{
"architecture":"x86_64",
"availability_zone":null,
"created_at":"2012-10-29T13:42:11Z",
"deleted_at":null,
"display_name":"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":{},
"node":"fake-mini",
"os_type":null,
"progress":0,
"ramdisk_id":"",
"reservation_id":"r-npxv0e40",
"state":"active",
"task_state":null,
"power_state":"running",
"tenant_id":"6f70656e737461636b20342065766572",
"terminated_at":null,
"flavor": {
"nova_object.name": "FlavorPayload",
"nova_object.data": {
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
"root_gb": 1,
"vcpus": 1,
"ephemeral_gb": 0,
"memory_mb": 512
},
"nova_object.version": "1.0",
"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.0"
},
"priority":"INFO",
"publisher_id":"nova-compute:compute"
}

View File

@ -0,0 +1,62 @@
{
"event_type":"instance.unshelve.start",
"payload":{
"nova_object.data":{
"architecture":"x86_64",
"availability_zone":null,
"created_at":"2012-10-29T13:42:11Z",
"deleted_at":null,
"display_name":"some-server",
"fault":null,
"host":null,
"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":{},
"node":null,
"os_type":null,
"progress":0,
"ramdisk_id":"",
"reservation_id":"r-npxv0e40",
"state":"shelved_offloaded",
"task_state":"unshelving",
"power_state":"running",
"tenant_id":"6f70656e737461636b20342065766572",
"terminated_at":null,
"flavor": {
"nova_object.name": "FlavorPayload",
"nova_object.data": {
"flavorid": "a22d5517-147c-4147-a0d1-e698df5cd4e3",
"root_gb": 1,
"vcpus": 1,
"ephemeral_gb": 0,
"memory_mb": 512
},
"nova_object.version": "1.0",
"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.0"
},
"priority":"INFO",
"publisher_id":"nova-compute:compute"
}

View File

@ -4325,6 +4325,10 @@ class ComputeManager(manager.Manager):
node):
LOG.info(_LI('Unshelving'), instance=instance)
self._notify_about_instance_usage(context, instance, 'unshelve.start')
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.UNSHELVE,
phase=fields.NotificationPhase.START)
instance.task_state = task_states.SPAWNING
instance.save()
@ -4379,6 +4383,9 @@ class ComputeManager(manager.Manager):
instance.save(expected_task_state=task_states.SPAWNING)
self._update_scheduler_instance_info(context, instance)
self._notify_about_instance_usage(context, instance, 'unshelve.end')
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.UNSHELVE,
phase=fields.NotificationPhase.END)
@messaging.expected_exceptions(NotImplementedError)
@wrap_instance_fault

View File

@ -302,8 +302,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
# @base.notification_sample('instance-trigger_crash_dump-end.json')
# @base.notification_sample('instance-unrescue-start.json')
# @base.notification_sample('instance-unrescue-end.json')
# @base.notification_sample('instance-unshelve-start.json')
# @base.notification_sample('instance-unshelve-end.json')
@base.notification_sample('instance-unshelve-start.json')
@base.notification_sample('instance-unshelve-end.json')
@nova_base.NovaObjectRegistry.register_notification
class InstanceActionNotification(base.NotificationBase):
# Version 1.0: Initial version

View File

@ -66,6 +66,7 @@ class TestInstanceNotificationSample(
self._test_pause_server,
self._test_shelve_server,
self._test_shelve_offload_server,
self._test_unshelve_server,
self._test_resize_server,
]
@ -320,6 +321,31 @@ class TestInstanceNotificationSample(
self.api.post_server_action(server['id'], {'unshelve': None})
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
def _test_unshelve_server(self, server):
# setting the shelved_offload_time to 0 should set the
# instance status to 'SHELVED_OFFLOADED'
self.flags(shelved_offload_time = 0)
self.api.post_server_action(server['id'], {'shelve': {}})
self._wait_for_state_change(self.api, server,
expected_status='SHELVED_OFFLOADED')
post = {'unshelve': None}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self.assertEqual(6, len(fake_notifier.VERSIONED_NOTIFICATIONS))
self._verify_notification(
'instance-unshelve-start',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[4])
self._verify_notification(
'instance-unshelve-end',
replacements={
'reservation_id': server['reservation_id'],
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[5])
def _test_suspend_server(self, server):
post = {'suspend': {}}
self.api.post_server_action(server['id'], post)

View File

@ -211,7 +211,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
def test_shelve_offload_forced_shutdown(self):
self._shelve_offload(clean_shutdown=False)
def test_unshelve(self):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def test_unshelve(self, mock_notify):
instance = self._create_fake_instance_obj()
instance.task_state = task_states.UNSHELVING
instance.save()
@ -295,6 +296,13 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
self.context, instance, image=image,
filter_properties=filter_properties,
node=node)
mock_notify.assert_has_calls([
mock.call(self.context, instance, 'fake-mini',
action='unshelve', phase='start'),
mock.call(self.context, instance, 'fake-mini',
action='unshelve', phase='end')])
self.assertNotIn('shelved_at', instance.system_metadata)
self.assertNotIn('shelved_image_id', instance.system_metadata)
self.assertNotIn('shelved_host', instance.system_metadata)
@ -309,7 +317,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
self.assertFalse(instance.auto_disk_config)
@mock.patch('nova.utils.get_image_from_system_metadata')
def test_unshelve_volume_backed(self, mock_image_meta):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def test_unshelve_volume_backed(self, mock_notify, mock_image_meta):
instance = self._create_fake_instance_obj()
node = test_compute.NODENAME
limits = {}