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
This commit is contained in:
Anton Arefiev 2016-03-07 17:20:23 +02:00
parent e8ecb99122
commit 2cbcfcd2a4
3 changed files with 27 additions and 5 deletions

View File

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

View File

@ -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')

View File

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