Skip to content

Commit 4269226

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "switch to stevedore for entry points"
2 parents d0741d7 + 870cf01 commit 4269226

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

lower-constraints.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ six==1.10.0
123123
smmap==0.9.0
124124
statsd==3.2.1
125125
stestr==1.0.0
126-
stevedore==1.20.0
126+
stevedore==2.0.1
127127
sushy==0.1.0
128128
tempest==17.1.0
129129
tenacity==3.2.1

openstackclient/common/clientmanager.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
"""Manage access to the clients, including authenticating when needed."""
1717

18+
import importlib
1819
import logging
1920
import sys
2021

2122
from osc_lib import clientmanager
2223
from osc_lib import shell
23-
import pkg_resources
24+
import stevedore
2425

2526

2627
LOG = logging.getLogger(__name__)
@@ -143,17 +144,25 @@ def is_volume_endpoint_enabled(self, volume_client):
143144
def get_plugin_modules(group):
144145
"""Find plugin entry points"""
145146
mod_list = []
146-
for ep in pkg_resources.iter_entry_points(group):
147+
mgr = stevedore.ExtensionManager(group)
148+
for ep in mgr:
147149
LOG.debug('Found plugin %s', ep.name)
148150

151+
# Different versions of stevedore use different
152+
# implementations of EntryPoint from other libraries, which
153+
# are not API-compatible.
149154
try:
150-
__import__(ep.module_name)
151-
except Exception:
155+
module_name = ep.entry_point.module_name
156+
except AttributeError:
157+
module_name = ep.entry_point.module
158+
159+
try:
160+
module = importlib.import_module(module_name)
161+
except Exception as err:
152162
sys.stderr.write(
153-
"WARNING: Failed to import plugin %s.\n" % ep.name)
163+
"WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err))
154164
continue
155165

156-
module = sys.modules[ep.module_name]
157166
mod_list.append(module)
158167
init_func = getattr(module, 'Initialize', None)
159168
if init_func:
@@ -164,7 +173,7 @@ def get_plugin_modules(group):
164173
clientmanager.ClientManager,
165174
module.API_NAME,
166175
clientmanager.ClientCache(
167-
getattr(sys.modules[ep.module_name], 'make_client', None)
176+
getattr(sys.modules[module_name], 'make_client', None)
168177
),
169178
)
170179
return mod_list

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ oslo.utils>=3.33.0 # Apache-2.0
1212
python-keystoneclient>=3.22.0 # Apache-2.0
1313
python-novaclient>=15.1.0 # Apache-2.0
1414
python-cinderclient>=3.3.0 # Apache-2.0
15+
stevedore>=2.0.1 # Apache-2.0

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ flake8-import-order>=0.13 # LGPLv3
88
oslotest>=3.2.0 # Apache-2.0
99
requests>=2.14.2 # Apache-2.0
1010
requests-mock>=1.2.0 # Apache-2.0
11-
stevedore>=1.20.0 # Apache-2.0
1211
stestr>=1.0.0 # Apache-2.0
1312
testtools>=2.2.0 # MIT
1413
tempest>=17.1.0 # Apache-2.0

0 commit comments

Comments
 (0)