Browse Source

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
Kaifeng Wang 3 months ago
parent
commit
9f8f3fc08d
2 changed files with 13 additions and 61 deletions
  1. 6
    19
      ironic_inspector/process.py
  2. 7
    42
      ironic_inspector/test/unit/test_process.py

+ 6
- 19
ironic_inspector/process.py View File

@@ -311,26 +311,10 @@ def reapply(node_ident, data=None):
311 311
     utils.executor().submit(_reapply, node_info, data)
312 312
 
313 313
 
314
-def _reapply(node_info, data=None):
314
+def _reapply(node_info, introspection_data=None):
315 315
     # runs in background
316
-    try:
317
-        node_info.started_at = timeutils.utcnow()
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
316
+    node_info.started_at = timeutils.utcnow()
317
+    node_info.commit()
334 318
 
335 319
     try:
336 320
         ironic = ir_utils.get_client()
@@ -344,6 +328,9 @@ def _reapply(node_info, data=None):
344 328
     try:
345 329
         _reapply_with_data(node_info, introspection_data)
346 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 334
         return
348 335
 
349 336
     _finish(node_info, ironic, introspection_data,

+ 7
- 42
ironic_inspector/test/unit/test_process.py View File

@@ -574,7 +574,8 @@ class TestReapply(BaseTest):
574 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 580
     @prepare_mocks
580 581
     def test_locking_failed(self, pop_mock, reapply_mock):
@@ -621,7 +622,7 @@ class TestReapplyNode(BaseTest):
621 622
                 error=self.node_info.error).save(self.session)
622 623
 
623 624
     def call(self):
624
-        process._reapply(self.node_info)
625
+        process._reapply(self.node_info, introspection_data=self.data)
625 626
         # make sure node_info lock is released after a call
626 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 639
     @prepare_mocks
639 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 641
         self.call()
644 642
 
645 643
         self.commit_fixture.mock.assert_called_once_with(self.node_info)
646 644
 
647 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 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 650
         # assert no power operations were performed
656 651
         self.assertFalse(self.cli.node.set_power_state.called)
@@ -658,34 +653,18 @@ class TestReapplyNode(BaseTest):
658 653
             self.node_info, istate.Events.finish)
659 654
 
660 655
         # asserting validate_interfaces was called
661
-        self.assertEqual(self.pxe_interfaces, swifted_data['interfaces'])
662
-        self.assertEqual([self.pxe_mac], swifted_data['macs'])
656
+        self.assertEqual(self.pxe_interfaces, self.data['interfaces'])
657
+        self.assertEqual([self.pxe_mac], self.data['macs'])
663 658
 
664 659
         # assert ports were created with whatever there was left
665 660
         # behind validate_interfaces
666 661
         self.cli.port.create.assert_called_once_with(
667 662
             node_uuid=self.uuid,
668
-            address=swifted_data['macs'][0],
663
+            address=self.data['macs'][0],
669 664
             extra={},
670 665
             pxe_enabled=True
671 666
         )
672 667
 
673
-    @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 668
     @prepare_mocks
690 669
     def test_prehook_failure(self, finished_mock, swift_mock, apply_mock,
691 670
                              post_hook_mock):
@@ -713,17 +692,3 @@ class TestReapplyNode(BaseTest):
713 692
         self.assertFalse(swift_mock.create_object.called)
714 693
         self.assertFalse(apply_mock.called)
715 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)

Loading…
Cancel
Save