From 44d66d351f68fd5bafef2376f4c96d94fa26ff2b Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Mon, 27 Jul 2020 11:46:35 -0700 Subject: [PATCH] Reset power state upon adoption failure When adoption fails, we should back out the power state so we don't accidently save a state that shouldn't be preserved due to the failure. Change-Id: I4647d0141fc639d49ccb0ef195577f18cd35bd30 Story: 2007901 Task: 40447 --- ironic/conductor/manager.py | 2 ++ ironic/tests/unit/conductor/test_manager.py | 9 ++++++++- ...ave-power-state-on-adopt-failed-09194c8269c779de.yaml | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/unsave-power-state-on-adopt-failed-09194c8269c779de.yaml diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py index 222ad55079..80dd6eb7b0 100644 --- a/ironic/conductor/manager.py +++ b/ironic/conductor/manager.py @@ -1764,6 +1764,8 @@ class ConductorManager(base_manager.BaseConductorManager): msg = (_('Error while attempting to adopt node %(node)s: ' '%(err)s.') % {'node': node.uuid, 'err': err}) LOG.error(msg) + # Wipe power state from being preserved as it is likely invalid. + node.power_state = states.NOSTATE node.last_error = msg task.process_event('fail') diff --git a/ironic/tests/unit/conductor/test_manager.py b/ironic/tests/unit/conductor/test_manager.py index 9ae4a04286..1946eab309 100644 --- a/ironic/tests/unit/conductor/test_manager.py +++ b/ironic/tests/unit/conductor/test_manager.py @@ -7061,7 +7061,13 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self._start_service() node = obj_utils.create_test_node( self.context, driver='fake-hardware', - provision_state=states.ADOPTING) + provision_state=states.ADOPTING, + power_state=states.POWER_ON) + # NOTE(TheJulia): When nodes are created for adoption, they + # would have no power state. Under normal circumstances + # during validate the node object is updated with power state + # however we need to make sure that we wipe preserved state + # as part of failure handling. task = task_manager.TaskManager(self.context, node.uuid) self.service._do_adoption(task) @@ -7075,6 +7081,7 @@ class DoNodeAdoptionTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase): self.assertFalse(mock_start_console.called) self.assertTrue(mock_boot_validate.called) self.assertIn('is_whole_disk_image', task.node.driver_internal_info) + self.assertEqual(states.NOSTATE, node.power_state) @mock.patch('ironic.drivers.modules.fake.FakeBoot.validate', autospec=True) @mock.patch('ironic.drivers.modules.fake.FakeConsole.start_console', diff --git a/releasenotes/notes/unsave-power-state-on-adopt-failed-09194c8269c779de.yaml b/releasenotes/notes/unsave-power-state-on-adopt-failed-09194c8269c779de.yaml new file mode 100644 index 0000000000..cebb92035b --- /dev/null +++ b/releasenotes/notes/unsave-power-state-on-adopt-failed-09194c8269c779de.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes the preservation of potentially incorrect power state + information when adoption process fails. Power state is now + wiped as part of the failure handling process instead of + being preserved.