From 7d0277cacd78265b0d0d497cabe0ef184f8b63d4 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 14 Aug 2014 16:02:47 +1000 Subject: [PATCH] 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 --- keystoneclient/auth/base.py | 4 ++-- keystoneclient/tests/auth/test_cli.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py index 74d4de533..4e1b269fe 100644 --- a/keystoneclient/auth/base.py +++ b/keystoneclient/auth/base.py @@ -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) diff --git a/keystoneclient/tests/auth/test_cli.py b/keystoneclient/tests/auth/test_cli.py index b4580a317..ea2a68911 100644 --- a/keystoneclient/tests/auth/test_cli.py +++ b/keystoneclient/tests/auth/test_cli.py @@ -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