Stop introspection if set boot device failed

At the beginning of introspection, ironic inspector sets boot device and
reboot node through ironic, currently it only stops when reboot the node
is failed. Actually the node is not guaranteed to reboot with pxe in either
case.

This patch eliminates the descripency, so that if anything goes wrong, it
will be exposed early.

Change-Id: I416e42137e59e04f7fd282aa309f2f89cf574209
Story: #2002977
Task: #22985
This commit is contained in:
Kaifeng Wang 2018-07-18 16:51:53 +08:00
parent 7991f12e17
commit 1ad6f69593
3 changed files with 31 additions and 5 deletions

View File

@ -106,15 +106,15 @@ def _background_introspect_locked(node_info, ironic):
ironic.node.set_boot_device(node_info.uuid, 'pxe',
persistent=False)
except Exception as exc:
LOG.warning('Failed to set boot device to PXE: %s',
exc, node_info=node_info)
raise utils.Error(_('Failed to set boot device to PXE: %s') % exc,
node_info=node_info)
try:
ironic.node.set_power_state(node_info.uuid, 'reboot')
except Exception as exc:
raise utils.Error(_('Failed to power on the node, check it\'s '
'power management configuration: %s'),
exc, node_info=node_info)
'power management configuration: %s') % exc,
node_info=node_info)
LOG.info('Introspection started successfully',
node_info=node_info)
else:

View File

@ -122,7 +122,6 @@ class TestIntrospect(BaseTest):
def test_power_failure(self, client_mock, start_mock):
cli = self._prepare(client_mock)
cli.node.set_boot_device.side_effect = exceptions.BadRequest()
cli.node.set_power_state.side_effect = exceptions.BadRequest()
start_mock.return_value = self.node_info
@ -163,6 +162,28 @@ class TestIntrospect(BaseTest):
self.node_info.acquire_lock.assert_called_once_with()
self.node_info.release_lock.assert_called_once_with()
def test_set_boot_device_failure(self, client_mock, start_mock):
cli = self._prepare(client_mock)
cli.node.set_boot_device.side_effect = exceptions.BadRequest()
start_mock.return_value = self.node_info
introspect.introspect(self.node.uuid)
cli.node.get.assert_called_once_with(self.uuid)
start_mock.assert_called_once_with(self.uuid,
bmc_address=self.bmc_address,
manage_boot=True,
ironic=cli)
cli.node.set_boot_device.assert_called_once_with(self.uuid,
'pxe',
persistent=False)
cli.node.set_power_state.assert_not_called()
start_mock.return_value.finished.assert_called_once_with(
introspect.istate.Events.error, error=mock.ANY)
self.node_info.acquire_lock.assert_called_once_with()
self.node_info.release_lock.assert_called_once_with()
def test_no_macs(self, client_mock, start_mock):
cli = self._prepare(client_mock)
self.node_info.ports.return_value = []

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Stops introspection when setting boot device is failed, as the node is
not guarenteed to perform a PXE boot in this case.