Skip to content

Commit aa88db9

Browse files
committed
Add callback on plugin load failure
I have seen a few cases where import errors (distutils - I am looking at you) result in an extension not being available, but there is no indication why this is the case. We do configure logging, but this happens too late (as part of the 'cliff.app.App.run' call to execute a command, which calls osc-lib's 'configure_logging' but which happens long after we've tried to import our plugins) to be of any use. Instead, make use of a callback to make it more obvious. Change-Id: Id68b06161e445b79fe43f463e06cda3c4771ef02 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 37a22cf commit aa88db9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

openstackclient/common/clientmanager.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,22 @@ def is_volume_endpoint_enabled(self, volume_client):
158158
# Plugin Support
159159

160160

161+
def _on_load_failure_callback(
162+
manager: stevedore.ExtensionManager,
163+
ep: importlib.metadata.EntryPoint,
164+
err: Exception,
165+
) -> None:
166+
sys.stderr.write(
167+
f"WARNING: Failed to import plugin {ep.group}:{ep.name}: {err}.\n"
168+
)
169+
170+
161171
def get_plugin_modules(group):
162172
"""Find plugin entry points"""
163173
mod_list = []
164-
mgr = stevedore.ExtensionManager(group)
174+
mgr = stevedore.ExtensionManager(
175+
group, on_load_failure_callback=_on_load_failure_callback
176+
)
165177
for ep in mgr:
166178
LOG.debug('Found plugin %s', ep.name)
167179

@@ -180,9 +192,8 @@ def get_plugin_modules(group):
180192
module = importlib.import_module(module_name)
181193
except Exception as err:
182194
sys.stderr.write(
183-
"WARNING: Failed to import plugin {}: {}.\n".format(
184-
ep.name, err
185-
)
195+
f"WARNING: Failed to import plugin {ep.group}:{ep.name}: "
196+
f"{err}.\n"
186197
)
187198
continue
188199

0 commit comments

Comments
 (0)