From 2cbcfcd2a4d680455a7f8a2a3d20b3155af186ee Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Mon, 7 Mar 2016 17:20:23 +0200 Subject: [PATCH] Don't fail on power off if in enroll state With enroll hook it's possible to process nodes in enroll state. As nodes in this state are not expected to have valid power credentials, we shouldn't fail if power off goes wrong. Change-Id: I79e502052c4ae1b531b4f0a0bc314b4cf6d29aac --- ironic_inspector/process.py | 16 +++++++++++----- ironic_inspector/test/test_process.py | 12 ++++++++++++ ...n-power-off-enroll-node-e40854f6def397b8.yaml | 4 ++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/no-fail-on-power-off-enroll-node-e40854f6def397b8.yaml diff --git a/ironic_inspector/process.py b/ironic_inspector/process.py index f8c5a32..651f505 100644 --- a/ironic_inspector/process.py +++ b/ironic_inspector/process.py @@ -227,11 +227,17 @@ def _finish(ironic, node_info, introspection_data): try: ironic.node.set_power_state(node_info.uuid, 'off') except Exception as exc: - msg = (_('Failed to power off node %(node)s, check it\'s power ' - 'management configuration: %(exc)s') % - {'node': node_info.uuid, 'exc': exc}) - node_info.finished(error=msg) - raise utils.Error(msg, node_info=node_info, data=introspection_data) + if node_info.node().provision_state == 'enroll': + LOG.info(_LI("Failed to power off the node in 'enroll' state, " + "ignoring; error was %s") % exc, + node_info=node_info, data=introspection_data) + else: + msg = (_('Failed to power off node %(node)s, check it\'s ' + 'power management configuration: %(exc)s') % + {'node': node_info.uuid, 'exc': exc}) + node_info.finished(error=msg) + raise utils.Error(msg, node_info=node_info, + data=introspection_data) node_info.finished() LOG.info(_LI('Introspection finished successfully'), diff --git a/ironic_inspector/test/test_process.py b/ironic_inspector/test/test_process.py index e16baea..875b1c9 100644 --- a/ironic_inspector/test/test_process.py +++ b/ironic_inspector/test/test_process.py @@ -399,6 +399,18 @@ class TestProcessNode(BaseTest): error='Failed to power off node %s, check it\'s power management' ' configuration: boom' % self.uuid) + @mock.patch.object(node_cache.NodeInfo, 'finished', autospec=True) + def test_power_off_enroll_state(self, finished_mock, filters_mock, + post_hook_mock): + self.node.provision_state = 'enroll' + self.node_info.node = mock.Mock(return_value=self.node) + + self.call() + + self.assertTrue(post_hook_mock.called) + self.assertTrue(self.cli.node.set_power_state.called) + finished_mock.assert_called_once_with(self.node_info) + @mock.patch.object(process.swift, 'SwiftAPI', autospec=True) def test_store_data(self, swift_mock, filters_mock, post_hook_mock): CONF.set_override('store_data', 'swift', 'processing') diff --git a/releasenotes/notes/no-fail-on-power-off-enroll-node-e40854f6def397b8.yaml b/releasenotes/notes/no-fail-on-power-off-enroll-node-e40854f6def397b8.yaml new file mode 100644 index 0000000..6bc33ba --- /dev/null +++ b/releasenotes/notes/no-fail-on-power-off-enroll-node-e40854f6def397b8.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Don't fail on finish power off if node in 'enroll' state. Nodes in + 'enroll' state are not expected to have power credentials.