Merge "use stevedore to load util plugins"

This commit is contained in:
Zuul 2020-08-05 09:16:42 +00:00 committed by Gerrit Code Review
commit 20cfe02dc1
2 changed files with 12 additions and 6 deletions

View File

@ -15,13 +15,13 @@
import collections import collections
import os import os
import pkg_resources
import sys import sys
import uuid import uuid
import prettytable import prettytable
import six import six
from six.moves.urllib import parse from six.moves.urllib import parse
import stevedore
from cinderclient import exceptions from cinderclient import exceptions
from oslo_utils import encodeutils from oslo_utils import encodeutils
@ -330,11 +330,16 @@ def safe_issubclass(*args):
def _load_entry_point(ep_name, name=None): def _load_entry_point(ep_name, name=None):
"""Try to load the entry point ep_name that matches name.""" """Try to load the entry point ep_name that matches name."""
for ep in pkg_resources.iter_entry_points(ep_name, name=name): mgr = stevedore.NamedExtensionManager(
namespace=ep_name,
names=[name],
# Ignore errors on load
on_load_failure_callback=lambda mgr, entry_point, error: None,
)
try: try:
return ep.load() return mgr[name].plugin
except (ImportError, pkg_resources.UnknownExtra, AttributeError): except KeyError:
continue pass
def get_function_name(func): def get_function_name(func):

View File

@ -9,3 +9,4 @@ six>=1.10.0 # MIT
oslo.i18n>=3.15.3 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0
requests!=2.20.0,>=2.14.2 # Apache-2.0 requests!=2.20.0,>=2.14.2 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0