From f29a71f576115a6bd8c625aea61dd80e9a3520b5 Mon Sep 17 00:00:00 2001 From: Galyna Zholtkevych Date: Mon, 5 Sep 2016 16:53:00 +0300 Subject: [PATCH] Set node to the error if reapply fails Setting node to the error status with error message if reapply fails to get introspection data from swift. Change-Id: Idccb68847d14d5050c735facf3da7b3ec108adbe Closes-Bug: #1618833 --- ironic_inspector/process.py | 7 +++++-- ironic_inspector/test/unit/test_process.py | 5 ++++- ...-node-to-error-when-swift-failure-3e919ecbf9db6401.yaml | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/set-node-to-error-when-swift-failure-3e919ecbf9db6401.yaml diff --git a/ironic_inspector/process.py b/ironic_inspector/process.py index 083fee486..7c8e90f8b 100644 --- a/ironic_inspector/process.py +++ b/ironic_inspector/process.py @@ -376,11 +376,14 @@ def _reapply(node_info): # runs in background try: introspection_data = _get_unprocessed_data(node_info.uuid) - except Exception: + except Exception as exc: LOG.exception(_LE('Encountered exception while fetching ' 'stored introspection data'), node_info=node_info) - node_info.release_lock() + msg = (_('Unexpected exception %(exc_class)s while fetching ' + 'unprocessed introspection data from Swift: %(error)s') % + {'exc_class': exc.__class__.__name__, 'error': exc}) + node_info.finished(error=msg) return failures = [] diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py index ee726e965..6125aebe4 100644 --- a/ironic_inspector/test/unit/test_process.py +++ b/ironic_inspector/test/unit/test_process.py @@ -656,6 +656,8 @@ class TestReapplyNode(BaseTest): swift_mock, apply_mock, post_hook_mock, ): exc = Exception('Oops') + expected_error = ('Unexpected exception Exception while fetching ' + 'unprocessed introspection data from Swift: Oops') swift_mock.get_object.side_effect = exc with mock.patch.object(process.LOG, 'exception', autospec=True) as log_mock: @@ -669,7 +671,8 @@ class TestReapplyNode(BaseTest): self.assertFalse(swift_mock.create_object.called) self.assertFalse(apply_mock.called) self.assertFalse(post_hook_mock.called) - self.assertFalse(finished_mock.called) + finished_mock.assert_called_once_with(self.node_info, + expected_error) @prepare_mocks def test_prehook_failure(self, finished_mock, swift_mock, diff --git a/releasenotes/notes/set-node-to-error-when-swift-failure-3e919ecbf9db6401.yaml b/releasenotes/notes/set-node-to-error-when-swift-failure-3e919ecbf9db6401.yaml new file mode 100644 index 000000000..e1232a060 --- /dev/null +++ b/releasenotes/notes/set-node-to-error-when-swift-failure-3e919ecbf9db6401.yaml @@ -0,0 +1,3 @@ +fixes: + - Set the node to the error state when it + failed get data from swift.