Make auth plugins dest save to os_

If the auth plugin saves into the normal namespace like .user_id and
user_id is an argument of the command then the two argument collide with
each other.

This is fairly common, particularly in keystoneclient's shell.

There is a little bit of a compatibility concern in that the variables
on the returned namespace have changed, however the usage of this
function should be if you use register_argparse_arguments you should
also use load_from_argparse_arguments and that is not changed.

Change-Id: Id1cb0983a1e78661492acd78ad9aa67ff8d49250
This commit is contained in:
Jamie Lennox
2014-08-14 16:02:47 +10:00
parent e7eaec13e9
commit 7d0277cacd
2 changed files with 7 additions and 2 deletions

View File

@@ -151,7 +151,7 @@ class BaseAuthPlugin(object):
default=default,
metavar=opt.metavar,
help=opt.help,
dest=opt.dest)
dest='os_%s' % opt.dest)
@classmethod
def load_from_argparse_arguments(cls, namespace, **kwargs):
@@ -165,7 +165,7 @@ class BaseAuthPlugin(object):
:returns: An auth plugin, or None if a name is not provided.
"""
for opt in cls.get_options():
val = getattr(namespace, opt.dest)
val = getattr(namespace, 'os_%s' % opt.dest)
if val is not None:
val = opt.type(val)
kwargs.setdefault(opt.dest, val)

View File

@@ -62,6 +62,11 @@ class CliTests(utils.TestCase):
a = cli.load_from_argparse_arguments(opts)
self.assertTestVals(a)
self.assertEqual(name, opts.os_auth_plugin)
self.assertEqual(str(self.a_int), opts.os_a_int)
self.assertEqual(str(self.a_float), opts.os_a_float)
self.assertEqual(str(self.a_bool), opts.os_a_bool)
@utils.mock_plugin
def test_default_options(self, m):
name = uuid.uuid4().hex