Merge "Add backwards compat mapping for auth-token"

This commit is contained in:
Jenkins 2015-12-21 14:02:55 +00:00 committed by Gerrit Code Review
commit 94915f149c
2 changed files with 45 additions and 0 deletions

View File

@ -467,6 +467,7 @@ class OpenStackConfig(object):
'project_domain_id': ('project_domain_id', 'project-domain-id'),
'project_domain_name': (
'project_domain_name', 'project-domain-name'),
'token': ('auth-token', 'auth_token', 'token'),
}
for target_key, possible_values in mappings.items():
target = None
@ -535,6 +536,13 @@ class OpenStackConfig(object):
# for from the user passing it explicitly. We'll stash it for later
local_parser.add_argument('--timeout', metavar='<timeout>')
# We need for get_one_cloud to be able to peek at whether a token
# was passed so that we can swap the default from password to
# token if it was. And we need to also peek for --os-auth-token
# for novaclient backwards compat
local_parser.add_argument('--os-token')
local_parser.add_argument('--os-auth-token')
# Peek into the future and see if we have an auth-type set in
# config AND a cloud set, so that we know which command line
# arguments to register and show to the user (the user may want
@ -832,6 +840,13 @@ class OpenStackConfig(object):
else:
config[key] = val
# Infer token plugin if a token was given
if (('auth' in config and 'token' in config['auth']) or
('auth_token' in config and config['auth_token']) or
('token' in config and config['token'])):
config['auth_type'] = 'token'
config.setdefault('token', config.pop('auth_token', None))
# These backwards compat values are only set via argparse. If it's
# there, it's because it was passed in explicitly, and should win
config = self._fix_backwards_api_timeout(config)

View File

@ -243,7 +243,9 @@ class TestConfigArgparse(base.TestCase):
project_name='project',
region_name='region2',
snack_type='cookie',
os_auth_token='no-good-things',
)
self.options = argparse.Namespace(**self.args)
def test_get_one_cloud_bad_region_argparse(self):
@ -401,6 +403,34 @@ class TestConfigArgparse(base.TestCase):
opts, _remain = parser.parse_known_args(['--os-cloud', 'foo'])
self.assertEqual(opts.os_cloud, 'foo')
def test_argparse_default_no_token(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
parser = argparse.ArgumentParser()
c.register_argparse_arguments(parser, [])
# novaclient will add this
parser.add_argument('--os-auth-token')
opts, _remain = parser.parse_known_args()
cc = c.get_one_cloud(
cloud='_test_cloud_regions', argparse=opts)
self.assertEqual(cc.config['auth_type'], 'password')
self.assertNotIn('token', cc.config['auth'])
def test_argparse_token(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
parser = argparse.ArgumentParser()
c.register_argparse_arguments(parser, [])
# novaclient will add this
parser.add_argument('--os-auth-token')
opts, _remain = parser.parse_known_args(
['--os-auth-token', 'very-bad-things'])
cc = c.get_one_cloud(argparse=opts)
self.assertEqual(cc.config['auth_type'], 'token')
self.assertEqual(cc.config['auth']['token'], 'very-bad-things')
def test_register_argparse_bad_plugin(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])