Introspection data storage backend follow up
An issue is spotted during implementing [1], we have a solely code path from api, do_reapply, reapply, to _reapply. Inspector now reads intrspection data ahead, so there is no need to do so in _reapply, reading introspection data there is never reached. The patch removes unecessary code and corresponding tests. [1] https://storyboard.openstack.org/#!/story/1564863 Change-Id: I5558bce2bc49de3d1c5dba59e203de4824a3addd Story: 1726713 Task: 11373
This commit is contained in:
parent
13e70283b1
commit
9f8f3fc08d
|
@ -311,26 +311,10 @@ def reapply(node_ident, data=None):
|
|||
utils.executor().submit(_reapply, node_info, data)
|
||||
|
||||
|
||||
def _reapply(node_info, data=None):
|
||||
def _reapply(node_info, introspection_data=None):
|
||||
# runs in background
|
||||
try:
|
||||
node_info.started_at = timeutils.utcnow()
|
||||
node_info.commit()
|
||||
if data:
|
||||
introspection_data = data
|
||||
else:
|
||||
introspection_data = get_introspection_data(node_info.uuid,
|
||||
processed=False,
|
||||
get_json=True)
|
||||
except Exception as exc:
|
||||
LOG.exception('Encountered exception while fetching '
|
||||
'stored introspection data',
|
||||
node_info=node_info)
|
||||
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(istate.Events.error, error=msg)
|
||||
return
|
||||
node_info.started_at = timeutils.utcnow()
|
||||
node_info.commit()
|
||||
|
||||
try:
|
||||
ironic = ir_utils.get_client()
|
||||
|
@ -344,6 +328,9 @@ def _reapply(node_info, data=None):
|
|||
try:
|
||||
_reapply_with_data(node_info, introspection_data)
|
||||
except Exception as exc:
|
||||
msg = (_('Failed reapply for node %(node)s, Error: '
|
||||
'%(exc)s') % {'node': node_info.uuid, 'exc': exc})
|
||||
LOG.error(msg, node_info=node_info, data=introspection_data)
|
||||
return
|
||||
|
||||
_finish(node_info, ironic, introspection_data,
|
||||
|
|
|
@ -574,7 +574,8 @@ class TestReapply(BaseTest):
|
|||
blocking=False
|
||||
)
|
||||
|
||||
reapply_mock.assert_called_once_with(pop_mock.return_value, data=None)
|
||||
reapply_mock.assert_called_once_with(pop_mock.return_value,
|
||||
introspection_data=None)
|
||||
|
||||
@prepare_mocks
|
||||
def test_locking_failed(self, pop_mock, reapply_mock):
|
||||
|
@ -621,7 +622,7 @@ class TestReapplyNode(BaseTest):
|
|||
error=self.node_info.error).save(self.session)
|
||||
|
||||
def call(self):
|
||||
process._reapply(self.node_info)
|
||||
process._reapply(self.node_info, introspection_data=self.data)
|
||||
# make sure node_info lock is released after a call
|
||||
self.node_info.release_lock.assert_called_once_with(self.node_info)
|
||||
|
||||
|
@ -637,20 +638,14 @@ class TestReapplyNode(BaseTest):
|
|||
|
||||
@prepare_mocks
|
||||
def test_ok(self, finished_mock, swift_mock, apply_mock, post_hook_mock):
|
||||
swift_name = 'inspector_data-%s' % self.uuid
|
||||
swift_mock.get_object.return_value = json.dumps(self.data)
|
||||
|
||||
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)
|
||||
swift_mock.create_object.assert_called_once_with(swift_name,
|
||||
mock.ANY)
|
||||
swifted_data = json.loads(swift_mock.create_object.call_args[0][1])
|
||||
|
||||
self.node_info.invalidate_cache.assert_called_once_with()
|
||||
apply_mock.assert_called_once_with(self.node_info, swifted_data)
|
||||
apply_mock.assert_called_once_with(self.node_info, self.data)
|
||||
|
||||
# assert no power operations were performed
|
||||
self.assertFalse(self.cli.node.set_power_state.called)
|
||||
|
@ -658,34 +653,18 @@ class TestReapplyNode(BaseTest):
|
|||
self.node_info, istate.Events.finish)
|
||||
|
||||
# asserting validate_interfaces was called
|
||||
self.assertEqual(self.pxe_interfaces, swifted_data['interfaces'])
|
||||
self.assertEqual([self.pxe_mac], swifted_data['macs'])
|
||||
self.assertEqual(self.pxe_interfaces, self.data['interfaces'])
|
||||
self.assertEqual([self.pxe_mac], self.data['macs'])
|
||||
|
||||
# assert ports were created with whatever there was left
|
||||
# behind validate_interfaces
|
||||
self.cli.port.create.assert_called_once_with(
|
||||
node_uuid=self.uuid,
|
||||
address=swifted_data['macs'][0],
|
||||
address=self.data['macs'][0],
|
||||
extra={},
|
||||
pxe_enabled=True
|
||||
)
|
||||
|
||||
@prepare_mocks
|
||||
def test_get_incomming_data_exception(self, finished_mock, 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
|
||||
self.call()
|
||||
|
||||
self.commit_fixture.mock.assert_called_once_with(self.node_info)
|
||||
self.assertFalse(swift_mock.create_object.called)
|
||||
self.assertFalse(apply_mock.called)
|
||||
self.assertFalse(post_hook_mock.called)
|
||||
finished_mock.assert_called_once_with(
|
||||
self.node_info, istate.Events.error, error=expected_error)
|
||||
|
||||
@prepare_mocks
|
||||
def test_prehook_failure(self, finished_mock, swift_mock, apply_mock,
|
||||
post_hook_mock):
|
||||
|
@ -713,17 +692,3 @@ class TestReapplyNode(BaseTest):
|
|||
self.assertFalse(swift_mock.create_object.called)
|
||||
self.assertFalse(apply_mock.called)
|
||||
self.assertFalse(post_hook_mock.called)
|
||||
|
||||
@prepare_mocks
|
||||
def test_generic_exception_creating_ports(self, finished_mock, swift_mock,
|
||||
apply_mock, post_hook_mock):
|
||||
swift_mock.get_object.return_value = json.dumps(self.data)
|
||||
exc = Exception('Oops')
|
||||
self.cli.port.create.side_effect = exc
|
||||
self.call()
|
||||
|
||||
finished_mock.assert_called_once_with(
|
||||
self.node_info, istate.Events.error, error=str(exc))
|
||||
self.assertFalse(swift_mock.create_object.called)
|
||||
self.assertFalse(apply_mock.called)
|
||||
self.assertFalse(post_hook_mock.called)
|
||||
|
|
Loading…
Reference in New Issue