From 62f6a0a1bc6c4b24621e1c2e927177f99501bef3 Mon Sep 17 00:00:00 2001 From: Surya Seetharaman Date: Fri, 22 Mar 2019 16:03:56 +0100 Subject: API microversion 2.76: Add 'power-update' external event This patch adds a new external event called "power-update" through which ironic will convey all (power_off and power_on) power state changes (running -> shutdown or shutdown -> running will be the only ones handled by nova and the rest will be ignored) on a physical instance to nova. The database will be updated accordingly to reflect the real vm_state and power_state of the instance. This way nova will not be able to enforce an incorrect power state on the physical instance during the periodic "sync_power_states" task. Implements blueprint nova-support-instance-power-update Story: 2004969 Task: 29423 Change-Id: I2b292050cc3ce5ef625659f5a1fe56bb76072496 --- nova/tests/unit/virt/ironic/test_driver.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'nova/tests/unit/virt/ironic/test_driver.py') diff --git a/nova/tests/unit/virt/ironic/test_driver.py b/nova/tests/unit/virt/ironic/test_driver.py index c3f4692c72..670a2e1323 100644 --- a/nova/tests/unit/virt/ironic/test_driver.py +++ b/nova/tests/unit/virt/ironic/test_driver.py @@ -26,6 +26,7 @@ from testtools import matchers from tooz import hashring as hash_ring from nova.api.metadata import base as instance_metadata +from nova.api.openstack import common from nova import block_device from nova.compute import power_state as nova_states from nova.compute import provider_tree @@ -1864,6 +1865,20 @@ class IronicDriverTestCase(test.NoDBTestCase): mock_sp.assert_has_calls([mock.call(node.uuid, 'reboot', soft=True), mock.call(node.uuid, 'reboot')]) + @mock.patch.object(objects.Instance, 'save') + def test_power_update_event(self, mock_save): + instance = fake_instance.fake_instance_obj( + self.ctx, node=self.instance_uuid, + power_state=nova_states.RUNNING, + vm_state=vm_states.ACTIVE, + task_state=task_states.POWERING_OFF) + self.driver.power_update_event(instance, common.POWER_OFF) + self.assertEqual(nova_states.SHUTDOWN, instance.power_state) + self.assertEqual(vm_states.STOPPED, instance.vm_state) + self.assertIsNone(instance.task_state) + mock_save.assert_called_once_with( + expected_task_state=task_states.POWERING_OFF) + @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @mock.patch.object(ironic_driver.IronicDriver, '_validate_instance_and_node') -- cgit v1.2.1