From bc614288b7766bee296ae748b7b8029e170ce2ad Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Tue, 7 Jun 2016 10:34:44 +1000 Subject: [PATCH] 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 --- keystoneauth1/loading/base.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/keystoneauth1/loading/base.py b/keystoneauth1/loading/base.py index 1a93f2e3..31277d2c 100644 --- a/keystoneauth1/loading/base.py +++ b/keystoneauth1/loading/base.py @@ -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.