Merge "Reset cached extension managers in the unit tests"

This commit is contained in:
Zuul 2019-03-12 18:31:28 +00:00 committed by Gerrit Code Review
commit 26eaf10a64
4 changed files with 16 additions and 8 deletions

View File

@ -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')

View File

@ -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()

View File

@ -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')

View File

@ -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)