Merge "Fix plugin loading tests"
This commit is contained in:
commit
34368ade9b
@ -62,7 +62,7 @@ class Token(BaseV3Loader):
|
||||
|
||||
@property
|
||||
def plugin_class(self):
|
||||
return identity.Token
|
||||
return identity.V3Token
|
||||
|
||||
def get_options(self):
|
||||
options = super(Token, self).get_options()
|
||||
|
@ -59,6 +59,7 @@ def get_plugin_loader(name):
|
||||
"""
|
||||
try:
|
||||
mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
|
||||
invoke_on_load=True,
|
||||
name=name)
|
||||
except RuntimeError:
|
||||
raise exceptions.NoMatchingPlugin(name)
|
||||
|
@ -48,7 +48,7 @@ def register_argparse_arguments(parser, argv, default=None):
|
||||
if not options.os_auth_plugin:
|
||||
return None
|
||||
|
||||
if isinstance(options.os_auth_plugin, type):
|
||||
if isinstance(options.os_auth_plugin, base.BaseLoader):
|
||||
msg = 'Default Authentication options'
|
||||
plugin = options.os_auth_plugin
|
||||
else:
|
||||
|
@ -71,6 +71,18 @@ class Opt(object):
|
||||
deprecated_opts=deprecated_opts,
|
||||
metavar=self.metavar)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (type(self) == type(other) and
|
||||
self.name == other.name and
|
||||
self.type == other.type and
|
||||
self.help == other.help and
|
||||
self.secret == other.secret and
|
||||
self.required == other.required and
|
||||
self.dest == other.dest and
|
||||
self.deprecated == other.deprecated and
|
||||
self.default == other.default and
|
||||
self.metavar == other.metavar)
|
||||
|
||||
@property
|
||||
def _all_opts(self):
|
||||
return itertools.chain([self], self.deprecated)
|
||||
@ -83,7 +95,7 @@ class Opt(object):
|
||||
def argparse_default(self):
|
||||
# select the first ENV that is not false-y or return None
|
||||
for o in self._all_opts:
|
||||
v = os.environ.get('OS_%s' % self.name.replace('-', '_').upper())
|
||||
v = os.environ.get('OS_%s' % o.name.replace('-', '_').upper())
|
||||
if v:
|
||||
return v
|
||||
|
||||
|
@ -20,6 +20,7 @@ from keystoneauth1 import access
|
||||
from keystoneauth1 import exceptions
|
||||
from keystoneauth1 import fixture
|
||||
from keystoneauth1 import loading
|
||||
from keystoneauth1.loading import base
|
||||
from keystoneauth1 import plugin
|
||||
from keystoneauth1 import session
|
||||
from keystoneauth1.tests.unit import utils
|
||||
@ -42,8 +43,12 @@ class MockPlugin(plugin.BaseAuthPlugin):
|
||||
|
||||
class BoolType(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
# hack around oslo.config type comparison
|
||||
return type(self) == type(other)
|
||||
|
||||
def __call__(self, value):
|
||||
return value.lower() in ('1', 'true', 't', 'yes', 'y')
|
||||
return str(value).lower() in ('1', 'true', 't', 'yes', 'y')
|
||||
|
||||
|
||||
class MockLoader(loading.BaseLoader):
|
||||
@ -76,8 +81,8 @@ class MockManager(object):
|
||||
def mock_plugin(f):
|
||||
@functools.wraps(f)
|
||||
def inner(*args, **kwargs):
|
||||
with mock.patch.object(loading, 'get_plugin_loader') as m:
|
||||
m.return_value = MockPlugin
|
||||
with mock.patch.object(base, 'get_plugin_loader') as m:
|
||||
m.return_value = MockLoader()
|
||||
args = list(args) + [m]
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
0
keystoneauth1/tests/unit/loading/__init__.py
Normal file
0
keystoneauth1/tests/unit/loading/__init__.py
Normal file
@ -16,12 +16,12 @@ import uuid
|
||||
import fixtures
|
||||
import mock
|
||||
|
||||
from keystoneauth1 import base
|
||||
from keystoneauth1 import loading
|
||||
from keystoneauth1 import plugin
|
||||
from keystoneauth1.tests.unit.auth import utils
|
||||
|
||||
|
||||
class TesterPlugin(base.BaseAuthPlugin):
|
||||
class TesterPlugin(plugin.BaseAuthPlugin):
|
||||
|
||||
def get_token(self, *args, **kwargs):
|
||||
return None
|
||||
@ -71,7 +71,7 @@ class CliTests(utils.TestCase):
|
||||
name = uuid.uuid4().hex
|
||||
argv = ['--os-auth-plugin', name]
|
||||
ret = loading.register_argparse_arguments(self.p, argv)
|
||||
self.assertIs(utils.MockPlugin, ret)
|
||||
self.assertIsInstance(ret, utils.MockLoader)
|
||||
|
||||
for n in ('--os-a-int', '--os-a-bool', '--os-a-float'):
|
||||
self.assertIn(n, self.p.format_usage())
|
||||
@ -87,7 +87,7 @@ class CliTests(utils.TestCase):
|
||||
'--os-a-bool', str(self.a_bool)]
|
||||
|
||||
klass = loading.register_argparse_arguments(self.p, argv)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
|
||||
opts = self.p.parse_args(argv)
|
||||
self.assertEqual(name, opts.os_auth_plugin)
|
||||
@ -107,7 +107,7 @@ class CliTests(utils.TestCase):
|
||||
'--os-a-float', str(self.a_float)]
|
||||
|
||||
klass = loading.register_argparse_arguments(self.p, argv)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
|
||||
opts = self.p.parse_args(argv)
|
||||
self.assertEqual(name, opts.os_auth_plugin)
|
||||
@ -121,7 +121,7 @@ class CliTests(utils.TestCase):
|
||||
def test_with_default_string_value(self, m):
|
||||
name = uuid.uuid4().hex
|
||||
klass = loading.register_argparse_arguments(self.p, [], default=name)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
m.assert_called_once_with(name)
|
||||
|
||||
@utils.mock_plugin
|
||||
@ -132,29 +132,29 @@ class CliTests(utils.TestCase):
|
||||
klass = loading.register_argparse_arguments(self.p,
|
||||
argv,
|
||||
default=default)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
m.assert_called_once_with(name)
|
||||
|
||||
@utils.mock_plugin
|
||||
def test_with_default_type_value(self, m):
|
||||
klass = loading.register_argparse_arguments(self.p,
|
||||
[],
|
||||
default=utils.MockPlugin)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
default=utils.MockLoader())
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
self.assertEqual(0, m.call_count)
|
||||
|
||||
@utils.mock_plugin
|
||||
def test_overrides_default_type_value(self, m):
|
||||
# using this test plugin would fail if called because there
|
||||
# is no get_options() function
|
||||
class TestPlugin(object):
|
||||
class TestLoader(object):
|
||||
pass
|
||||
name = uuid.uuid4().hex
|
||||
argv = ['--os-auth-plugin', name]
|
||||
klass = loading.register_argparse_arguments(self.p,
|
||||
argv,
|
||||
default=TestPlugin)
|
||||
self.assertIs(utils.MockPlugin, klass)
|
||||
default=TestLoader)
|
||||
self.assertIsInstance(klass, utils.MockLoader)
|
||||
m.assert_called_once_with(name)
|
||||
|
||||
@utils.mock_plugin
|
||||
|
@ -23,6 +23,10 @@ from keystoneauth1.loading._plugins.identity import v3
|
||||
from keystoneauth1.tests.unit.auth import utils
|
||||
|
||||
|
||||
def to_oslo_opts(opts):
|
||||
return [o._to_oslo_opt() for o in opts]
|
||||
|
||||
|
||||
class ConfTests(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -45,8 +49,9 @@ class ConfTests(utils.TestCase):
|
||||
self.conf_fixture.config(auth_section=section, group=self.GROUP)
|
||||
loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(v2.Password.get_options(),
|
||||
group=section)
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(v2.Password().get_options()),
|
||||
group=section)
|
||||
|
||||
self.conf_fixture.config(auth_plugin=self.V2PASS,
|
||||
username=username,
|
||||
@ -72,7 +77,7 @@ class ConfTests(utils.TestCase):
|
||||
self.conf_fixture.config(auth_section=section, group=self.GROUP)
|
||||
loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(v3.Token().get_options(),
|
||||
self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()),
|
||||
group=section)
|
||||
|
||||
self.conf_fixture.config(auth_plugin=self.V3TOKEN,
|
||||
@ -107,11 +112,12 @@ class ConfTests(utils.TestCase):
|
||||
|
||||
@mock.patch('stevedore.DriverManager')
|
||||
def test_other_params(self, m):
|
||||
m.return_value = utils.MockManager(utils.MockPlugin)
|
||||
m.return_value = utils.MockManager(utils.MockLoader())
|
||||
driver_name = uuid.uuid4().hex
|
||||
|
||||
self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
|
||||
group=self.GROUP)
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(utils.MockLoader().get_options()),
|
||||
group=self.GROUP)
|
||||
self.conf_fixture.config(auth_plugin=driver_name,
|
||||
group=self.GROUP,
|
||||
**self.TEST_VALS)
|
||||
@ -120,12 +126,15 @@ class ConfTests(utils.TestCase):
|
||||
self.assertTestVals(a)
|
||||
|
||||
m.assert_called_once_with(namespace=loading.PLUGIN_NAMESPACE,
|
||||
name=driver_name)
|
||||
name=driver_name,
|
||||
invoke_on_load=True)
|
||||
|
||||
@utils.mock_plugin
|
||||
def test_same_section(self, m):
|
||||
self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
|
||||
group=self.GROUP)
|
||||
self.conf_fixture.register_opts(
|
||||
to_oslo_opts(utils.MockLoader().get_options()),
|
||||
group=self.GROUP)
|
||||
|
||||
loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
||||
self.conf_fixture.config(auth_plugin=uuid.uuid4().hex,
|
||||
group=self.GROUP,
|
||||
@ -141,8 +150,9 @@ class ConfTests(utils.TestCase):
|
||||
self.conf_fixture.config(auth_section=section, group=self.GROUP)
|
||||
loading.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
||||
|
||||
self.conf_fixture.register_opts(utils.MockPlugin.get_options(),
|
||||
group=section)
|
||||
self.conf_fixture.register_opts(to_oslo_opts(
|
||||
utils.MockLoader().get_options()),
|
||||
group=section)
|
||||
self.conf_fixture.config(group=section,
|
||||
auth_plugin=uuid.uuid4().hex,
|
||||
**self.TEST_VALS)
|
||||
@ -168,6 +178,6 @@ class ConfTests(utils.TestCase):
|
||||
|
||||
def test_get_named(self):
|
||||
loaded_opts = loading.get_plugin_options('v2password')
|
||||
plugin_opts = v2.Password.get_options()
|
||||
plugin_opts = v2.Password().get_options()
|
||||
|
||||
self.assertEqual(plugin_opts, loaded_opts)
|
||||
|
Loading…
Reference in New Issue
Block a user