diff --git a/ironic_inspector/plugins/base.py b/ironic_inspector/plugins/base.py index 3d2a12a5b..87d807dc4 100644 --- a/ironic_inspector/plugins/base.py +++ b/ironic_inspector/plugins/base.py @@ -145,6 +145,21 @@ _ACTIONS_MGR = None _INTROSPECTION_DATA_MGR = None +def reset(): + """Reset cached managers.""" + global _HOOKS_MGR + global _NOT_FOUND_HOOK_MGR + global _CONDITIONS_MGR + global _ACTIONS_MGR + global _INTROSPECTION_DATA_MGR + + _HOOKS_MGR = None + _NOT_FOUND_HOOK_MGR = None + _CONDITIONS_MGR = None + _ACTIONS_MGR = None + _INTROSPECTION_DATA_MGR = None + + def missing_entrypoints_callback(names): """Raise MissingHookError with comma-separated list of missing hooks""" error = _('The following hook(s) are missing or failed to load: %s') diff --git a/ironic_inspector/test/base.py b/ironic_inspector/test/base.py index 12c8605d1..2a3b66dd5 100644 --- a/ironic_inspector/test/base.py +++ b/ironic_inspector/test/base.py @@ -50,7 +50,7 @@ class BaseTest(test_base.BaseTestCase): db.Base.metadata.create_all(engine) engine.connect() self.addCleanup(engine.dispose) - plugins_base._HOOKS_MGR = None + plugins_base.reset() node_cache._SEMAPHORES = lockutils.Semaphores() patch = mock.patch.object(i18n, '_', lambda s: s) patch.start() diff --git a/ironic_inspector/test/unit/test_main.py b/ironic_inspector/test/unit/test_main.py index 800701bed..690f8ce70 100644 --- a/ironic_inspector/test/unit/test_main.py +++ b/ironic_inspector/test/unit/test_main.py @@ -659,7 +659,6 @@ class TestPlugins(unittest.TestCase): @mock.patch.object(example_plugin.ExampleProcessingHook, 'before_update', autospec=True) def test_hook(self, mock_post, mock_pre): - plugins_base._HOOKS_MGR = None CONF.set_override('processing_hooks', 'example', 'processing') mgr = plugins_base.processing_hooks_manager() mgr.map_method('before_processing', 'introspection_data') diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py index 297985aa0..3d89630ac 100644 --- a/ironic_inspector/test/unit/test_process.py +++ b/ironic_inspector/test/unit/test_process.py @@ -209,7 +209,6 @@ class TestProcess(BaseProcessTest): self.assertFalse(self.node_info.finished.called) def test_error_if_node_not_found_hook(self): - plugins_base._NOT_FOUND_HOOK_MGR = None self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM') self.assertRaisesRegex(utils.Error, 'Look up error: BOOM', @@ -221,7 +220,6 @@ class TestProcess(BaseProcessTest): class TestNodeNotFoundHook(BaseProcessTest): def test_node_not_found_hook_run_ok(self, hook_mock): CONF.set_override('node_not_found_hook', 'example', 'processing') - plugins_base._NOT_FOUND_HOOK_MGR = None self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM') hook_mock.return_value = node_cache.NodeInfo( uuid=self.node.uuid, @@ -232,7 +230,6 @@ class TestNodeNotFoundHook(BaseProcessTest): def test_node_not_found_hook_run_none(self, hook_mock): CONF.set_override('node_not_found_hook', 'example', 'processing') - plugins_base._NOT_FOUND_HOOK_MGR = None self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM') hook_mock.return_value = None self.assertRaisesRegex(utils.Error, @@ -242,7 +239,6 @@ class TestNodeNotFoundHook(BaseProcessTest): def test_node_not_found_hook_exception(self, hook_mock): CONF.set_override('node_not_found_hook', 'example', 'processing') - plugins_base._NOT_FOUND_HOOK_MGR = None self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM') hook_mock.side_effect = Exception('Hook Error') self.assertRaisesRegex(utils.Error, @@ -398,7 +394,6 @@ class TestProcessNode(BaseTest): started_at=self.node_info.started_at, finished_at=self.node_info.finished_at, error=self.node_info.error).save(self.session) - plugins_base._INTROSPECTION_DATA_MGR = None def test_return_includes_uuid(self): ret_val = process._process_node(self.node_info, self.node, self.data) @@ -670,7 +665,6 @@ class TestReapplyNode(BaseTest): post_hook_mock): CONF.set_override('processing_hooks', 'example', 'processing') - plugins_base._HOOKS_MGR = None exc = Exception('Failed.') swift_mock.get_object.return_value = json.dumps(self.data)