Merge "Add callback function to manage missing hooks"

This commit is contained in:
Jenkins 2016-08-09 17:17:56 +00:00 committed by Gerrit Code Review
commit 36251082c5
3 changed files with 14 additions and 3 deletions

View File

@ -411,8 +411,9 @@ class Service(object):
hooks = [ext.name for ext in
plugins_base.processing_hooks_manager()]
except KeyError as exc:
# stevedore raises KeyError on missing hook
LOG.critical(_LC('Hook %s failed to load or was not found'),
# callback function raises MissingHookError derived from KeyError
# on missing hook
LOG.critical(_LC('Hook(s) %s failed to load or was not found'),
str(exc))
sys.exit(1)

View File

@ -149,6 +149,12 @@ _CONDITIONS_MGR = None
_ACTIONS_MGR = None
def missing_entrypoints_callback(names):
"""Raise MissingHookError with comma-separated list of missing hooks"""
missing_names = ', '.join(names)
raise MissingHookError(missing_names)
def processing_hooks_manager(*args):
"""Create a Stevedore extension manager for processing hooks.
@ -164,6 +170,7 @@ def processing_hooks_manager(*args):
names=names,
invoke_on_load=True,
invoke_args=args,
on_missing_entrypoints_callback=missing_entrypoints_callback,
name_order=True)
return _HOOKS_MGR
@ -204,3 +211,7 @@ def rule_actions_manager():
'actions is deprecated (action "%s")'),
act.name)
return _ACTIONS_MGR
class MissingHookError(KeyError):
"""Exception when hook is not found when processing it."""

View File

@ -626,7 +626,6 @@ class TestInit(test_base.BaseTest):
self.service.init()
self.assertFalse(mock_firewall.called)
@unittest.skip('skipped until stevedore > 1.15.0 is released')
@mock.patch.object(main.LOG, 'critical')
def test_init_failed_processing_hook(self, mock_log, mock_node_cache,
mock_get_client, mock_auth,