--- /dev/null
+{
+ "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"
+}
--- /dev/null
+{
+ "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"
+}
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
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):
@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')
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,
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')
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_on-end',
+ '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[3])
+
def _test_shelve_server(self, server):
self.flags(shelved_offload_time = -1)
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, {}, {},
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')
@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
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(