Merge "use stevedore to load extensions"
This commit is contained in:
commit
51de7e320a
@ -92,7 +92,7 @@ Routes==2.3.1
|
||||
simplejson==3.5.1
|
||||
smmap==0.9.0
|
||||
statsd==3.2.1
|
||||
stevedore==1.20.0
|
||||
stevedore==2.0.1
|
||||
tempest==17.1.0
|
||||
tenacity==3.2.1
|
||||
stestr==2.0.0
|
||||
|
@ -28,7 +28,7 @@ from keystoneauth1 import adapter
|
||||
from keystoneauth1 import identity
|
||||
from keystoneauth1 import session as ksession
|
||||
from oslo_utils import importutils
|
||||
import pkg_resources
|
||||
import stevedore
|
||||
|
||||
import novaclient
|
||||
from novaclient import api_versions
|
||||
@ -176,12 +176,15 @@ def _discover_via_python_path():
|
||||
yield name, module
|
||||
|
||||
|
||||
def _discover_via_entry_points():
|
||||
for ep in pkg_resources.iter_entry_points('novaclient.extension'):
|
||||
name = ep.name
|
||||
module = ep.load()
|
||||
def _make_discovery_manager():
|
||||
# This function provides a place to mock out the entry point scan
|
||||
return stevedore.ExtensionManager('novaclient.extension')
|
||||
|
||||
yield name, module
|
||||
|
||||
def _discover_via_entry_points():
|
||||
mgr = _make_discovery_manager()
|
||||
for extension in mgr:
|
||||
yield extension.name, extension.plugin
|
||||
|
||||
|
||||
def _get_client_class_and_version(version):
|
||||
|
@ -17,7 +17,8 @@ import imp
|
||||
import inspect
|
||||
from unittest import mock
|
||||
|
||||
import pkg_resources
|
||||
import stevedore
|
||||
from stevedore import extension
|
||||
|
||||
from novaclient import client
|
||||
from novaclient.tests.unit import utils
|
||||
@ -27,16 +28,20 @@ class DiscoverTest(utils.TestCase):
|
||||
|
||||
def test_discover_via_entry_points(self):
|
||||
|
||||
def mock_iter_entry_points(group):
|
||||
if group == 'novaclient.extension':
|
||||
fake_ep = mock.Mock()
|
||||
fake_ep.name = 'foo'
|
||||
fake_ep.module = imp.new_module('foo')
|
||||
fake_ep.load.return_value = fake_ep.module
|
||||
return [fake_ep]
|
||||
def mock_mgr():
|
||||
fake_ep = mock.Mock()
|
||||
fake_ep.name = 'foo'
|
||||
fake_ep.module = imp.new_module('foo')
|
||||
fake_ep.load.return_value = fake_ep.module
|
||||
fake_ext = extension.Extension(
|
||||
name='foo',
|
||||
entry_point=fake_ep,
|
||||
plugin=fake_ep.module,
|
||||
obj=None,
|
||||
)
|
||||
return stevedore.ExtensionManager.make_test_instance([fake_ext])
|
||||
|
||||
@mock.patch.object(pkg_resources, 'iter_entry_points',
|
||||
mock_iter_entry_points)
|
||||
@mock.patch.object(client, '_make_discovery_manager', mock_mgr)
|
||||
def test():
|
||||
for name, module in client._discover_via_entry_points():
|
||||
self.assertEqual('foo', name)
|
||||
|
@ -9,3 +9,4 @@ oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7.2 # BSD
|
||||
simplejson>=3.5.1 # MIT
|
||||
stevedore>=2.0.1 # Apache-2.0
|
||||
|
Loading…
Reference in New Issue
Block a user