Reapply doesn't update started_at time
The reapply API/Action(openstack baremetal introspection reprocess UUID) doesn't update the started_at time when Ironic Inspector begins processing the node. This adds the started_at time when the reapply API/Action is performed. Change-Id: Ic79db4ba9305841fb662afcb56f556ad4a57a500 Closes-Bug: #1625180
This commit is contained in:
parent
6bf5bc8228
commit
43c89efcb7
@ -23,6 +23,7 @@ import json
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import base64
|
from oslo_serialization import base64
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
from ironic_inspector.common.i18n import _, _LE, _LI, _LW
|
from ironic_inspector.common.i18n import _, _LE, _LI, _LW
|
||||||
from ironic_inspector.common import ironic as ir_utils
|
from ironic_inspector.common import ironic as ir_utils
|
||||||
@ -389,6 +390,8 @@ def reapply(node_ident):
|
|||||||
def _reapply(node_info):
|
def _reapply(node_info):
|
||||||
# runs in background
|
# runs in background
|
||||||
try:
|
try:
|
||||||
|
node_info.started_at = timeutils.utcnow()
|
||||||
|
node_info.commit()
|
||||||
introspection_data = _get_unprocessed_data(node_info.uuid)
|
introspection_data = _get_unprocessed_data(node_info.uuid)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
LOG.exception(_LE('Encountered exception while fetching '
|
LOG.exception(_LE('Encountered exception while fetching '
|
||||||
|
@ -561,6 +561,7 @@ class Test(Base):
|
|||||||
eventlet.greenthread.sleep(DEFAULT_SLEEP)
|
eventlet.greenthread.sleep(DEFAULT_SLEEP)
|
||||||
|
|
||||||
status = self.call_get_status(self.uuid)
|
status = self.call_get_status(self.uuid)
|
||||||
|
inspect_started_at = timeutils.parse_isotime(status['started_at'])
|
||||||
self.check_status(status, finished=True)
|
self.check_status(status, finished=True)
|
||||||
|
|
||||||
res = self.call_reapply(self.uuid)
|
res = self.call_reapply(self.uuid)
|
||||||
@ -568,6 +569,13 @@ class Test(Base):
|
|||||||
self.assertEqual('', res.text)
|
self.assertEqual('', res.text)
|
||||||
eventlet.greenthread.sleep(DEFAULT_SLEEP)
|
eventlet.greenthread.sleep(DEFAULT_SLEEP)
|
||||||
|
|
||||||
|
status = self.call_get_status(self.uuid)
|
||||||
|
self.check_status(status, finished=True)
|
||||||
|
|
||||||
|
# checks the started_at updated in DB is correct
|
||||||
|
reapply_started_at = timeutils.parse_isotime(status['started_at'])
|
||||||
|
self.assertLess(inspect_started_at, reapply_started_at)
|
||||||
|
|
||||||
# reapply request data
|
# reapply request data
|
||||||
get_mock.assert_called_once_with(self.uuid,
|
get_mock.assert_called_once_with(self.uuid,
|
||||||
suffix='UNPROCESSED')
|
suffix='UNPROCESSED')
|
||||||
|
@ -613,6 +613,9 @@ class TestReapplyNode(BaseTest):
|
|||||||
self.cli.node.update.return_value = self.node
|
self.cli.node.update.return_value = self.node
|
||||||
self.cli.node.list_ports.return_value = []
|
self.cli.node.list_ports.return_value = []
|
||||||
self.node_info._state = istate.States.finished
|
self.node_info._state = istate.States.finished
|
||||||
|
self.commit_fixture = self.useFixture(
|
||||||
|
fixtures.MockPatchObject(node_cache.NodeInfo, 'commit',
|
||||||
|
autospec=True))
|
||||||
db.Node(uuid=self.node_info.uuid, state=self.node_info._state,
|
db.Node(uuid=self.node_info.uuid, state=self.node_info._state,
|
||||||
started_at=self.node_info.started_at,
|
started_at=self.node_info.started_at,
|
||||||
finished_at=self.node_info.finished_at,
|
finished_at=self.node_info.finished_at,
|
||||||
@ -641,6 +644,8 @@ class TestReapplyNode(BaseTest):
|
|||||||
|
|
||||||
self.call()
|
self.call()
|
||||||
|
|
||||||
|
self.commit_fixture.mock.assert_called_once_with(self.node_info)
|
||||||
|
|
||||||
post_hook_mock.assert_called_once_with(mock.ANY, self.node_info)
|
post_hook_mock.assert_called_once_with(mock.ANY, self.node_info)
|
||||||
swift_mock.create_object.assert_called_once_with(swift_name,
|
swift_mock.create_object.assert_called_once_with(swift_name,
|
||||||
mock.ANY)
|
mock.ANY)
|
||||||
@ -668,13 +673,14 @@ class TestReapplyNode(BaseTest):
|
|||||||
@prepare_mocks
|
@prepare_mocks
|
||||||
def test_get_incomming_data_exception(self, finished_mock,
|
def test_get_incomming_data_exception(self, finished_mock,
|
||||||
swift_mock, apply_mock,
|
swift_mock, apply_mock,
|
||||||
post_hook_mock, ):
|
post_hook_mock):
|
||||||
exc = Exception('Oops')
|
exc = Exception('Oops')
|
||||||
expected_error = ('Unexpected exception Exception while fetching '
|
expected_error = ('Unexpected exception Exception while fetching '
|
||||||
'unprocessed introspection data from Swift: Oops')
|
'unprocessed introspection data from Swift: Oops')
|
||||||
swift_mock.get_object.side_effect = exc
|
swift_mock.get_object.side_effect = exc
|
||||||
self.call()
|
self.call()
|
||||||
|
|
||||||
|
self.commit_fixture.mock.assert_called_once_with(self.node_info)
|
||||||
self.assertFalse(swift_mock.create_object.called)
|
self.assertFalse(swift_mock.create_object.called)
|
||||||
self.assertFalse(apply_mock.called)
|
self.assertFalse(apply_mock.called)
|
||||||
self.assertFalse(post_hook_mock.called)
|
self.assertFalse(post_hook_mock.called)
|
||||||
@ -683,7 +689,7 @@ class TestReapplyNode(BaseTest):
|
|||||||
|
|
||||||
@prepare_mocks
|
@prepare_mocks
|
||||||
def test_prehook_failure(self, finished_mock, swift_mock,
|
def test_prehook_failure(self, finished_mock, swift_mock,
|
||||||
apply_mock, post_hook_mock, ):
|
apply_mock, post_hook_mock):
|
||||||
CONF.set_override('processing_hooks', 'example',
|
CONF.set_override('processing_hooks', 'example',
|
||||||
'processing')
|
'processing')
|
||||||
plugins_base._HOOKS_MGR = None
|
plugins_base._HOOKS_MGR = None
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- The POST /v1/introspection/<Node ID>/data/unprocessed API updates the
|
||||||
|
started_at time when ironic inspector begins processing the node.
|
Loading…
Reference in New Issue
Block a user