Transform instance.resize notifications

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

Implements: bp versioned-notification-transformation-newton
Change-Id: If5183eddb7d79712f360cde11c554e4798f86255
This commit is contained in:
Anusha Unnam 2016-06-10 22:15:12 +00:00 committed by John Garbutt
parent 5bd8e2d47c
commit 029f92d93a
6 changed files with 168 additions and 3 deletions

View File

@ -0,0 +1,62 @@
{
"event_type":"instance.resize.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":"resize_migrated",
"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.resize.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":"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":"resize_migrating",
"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

@ -3769,6 +3769,10 @@ class ComputeManager(manager.Manager):
self._notify_about_instance_usage(
context, instance, "resize.start", network_info=network_info)
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.RESIZE,
phase=fields.NotificationPhase.START)
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
context, instance.uuid)
block_device_info = self._get_instance_block_device_info(
@ -3804,6 +3808,10 @@ class ComputeManager(manager.Manager):
self._notify_about_instance_usage(context, instance, "resize.end",
network_info=network_info)
compute_utils.notify_about_instance_action(context, instance,
self.host, action=fields.NotificationAction.RESIZE,
phase=fields.NotificationPhase.END)
self.instance_events.clear_events_for_instance(instance)
def _terminate_volume_connections(self, context, instance, bdms):

View File

@ -227,8 +227,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
@base.notification_sample('instance-pause-end.json')
# @base.notification_sample('instance-unpause-start.json')
# @base.notification_sample('instance-unpause-end.json')
# @base.notification_sample('instance-resize-start.json')
# @base.notification_sample('instance-resize-end.json')
@base.notification_sample('instance-resize-start.json')
@base.notification_sample('instance-resize-end.json')
@base.notification_sample('instance-suspend-start.json')
@base.notification_sample('instance-suspend-end.json')
@base.notification_sample('instance-power_on-start.json')

View File

@ -289,3 +289,28 @@ class TestInstanceNotificationSample(
notification_sample_base.NotificationSampleTestBase.ANY,
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
def test_create_resize_server(self):
server = self._boot_a_server(
extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
self.flags(allow_resize_to_same_host=True)
post = {'resize': {'flavorRef': '2'}}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
self._verify_notification(
'instance-resize-start',
replacements={
'reservation_id':
notification_sample_base.NotificationSampleTestBase.ANY,
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
self._verify_notification(
'instance-resize-end',
replacements={
'reservation_id':
notification_sample_base.NotificationSampleTestBase.ANY,
'uuid': server['id']},
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])

View File

@ -5036,6 +5036,8 @@ class ComputeTestCase(BaseTestCase):
instance.uuid, 'pre-migrating')
with test.nested(
mock.patch.object(nova.compute.utils,
'notify_about_instance_action'),
mock.patch.object(objects.BlockDeviceMappingList,
'get_by_instance_uuid', return_value='fake_bdms'),
mock.patch.object(
@ -5044,12 +5046,18 @@ class ComputeTestCase(BaseTestCase):
mock.patch.object(self.compute, '_terminate_volume_connections'),
mock.patch.object(self.compute, '_get_power_off_values',
return_value=(1, 2))
) as (mock_get_by_inst_uuid, mock_get_instance_vol_bdinfo,
) as (mock_notify_action, mock_get_by_inst_uuid,
mock_get_instance_vol_bdinfo,
mock_terminate_vol_conn, mock_get_power_off_values):
self.compute.resize_instance(self.context, instance=instance,
migration=migration, image={}, reservations=[],
instance_type=jsonutils.to_primitive(instance_type),
clean_shutdown=clean_shutdown)
mock_notify_action.assert_has_calls([
mock.call(self.context, instance, 'fake-mini',
action='resize', phase='start'),
mock.call(self.context, instance, 'fake-mini',
action='resize', phase='end')])
mock_get_instance_vol_bdinfo.assert_called_once_with(
self.context, instance, bdms='fake_bdms')
mock_terminate_vol_conn.assert_called_once_with(self.context,