use stevedore to load extensions
pkg_resources was deprecated in python3.12 Change-Id: Ifa4c93220d3f39f706cc7fd462f28ebcdce14707
This commit is contained in:
parent
c7380db1bf
commit
2d912fb78f
@ -11,3 +11,4 @@ python-swiftclient>=3.2.0 # Apache-2.0
|
||||
python-mistralclient!=3.2.0,>=3.1.0 # Apache-2.0
|
||||
osc-lib>=1.8.0 # Apache-2.0
|
||||
python-openstackclient>=3.12.0 # Apache-2.0
|
||||
stevedore>=2.0.1 # Apache-2.0
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
import pkg_resources
|
||||
import stevedore
|
||||
|
||||
from troveclient import exceptions
|
||||
|
||||
@ -33,15 +33,12 @@ def discover_auth_systems():
|
||||
|
||||
This won't take into account the old style auth-systems.
|
||||
"""
|
||||
ep_name = 'openstack.client.auth_plugin'
|
||||
for ep in pkg_resources.iter_entry_points(ep_name):
|
||||
try:
|
||||
auth_plugin = ep.load()
|
||||
except (ImportError, pkg_resources.UnknownExtra, AttributeError) as e:
|
||||
LOG.debug("ERROR: Cannot load auth plugin %s", ep.name)
|
||||
LOG.debug(e, exc_info=1)
|
||||
else:
|
||||
_discovered_plugins[ep.name] = auth_plugin
|
||||
global _discovered_plugins
|
||||
mgr = stevedore.ExtensionManager(
|
||||
namespace='openstack.client.auth_plugin',
|
||||
invoke_on_load=True,
|
||||
)
|
||||
_discovered_plugins = {ext.name: ext.obj for ext in mgr}
|
||||
|
||||
|
||||
def load_auth_system_opts(parser):
|
||||
@ -60,7 +57,7 @@ def load_auth_system_opts(parser):
|
||||
|
||||
def load_plugin(auth_system):
|
||||
if auth_system in _discovered_plugins:
|
||||
return _discovered_plugins[auth_system]()
|
||||
return _discovered_plugins[auth_system]
|
||||
|
||||
raise exceptions.AuthSystemNotFound(auth_system)
|
||||
|
||||
|
@ -33,7 +33,8 @@ from keystoneauth1.identity.generic import token
|
||||
from keystoneauth1 import loading
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
import pkg_resources
|
||||
import stevedore
|
||||
|
||||
|
||||
from troveclient.apiclient import exceptions as exc
|
||||
import troveclient.auth_plugin
|
||||
@ -323,11 +324,10 @@ class OpenStackTroveShell(object):
|
||||
yield name, module
|
||||
|
||||
def _discover_via_entry_points(self):
|
||||
for ep in pkg_resources.iter_entry_points('troveclient.extension'):
|
||||
name = ep.name
|
||||
module = ep.load()
|
||||
|
||||
yield name, module
|
||||
mgr = stevedore.ExtensionManager(namespace='troveclient.extension',
|
||||
invoke_on_load=True)
|
||||
for ext in mgr:
|
||||
yield ext.name, ext.plugin
|
||||
|
||||
def _add_bash_completion_subparser(self, subparsers):
|
||||
subparser = subparsers.add_parser(
|
||||
|
@ -17,7 +17,6 @@ import inspect
|
||||
import types
|
||||
from unittest import mock
|
||||
|
||||
import pkg_resources
|
||||
import testtools
|
||||
|
||||
import troveclient.shell
|
||||
@ -25,26 +24,6 @@ import troveclient.shell
|
||||
|
||||
class DiscoverTest(testtools.TestCase):
|
||||
|
||||
def test_discover_via_entry_points(self):
|
||||
|
||||
def mock_iter_entry_points(group):
|
||||
if group == 'troveclient.extension':
|
||||
fake_ep = mock.Mock()
|
||||
fake_ep.name = 'foo'
|
||||
fake_ep.module = types.ModuleType('foo')
|
||||
fake_ep.load.return_value = fake_ep.module
|
||||
return [fake_ep]
|
||||
|
||||
@mock.patch.object(pkg_resources, 'iter_entry_points',
|
||||
mock_iter_entry_points)
|
||||
def test():
|
||||
shell = troveclient.shell.OpenStackTroveShell()
|
||||
for name, module in shell._discover_via_entry_points():
|
||||
self.assertEqual('foo', name)
|
||||
self.assertTrue(inspect.ismodule(module))
|
||||
|
||||
test()
|
||||
|
||||
def test_discover_extensions(self):
|
||||
|
||||
def mock_discover_via_python_path(self):
|
||||
|
Loading…
Reference in New Issue
Block a user