Skip to content

Commit 2d912fb

Browse files
committed
use stevedore to load extensions
pkg_resources was deprecated in python3.12 Change-Id: Ifa4c93220d3f39f706cc7fd462f28ebcdce14707
1 parent c7380db commit 2d912fb

4 files changed

Lines changed: 15 additions & 38 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ python-swiftclient>=3.2.0 # Apache-2.0
1111
python-mistralclient!=3.2.0,>=3.1.0 # Apache-2.0
1212
osc-lib>=1.8.0 # Apache-2.0
1313
python-openstackclient>=3.12.0 # Apache-2.0
14+
stevedore>=2.0.1 # Apache-2.0

troveclient/auth_plugin.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import logging
1919

20-
import pkg_resources
20+
import stevedore
2121

2222
from troveclient import exceptions
2323

@@ -33,15 +33,12 @@ def discover_auth_systems():
3333
3434
This won't take into account the old style auth-systems.
3535
"""
36-
ep_name = 'openstack.client.auth_plugin'
37-
for ep in pkg_resources.iter_entry_points(ep_name):
38-
try:
39-
auth_plugin = ep.load()
40-
except (ImportError, pkg_resources.UnknownExtra, AttributeError) as e:
41-
LOG.debug("ERROR: Cannot load auth plugin %s", ep.name)
42-
LOG.debug(e, exc_info=1)
43-
else:
44-
_discovered_plugins[ep.name] = auth_plugin
36+
global _discovered_plugins
37+
mgr = stevedore.ExtensionManager(
38+
namespace='openstack.client.auth_plugin',
39+
invoke_on_load=True,
40+
)
41+
_discovered_plugins = {ext.name: ext.obj for ext in mgr}
4542

4643

4744
def load_auth_system_opts(parser):
@@ -60,7 +57,7 @@ def load_auth_system_opts(parser):
6057

6158
def load_plugin(auth_system):
6259
if auth_system in _discovered_plugins:
63-
return _discovered_plugins[auth_system]()
60+
return _discovered_plugins[auth_system]
6461

6562
raise exceptions.AuthSystemNotFound(auth_system)
6663

troveclient/shell.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
from keystoneauth1 import loading
3434
from oslo_utils import encodeutils
3535
from oslo_utils import importutils
36-
import pkg_resources
36+
import stevedore
37+
3738

3839
from troveclient.apiclient import exceptions as exc
3940
import troveclient.auth_plugin
@@ -323,11 +324,10 @@ def _discover_via_contrib_path(self, version):
323324
yield name, module
324325

325326
def _discover_via_entry_points(self):
326-
for ep in pkg_resources.iter_entry_points('troveclient.extension'):
327-
name = ep.name
328-
module = ep.load()
329-
330-
yield name, module
327+
mgr = stevedore.ExtensionManager(namespace='troveclient.extension',
328+
invoke_on_load=True)
329+
for ext in mgr:
330+
yield ext.name, ext.plugin
331331

332332
def _add_bash_completion_subparser(self, subparsers):
333333
subparser = subparsers.add_parser(

troveclient/tests/test_discover.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,13 @@
1717
import types
1818
from unittest import mock
1919

20-
import pkg_resources
2120
import testtools
2221

2322
import troveclient.shell
2423

2524

2625
class DiscoverTest(testtools.TestCase):
2726

28-
def test_discover_via_entry_points(self):
29-
30-
def mock_iter_entry_points(group):
31-
if group == 'troveclient.extension':
32-
fake_ep = mock.Mock()
33-
fake_ep.name = 'foo'
34-
fake_ep.module = types.ModuleType('foo')
35-
fake_ep.load.return_value = fake_ep.module
36-
return [fake_ep]
37-
38-
@mock.patch.object(pkg_resources, 'iter_entry_points',
39-
mock_iter_entry_points)
40-
def test():
41-
shell = troveclient.shell.OpenStackTroveShell()
42-
for name, module in shell._discover_via_entry_points():
43-
self.assertEqual('foo', name)
44-
self.assertTrue(inspect.ismodule(module))
45-
46-
test()
47-
4827
def test_discover_extensions(self):
4928

5029
def mock_discover_via_python_path(self):

0 commit comments

Comments
 (0)