summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2019-01-24 17:21:58 +0800
committerKaifeng Wang <kaifeng.w@gmail.com>2019-01-24 17:33:00 +0800
commit9f8f3fc08ddbc9c40e68359987621d3575b07cfc (patch)
tree7263f9841e938201fb179c79bea58188cd81060b
parent13e70283b13e1c4e65a965197f23709ce9343e80 (diff)
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
Notes
Notes (review): Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Code-Review+2: Julia Kreger <juliaashleykreger@gmail.com> Workflow+1: Julia Kreger <juliaashleykreger@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 13 Feb 2019 18:45:28 +0000 Reviewed-on: https://review.openstack.org/632969 Project: openstack/ironic-inspector Branch: refs/heads/master
-rw-r--r--ironic_inspector/process.py25
-rw-r--r--ironic_inspector/test/unit/test_process.py49
2 files changed, 13 insertions, 61 deletions
diff --git a/ironic_inspector/process.py b/ironic_inspector/process.py
index 4f86bbe..d41a761 100644
--- a/ironic_inspector/process.py
+++ b/ironic_inspector/process.py
@@ -311,26 +311,10 @@ def reapply(node_ident, data=None):
311 utils.executor().submit(_reapply, node_info, data) 311 utils.executor().submit(_reapply, node_info, data)
312 312
313 313
314def _reapply(node_info, data=None): 314def _reapply(node_info, introspection_data=None):
315 # runs in background 315 # runs in background
316 try: 316 node_info.started_at = timeutils.utcnow()
317 node_info.started_at = timeutils.utcnow() 317 node_info.commit()
318 node_info.commit()
319 if data:
320 introspection_data = data
321 else:
322 introspection_data = get_introspection_data(node_info.uuid,
323 processed=False,
324 get_json=True)
325 except Exception as exc:
326 LOG.exception('Encountered exception while fetching '
327 'stored introspection data',
328 node_info=node_info)
329 msg = (_('Unexpected exception %(exc_class)s while fetching '
330 'unprocessed introspection data from Swift: %(error)s') %
331 {'exc_class': exc.__class__.__name__, 'error': exc})
332 node_info.finished(istate.Events.error, error=msg)
333 return
334 318
335 try: 319 try:
336 ironic = ir_utils.get_client() 320 ironic = ir_utils.get_client()
@@ -344,6 +328,9 @@ def _reapply(node_info, data=None):
344 try: 328 try:
345 _reapply_with_data(node_info, introspection_data) 329 _reapply_with_data(node_info, introspection_data)
346 except Exception as exc: 330 except Exception as exc:
331 msg = (_('Failed reapply for node %(node)s, Error: '
332 '%(exc)s') % {'node': node_info.uuid, 'exc': exc})
333 LOG.error(msg, node_info=node_info, data=introspection_data)
347 return 334 return
348 335
349 _finish(node_info, ironic, introspection_data, 336 _finish(node_info, ironic, introspection_data,
diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py
index 739ae55..297985a 100644
--- a/ironic_inspector/test/unit/test_process.py
+++ b/ironic_inspector/test/unit/test_process.py
@@ -574,7 +574,8 @@ class TestReapply(BaseTest):
574 blocking=False 574 blocking=False
575 ) 575 )
576 576
577 reapply_mock.assert_called_once_with(pop_mock.return_value, data=None) 577 reapply_mock.assert_called_once_with(pop_mock.return_value,
578 introspection_data=None)
578 579
579 @prepare_mocks 580 @prepare_mocks
580 def test_locking_failed(self, pop_mock, reapply_mock): 581 def test_locking_failed(self, pop_mock, reapply_mock):
@@ -621,7 +622,7 @@ class TestReapplyNode(BaseTest):
621 error=self.node_info.error).save(self.session) 622 error=self.node_info.error).save(self.session)
622 623
623 def call(self): 624 def call(self):
624 process._reapply(self.node_info) 625 process._reapply(self.node_info, introspection_data=self.data)
625 # make sure node_info lock is released after a call 626 # make sure node_info lock is released after a call
626 self.node_info.release_lock.assert_called_once_with(self.node_info) 627 self.node_info.release_lock.assert_called_once_with(self.node_info)
627 628
@@ -637,20 +638,14 @@ class TestReapplyNode(BaseTest):
637 638
638 @prepare_mocks 639 @prepare_mocks
639 def test_ok(self, finished_mock, swift_mock, apply_mock, post_hook_mock): 640 def test_ok(self, finished_mock, swift_mock, apply_mock, post_hook_mock):
640 swift_name = 'inspector_data-%s' % self.uuid
641 swift_mock.get_object.return_value = json.dumps(self.data)
642
643 self.call() 641 self.call()
644 642
645 self.commit_fixture.mock.assert_called_once_with(self.node_info) 643 self.commit_fixture.mock.assert_called_once_with(self.node_info)
646 644
647 post_hook_mock.assert_called_once_with(mock.ANY, self.node_info) 645 post_hook_mock.assert_called_once_with(mock.ANY, self.node_info)
648 swift_mock.create_object.assert_called_once_with(swift_name,
649 mock.ANY)
650 swifted_data = json.loads(swift_mock.create_object.call_args[0][1])
651 646
652 self.node_info.invalidate_cache.assert_called_once_with() 647 self.node_info.invalidate_cache.assert_called_once_with()
653 apply_mock.assert_called_once_with(self.node_info, swifted_data) 648 apply_mock.assert_called_once_with(self.node_info, self.data)
654 649
655 # assert no power operations were performed 650 # assert no power operations were performed
656 self.assertFalse(self.cli.node.set_power_state.called) 651 self.assertFalse(self.cli.node.set_power_state.called)
@@ -658,35 +653,19 @@ class TestReapplyNode(BaseTest):
658 self.node_info, istate.Events.finish) 653 self.node_info, istate.Events.finish)
659 654
660 # asserting validate_interfaces was called 655 # asserting validate_interfaces was called
661 self.assertEqual(self.pxe_interfaces, swifted_data['interfaces']) 656 self.assertEqual(self.pxe_interfaces, self.data['interfaces'])
662 self.assertEqual([self.pxe_mac], swifted_data['macs']) 657 self.assertEqual([self.pxe_mac], self.data['macs'])
663 658
664 # assert ports were created with whatever there was left 659 # assert ports were created with whatever there was left
665 # behind validate_interfaces 660 # behind validate_interfaces
666 self.cli.port.create.assert_called_once_with( 661 self.cli.port.create.assert_called_once_with(
667 node_uuid=self.uuid, 662 node_uuid=self.uuid,
668 address=swifted_data['macs'][0], 663 address=self.data['macs'][0],
669 extra={}, 664 extra={},
670 pxe_enabled=True 665 pxe_enabled=True
671 ) 666 )
672 667
673 @prepare_mocks 668 @prepare_mocks
674 def test_get_incomming_data_exception(self, finished_mock, swift_mock,
675 apply_mock, post_hook_mock):
676 exc = Exception('Oops')
677 expected_error = ('Unexpected exception Exception while fetching '
678 'unprocessed introspection data from Swift: Oops')
679 swift_mock.get_object.side_effect = exc
680 self.call()
681
682 self.commit_fixture.mock.assert_called_once_with(self.node_info)
683 self.assertFalse(swift_mock.create_object.called)
684 self.assertFalse(apply_mock.called)
685 self.assertFalse(post_hook_mock.called)
686 finished_mock.assert_called_once_with(
687 self.node_info, istate.Events.error, error=expected_error)
688
689 @prepare_mocks
690 def test_prehook_failure(self, finished_mock, swift_mock, apply_mock, 669 def test_prehook_failure(self, finished_mock, swift_mock, apply_mock,
691 post_hook_mock): 670 post_hook_mock):
692 CONF.set_override('processing_hooks', 'example', 671 CONF.set_override('processing_hooks', 'example',
@@ -713,17 +692,3 @@ class TestReapplyNode(BaseTest):
713 self.assertFalse(swift_mock.create_object.called) 692 self.assertFalse(swift_mock.create_object.called)
714 self.assertFalse(apply_mock.called) 693 self.assertFalse(apply_mock.called)
715 self.assertFalse(post_hook_mock.called) 694 self.assertFalse(post_hook_mock.called)
716
717 @prepare_mocks
718 def test_generic_exception_creating_ports(self, finished_mock, swift_mock,
719 apply_mock, post_hook_mock):
720 swift_mock.get_object.return_value = json.dumps(self.data)
721 exc = Exception('Oops')
722 self.cli.port.create.side_effect = exc
723 self.call()
724
725 finished_mock.assert_called_once_with(
726 self.node_info, istate.Events.error, error=str(exc))
727 self.assertFalse(swift_mock.create_object.called)
728 self.assertFalse(apply_mock.called)
729 self.assertFalse(post_hook_mock.called)