Merge "Reset power state upon adoption failure"

This commit is contained in:
Zuul 2020-07-30 11:21:52 +00:00 committed by Gerrit Code Review
commit 888f766cee
3 changed files with 17 additions and 1 deletions

View File

@ -1770,6 +1770,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')

View File

@ -7090,7 +7090,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)
@ -7104,6 +7110,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',

View File

@ -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.