File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ python-swiftclient>=3.2.0 # Apache-2.0
1111python-mistralclient != 3.2.0 ,>= 3.1.0 # Apache-2.0
1212osc-lib >= 1.8.0 # Apache-2.0
1313python-openstackclient >= 3.12.0 # Apache-2.0
14+ stevedore >= 2.0.1 # Apache-2.0
Original file line number Diff line number Diff line change 1717
1818import logging
1919
20- import pkg_resources
20+ import stevedore
2121
2222from 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
4744def load_auth_system_opts (parser ):
@@ -60,7 +57,7 @@ def load_auth_system_opts(parser):
6057
6158def 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
Original file line number Diff line number Diff line change 3333from keystoneauth1 import loading
3434from oslo_utils import encodeutils
3535from oslo_utils import importutils
36- import pkg_resources
36+ import stevedore
37+
3738
3839from troveclient .apiclient import exceptions as exc
3940import 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 (
Original file line number Diff line number Diff line change 1717import types
1818from unittest import mock
1919
20- import pkg_resources
2120import testtools
2221
2322import troveclient .shell
2423
2524
2625class 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 ):
You can’t perform that action at this time.
0 commit comments