Merge "Remove the keystoneclient auth fallback"

This commit is contained in:
Jenkins 2017-03-04 17:10:54 +00:00 committed by Gerrit Code Review
commit d6908f93a7
4 changed files with 13 additions and 77 deletions

View File

@ -861,59 +861,6 @@ class OpenStackConfig(object):
config['auth_type'] = 'admin_token'
return loading.get_plugin_loader(config['auth_type'])
def _validate_auth_ksc(self, config, cloud):
try:
import keystoneclient.auth as ksc_auth
except ImportError:
return config
# May throw a keystoneclient.exceptions.NoMatchingPlugin
plugin_options = ksc_auth.get_plugin_class(
config['auth_type']).get_options()
for p_opt in plugin_options:
# if it's in config.auth, win, kill it from config dict
# if it's in config and not in config.auth, move it
# deprecated loses to current
# provided beats default, deprecated or not
winning_value = self._find_winning_auth_value(
p_opt,
config['auth'],
)
if not winning_value:
winning_value = self._find_winning_auth_value(
p_opt,
config,
)
# if the plugin tells us that this value is required
# then error if it's doesn't exist now
if not winning_value and p_opt.required:
raise exceptions.OpenStackConfigException(
'Unable to find auth information for cloud'
' {cloud} in config files {files}'
' or environment variables. Missing value {auth_key}'
' required for auth plugin {plugin}'.format(
cloud=cloud, files=','.join(self._config_files),
auth_key=p_opt.name, plugin=config.get('auth_type')))
# Clean up after ourselves
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated_opts]:
opt = opt.replace('-', '_')
config.pop(opt, None)
config['auth'].pop(opt, None)
if winning_value:
# Prefer the plugin configuration dest value if the value's key
# is marked as depreciated.
if p_opt.dest is None:
config['auth'][p_opt.name.replace('-', '_')] = (
winning_value)
else:
config['auth'][p_opt.dest] = winning_value
return config
def _validate_auth(self, config, loader):
# May throw a keystoneauth1.exceptions.NoMatchingPlugin
@ -1107,21 +1054,9 @@ class OpenStackConfig(object):
config = self.auth_config_hook(config)
if validate:
try:
loader = self._get_auth_loader(config)
config = self._validate_auth(config, loader)
auth_plugin = loader.load_from_options(**config['auth'])
except Exception as e:
# We WANT the ksa exception normally
# but OSC can't handle it right now, so we try deferring
# to ksc. If that ALSO fails, it means there is likely
# a deeper issue, so we assume the ksa error was correct
self.log.debug("Deferring keystone exception: {e}".format(e=e))
auth_plugin = None
try:
config = self._validate_auth_ksc(config, cloud)
except Exception:
raise e
loader = self._get_auth_loader(config)
config = self._validate_auth(config, loader)
auth_plugin = loader.load_from_options(**config['auth'])
else:
auth_plugin = None

View File

@ -226,7 +226,7 @@ class TestConfig(base.TestCase):
c = config.OpenStackConfig(config_files=['nonexistent'],
vendor_files=['nonexistent'],
secure_files=[self.secure_yaml])
cc = c.get_one_cloud(cloud='_test_cloud_no_vendor')
cc = c.get_one_cloud(cloud='_test_cloud_no_vendor', validate=False)
self.assertEqual('testpass', cc.auth['password'])
def test_get_cloud_names(self):
@ -384,7 +384,7 @@ class TestConfigArgparse(base.TestCase):
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(
cloud='_test_cloud_regions', argparse=self.options)
cloud='_test_cloud_regions', argparse=self.options, validate=False)
self.assertEqual(cc.region_name, 'region2')
self.assertEqual(cc.snack_type, 'cookie')
@ -481,7 +481,7 @@ class TestConfigArgparse(base.TestCase):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(argparse=self.options)
cc = c.get_one_cloud(argparse=self.options, validate=False)
self.assertIsNone(cc.cloud)
self.assertEqual(cc.region_name, 'region2')
self.assertEqual(cc.snack_type, 'cookie')
@ -490,7 +490,7 @@ class TestConfigArgparse(base.TestCase):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(**self.args)
cc = c.get_one_cloud(validate=False, **self.args)
self.assertIsNone(cc.cloud)
self.assertEqual(cc.region_name, 'region2')
self.assertEqual(cc.snack_type, 'cookie')
@ -622,7 +622,7 @@ class TestConfigArgparse(base.TestCase):
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(
cloud='envvars', argparse=self.options)
cloud='envvars', argparse=self.options, validate=False)
self.assertEqual(cc.auth['project_name'], 'project')
def test_argparse_default_no_token(self):
@ -650,7 +650,7 @@ class TestConfigArgparse(base.TestCase):
opts, _remain = parser.parse_known_args(
['--os-auth-token', 'very-bad-things',
'--os-auth-type', 'token'])
cc = c.get_one_cloud(argparse=opts)
cc = c.get_one_cloud(argparse=opts, validate=False)
self.assertEqual(cc.config['auth_type'], 'token')
self.assertEqual(cc.config['auth']['token'], 'very-bad-things')

View File

@ -18,7 +18,8 @@ from os_client_config.tests import base
class TestInit(base.TestCase):
def test_get_config_without_arg_parser(self):
cloud_config = os_client_config.get_config(options=None)
cloud_config = os_client_config.get_config(
options=None, validate=False)
self.assertIsInstance(
cloud_config,
os_client_config.cloud_config.CloudConfig
@ -26,7 +27,8 @@ class TestInit(base.TestCase):
def test_get_config_with_arg_parser(self):
cloud_config = os_client_config.get_config(
options=argparse.ArgumentParser())
options=argparse.ArgumentParser(),
validate=False)
self.assertIsInstance(
cloud_config,
os_client_config.cloud_config.CloudConfig

View File

@ -11,7 +11,6 @@ fixtures>=0.3.14
jsonschema>=2.0.0,<3.0.0,!=2.5.0
mock>=1.2
python-glanceclient>=0.18.0
python-keystoneclient>=1.1.0
python-subunit>=0.0.18
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
oslosphinx>=2.5.0,<2.6.0 # Apache-2.0