summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2020-07-27 11:46:35 -0700
committerJulia Kreger <juliaashleykreger@gmail.com>2020-07-27 11:46:35 -0700
commit44d66d351f68fd5bafef2376f4c96d94fa26ff2b (patch)
tree4e960d24aa3a26a71492f6db46eb6f6898fa0fc4
parentbc60f08a59934c389d4876d36a7f33e9df3e2eb3 (diff)
downloadironic-44d66d351f68fd5bafef2376f4c96d94fa26ff2b.tar.gz
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
-rw-r--r--ironic/conductor/manager.py2
-rw-r--r--ironic/tests/unit/conductor/test_manager.py9
-rw-r--r--releasenotes/notes/unsave-power-state-on-adopt-failed-09194c8269c779de.yaml7
3 files changed, 17 insertions, 1 deletions
diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py
index 222ad5507..80dd6eb7b 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 9ae4a0428..1946eab30 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 000000000..cebb92035
--- /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.