Add available flag to plugin loaders

Currently when iterating through plugins all plugins are loaded and
returned to the user. This is confusing for things like the kerberos
plugin where the required dependencies may not be available.

Add an available property on plugin loaders. Plugins that do not wish to
be shown to users can set available to false.

The lack of tests on this patch is unfortunate however any testing
involes a lot of mocking at levels lower than keystoneauth interact with
(i've tried). We would need to mock the pkg_resources layer that
stevedore uses and are essentially testing that EnabledExtensionManager
is doing the right thing.

I encourage people to verify this manually.

Closes-Bug: #1589740
Change-Id: I446441467ef32f7bc916221991388ac528df48f4
This commit is contained in:
Jamie Lennox 2016-06-07 10:34:44 +10:00
parent a607e71d4b
commit bc614288b7
1 changed files with 25 additions and 4 deletions

View File

@ -28,6 +28,11 @@ __all__ = ('get_available_plugin_names',
'PLUGIN_NAMESPACE')
def _auth_plugin_available(ext):
"""Read the value of available for whether to load this plugin."""
return ext.obj.available
def get_available_plugin_names():
"""Get the names of all the plugins that are available on the system.
@ -37,7 +42,10 @@ def get_available_plugin_names():
:returns: A list of names.
:rtype: frozenset
"""
mgr = stevedore.ExtensionManager(namespace=PLUGIN_NAMESPACE)
mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE,
check_func=_auth_plugin_available,
invoke_on_load=True,
propagate_map_exceptions=True)
return frozenset(mgr.names())
@ -48,9 +56,10 @@ def get_available_plugin_loaders():
loader as the value.
:rtype: dict
"""
mgr = stevedore.ExtensionManager(namespace=PLUGIN_NAMESPACE,
invoke_on_load=True,
propagate_map_exceptions=True)
mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE,
check_func=_auth_plugin_available,
invoke_on_load=True,
propagate_map_exceptions=True)
return dict(mgr.map(lambda ext: (ext.entry_point.name, ext.obj)))
@ -109,6 +118,18 @@ class BaseLoader(object):
"""
return []
@property
def available(self):
"""Return if the plugin is available for loading.
If a plugin is missing dependencies or for some other reason should not
be available to the current system it should override this property and
return False to exclude itself from the plugin list.
:rtype: bool
"""
return True
def load_from_options(self, **kwargs):
"""Create a plugin from the arguments retrieved from get_options.