do not emit warnings for missing hooks

Add a flag to disable the default warning log messages in the
NamedExtensionManager and then have the HookManager pass False by
default.

Change-Id: I78c91bcfd8cd41929f25057791157f82eb4a3a50
Closes-Bug: #1611387
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-08-09 13:30:08 -04:00
parent 0c6b78cf88
commit 62398ed4a3
2 changed files with 23 additions and 3 deletions

View File

@ -27,12 +27,25 @@ class HookManager(NamedExtensionManager):
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
:type on_missing_entrypoints_callback: function
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:param warn_on_missing_entrypoint: Flag to control whether failing
to load a plugin is reported via a log mess. Only applies if
on_missing_entrypoints_callback is None.
:type warn_on_missing_entrypoint: bool
"""
def __init__(self, namespace, name,
invoke_on_load=False, invoke_args=(), invoke_kwds={},
on_load_failure_callback=None,
verify_requirements=False):
verify_requirements=False,
on_missing_entrypoints_callback=None,
# NOTE(dhellmann): This default is different from the
# base class because for hooks it is less likely to
# be an error to have no entry points present.
warn_on_missing_entrypoint=False):
super(HookManager, self).__init__(
namespace,
[name],
@ -40,7 +53,9 @@ class HookManager(NamedExtensionManager):
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
on_load_failure_callback=on_load_failure_callback,
on_missing_entrypoints_callback=on_missing_entrypoints_callback,
verify_requirements=verify_requirements,
warn_on_missing_entrypoint=warn_on_missing_entrypoint,
)
def _init_attributes(self, namespace, names, name_order=False,

View File

@ -45,6 +45,10 @@ class NamedExtensionManager(ExtensionManager):
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
:param warn_on_missing_entrypoint: Flag to control whether failing
to load a plugin is reported via a log mess. Only applies if
on_missing_entrypoints_callback is None.
:type warn_on_missing_entrypoint: bool
"""
@ -53,7 +57,8 @@ class NamedExtensionManager(ExtensionManager):
name_order=False, propagate_map_exceptions=False,
on_load_failure_callback=None,
on_missing_entrypoints_callback=None,
verify_requirements=False):
verify_requirements=False,
warn_on_missing_entrypoint=True):
self._init_attributes(
namespace, names, name_order=name_order,
propagate_map_exceptions=propagate_map_exceptions,
@ -66,7 +71,7 @@ class NamedExtensionManager(ExtensionManager):
if self._missing_names:
if on_missing_entrypoints_callback:
on_missing_entrypoints_callback(self._missing_names)
else:
elif warn_on_missing_entrypoint:
LOG.warning('Could not load %s' %
', '.join(self._missing_names))
self._init_plugins(extensions)