Transform instance.power_off notifications
The instance.power_off.start and instance.power_off.end notifications are transformed to the versioned framework. Change-Id: I45b7b2175f318747158564eb14e21129add86fe9 Implements: bp versioned-notification-transformation-ocata
This commit is contained in:
parent
3d7ff766a7
commit
865f0d2050
62
doc/notification_samples/instance-power_off-end.json
Normal file
62
doc/notification_samples/instance-power_off-end.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"event_type":"instance.power_off.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":"stopped",
|
||||
"task_state":null,
|
||||
"power_state":"shutdown",
|
||||
"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"
|
||||
}
|
62
doc/notification_samples/instance-power_off-start.json
Normal file
62
doc/notification_samples/instance-power_off-start.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"event_type":"instance.power_off.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":"powering-off",
|
||||
"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"
|
||||
}
|
@ -2424,6 +2424,11 @@ class ComputeManager(manager.Manager):
|
||||
|
||||
self._notify_about_instance_usage(context, instance,
|
||||
"power_off.start")
|
||||
|
||||
compute_utils.notify_about_instance_action(context, instance,
|
||||
self.host, action=fields.NotificationAction.POWER_OFF,
|
||||
phase=fields.NotificationPhase.START)
|
||||
|
||||
self._power_off_instance(context, instance, clean_shutdown)
|
||||
instance.power_state = self._get_power_state(context, instance)
|
||||
instance.vm_state = vm_states.STOPPED
|
||||
@ -2432,6 +2437,10 @@ class ComputeManager(manager.Manager):
|
||||
self._notify_about_instance_usage(context, instance,
|
||||
"power_off.end")
|
||||
|
||||
compute_utils.notify_about_instance_action(context, instance,
|
||||
self.host, action=fields.NotificationAction.POWER_OFF,
|
||||
phase=fields.NotificationPhase.END)
|
||||
|
||||
do_stop_instance()
|
||||
|
||||
def _power_on(self, context, instance):
|
||||
|
@ -233,8 +233,8 @@ class InstanceStateUpdatePayload(base.NotificationPayloadBase):
|
||||
@base.notification_sample('instance-suspend-end.json')
|
||||
@base.notification_sample('instance-power_on-start.json')
|
||||
@base.notification_sample('instance-power_on-end.json')
|
||||
# @base.notification_sample('instance-power_off-start.json')
|
||||
# @base.notification_sample('instance-power_off-end.json')
|
||||
@base.notification_sample('instance-power_off-start.json')
|
||||
@base.notification_sample('instance-power_off-end.json')
|
||||
# @base.notification_sample('instance-reboot-start.json')
|
||||
# @base.notification_sample('instance-reboot-end.json')
|
||||
# @base.notification_sample('instance-shutdown-start.json')
|
||||
|
@ -39,7 +39,7 @@ class TestInstanceNotificationSample(
|
||||
extra_params={'networks': [{'port': self.neutron.port_1['id']}]})
|
||||
|
||||
actions = [
|
||||
self._test_power_on_server,
|
||||
self._test_power_off_on_server,
|
||||
self._test_restore_server,
|
||||
self._test_suspend_server,
|
||||
self._test_pause_server,
|
||||
@ -212,7 +212,7 @@ class TestInstanceNotificationSample(
|
||||
self._verify_instance_update_steps(delete_steps, instance_updates,
|
||||
initial=replacements)
|
||||
|
||||
def _test_power_on_server(self, server):
|
||||
def _test_power_off_on_server(self, server):
|
||||
self.api.post_server_action(server['id'], {'os-stop': {}})
|
||||
self._wait_for_state_change(self.api, server,
|
||||
expected_status='SHUTOFF')
|
||||
@ -220,19 +220,33 @@ class TestInstanceNotificationSample(
|
||||
self._wait_for_state_change(self.api, server,
|
||||
expected_status='ACTIVE')
|
||||
|
||||
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
self._verify_notification(
|
||||
'instance-power_on-start',
|
||||
'instance-power_off-start',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
|
||||
self._verify_notification(
|
||||
'instance-power_off-end',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'power_state': 'running',
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
|
||||
self._verify_notification(
|
||||
'instance-power_on-start',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[2])
|
||||
self._verify_notification(
|
||||
'instance-power_on-end',
|
||||
replacements={
|
||||
'reservation_id': server['reservation_id'],
|
||||
'uuid': server['id']},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
|
||||
|
||||
def _test_shelve_server(self, server):
|
||||
self.flags(shelved_offload_time = -1)
|
||||
|
@ -2051,7 +2051,8 @@ class ComputeTestCase(BaseTestCase):
|
||||
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
|
||||
self.assertEqual(instance['vm_state'], vm_states.ERROR)
|
||||
|
||||
def test_stop(self):
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_action')
|
||||
def test_stop(self, mock_notify):
|
||||
# Ensure instance can be stopped.
|
||||
instance = self._create_fake_instance_obj()
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {},
|
||||
@ -2065,6 +2066,11 @@ class ComputeTestCase(BaseTestCase):
|
||||
expected_attrs=extra)
|
||||
self.compute.stop_instance(self.context, instance=inst_obj,
|
||||
clean_shutdown=True)
|
||||
mock_notify.assert_has_calls([
|
||||
mock.call(self.context, inst_obj, 'fake-mini', action='power_off',
|
||||
phase='start'),
|
||||
mock.call(self.context, inst_obj, 'fake-mini', action='power_off',
|
||||
phase='end')])
|
||||
self.compute.terminate_instance(self.context, instance, [], [])
|
||||
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_action')
|
||||
|
@ -2852,12 +2852,13 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
|
||||
@mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=power_state.SHUTDOWN)
|
||||
@mock.patch.object(compute_utils, 'notify_about_instance_action')
|
||||
@mock.patch.object(self.compute, '_notify_about_instance_usage')
|
||||
@mock.patch.object(self.compute, '_power_off_instance')
|
||||
@mock.patch.object(instance, 'save')
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def do_test(event_mock, save_mock, power_off_mock, notify_mock,
|
||||
get_state_mock):
|
||||
notify_action_mock, get_state_mock):
|
||||
# run the code
|
||||
self.compute.stop_instance(self.context, instance, True)
|
||||
# assert the calls
|
||||
@ -2866,6 +2867,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
||||
mock.call(self.context, instance, 'power_off.start'),
|
||||
mock.call(self.context, instance, 'power_off.end')
|
||||
])
|
||||
notify_action_mock.assert_has_calls([
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='power_off', phase='start'),
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
action='power_off', phase='end'),
|
||||
])
|
||||
power_off_mock.assert_called_once_with(
|
||||
self.context, instance, True)
|
||||
save_mock.assert_called_once_with(
|
||||
|
Loading…
x
Reference in New Issue
Block a user