Merge "Pass the argparse data into to validate_auth"
This commit is contained in:
commit
dbd4666fb5
@ -766,7 +766,7 @@ class OpenStackConfig(object):
|
|||||||
cloud, region_name=region['name']))
|
cloud, region_name=region['name']))
|
||||||
return clouds
|
return clouds
|
||||||
|
|
||||||
def _fix_args(self, args, argparse=None):
|
def _fix_args(self, args=None, argparse=None):
|
||||||
"""Massage the passed-in options
|
"""Massage the passed-in options
|
||||||
|
|
||||||
Replace - with _ and strip os_ prefixes.
|
Replace - with _ and strip os_ prefixes.
|
||||||
@ -774,6 +774,8 @@ class OpenStackConfig(object):
|
|||||||
Convert an argparse Namespace object to a dict, removing values
|
Convert an argparse Namespace object to a dict, removing values
|
||||||
that are either None or ''.
|
that are either None or ''.
|
||||||
"""
|
"""
|
||||||
|
if not args:
|
||||||
|
args = {}
|
||||||
|
|
||||||
if argparse:
|
if argparse:
|
||||||
# Convert the passed-in Namespace
|
# Convert the passed-in Namespace
|
||||||
@ -834,7 +836,7 @@ class OpenStackConfig(object):
|
|||||||
config['auth']['token'] = 'notused'
|
config['auth']['token'] = 'notused'
|
||||||
return loading.get_plugin_loader(config['auth_type'])
|
return loading.get_plugin_loader(config['auth_type'])
|
||||||
|
|
||||||
def _validate_auth_ksc(self, config, cloud):
|
def _validate_auth_ksc(self, config, cloud, fixed_argparse):
|
||||||
try:
|
try:
|
||||||
import keystoneclient.auth as ksc_auth
|
import keystoneclient.auth as ksc_auth
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -845,14 +847,22 @@ class OpenStackConfig(object):
|
|||||||
config['auth_type']).get_options()
|
config['auth_type']).get_options()
|
||||||
|
|
||||||
for p_opt in plugin_options:
|
for p_opt in plugin_options:
|
||||||
|
# if it's in argparse, it was passed on the command line and wins
|
||||||
# if it's in config.auth, win, kill it from config dict
|
# if it's in config.auth, win, kill it from config dict
|
||||||
# if it's in config and not in config.auth, move it
|
# if it's in config and not in config.auth, move it
|
||||||
# deprecated loses to current
|
# deprecated loses to current
|
||||||
# provided beats default, deprecated or not
|
# provided beats default, deprecated or not
|
||||||
|
winning_value = self._find_winning_auth_value(
|
||||||
|
p_opt, fixed_argparse)
|
||||||
|
if winning_value:
|
||||||
|
found_in_argparse = True
|
||||||
|
else:
|
||||||
|
found_in_argparse = False
|
||||||
winning_value = self._find_winning_auth_value(
|
winning_value = self._find_winning_auth_value(
|
||||||
p_opt, config['auth'])
|
p_opt, config['auth'])
|
||||||
if not winning_value:
|
if not winning_value:
|
||||||
winning_value = self._find_winning_auth_value(p_opt, config)
|
winning_value = self._find_winning_auth_value(
|
||||||
|
p_opt, config)
|
||||||
|
|
||||||
# if the plugin tells us that this value is required
|
# if the plugin tells us that this value is required
|
||||||
# then error if it's doesn't exist now
|
# then error if it's doesn't exist now
|
||||||
@ -868,6 +878,11 @@ class OpenStackConfig(object):
|
|||||||
# Clean up after ourselves
|
# Clean up after ourselves
|
||||||
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated_opts]:
|
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated_opts]:
|
||||||
opt = opt.replace('-', '_')
|
opt = opt.replace('-', '_')
|
||||||
|
# don't do this if the value came from argparse, because we
|
||||||
|
# don't (yet) know if the value in not-auth came from argparse
|
||||||
|
# overlay or from someone passing in a dict to kwargs
|
||||||
|
# TODO(mordred) Fix that data path too
|
||||||
|
if not found_in_argparse:
|
||||||
config.pop(opt, None)
|
config.pop(opt, None)
|
||||||
config['auth'].pop(opt, None)
|
config['auth'].pop(opt, None)
|
||||||
|
|
||||||
@ -882,24 +897,37 @@ class OpenStackConfig(object):
|
|||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def _validate_auth(self, config, loader):
|
def _validate_auth(self, config, loader, fixed_argparse):
|
||||||
# May throw a keystoneauth1.exceptions.NoMatchingPlugin
|
# May throw a keystoneauth1.exceptions.NoMatchingPlugin
|
||||||
|
|
||||||
plugin_options = loader.get_options()
|
plugin_options = loader.get_options()
|
||||||
|
|
||||||
for p_opt in plugin_options:
|
for p_opt in plugin_options:
|
||||||
|
# if it's in argparse, it was passed on the command line and wins
|
||||||
# if it's in config.auth, win, kill it from config dict
|
# if it's in config.auth, win, kill it from config dict
|
||||||
# if it's in config and not in config.auth, move it
|
# if it's in config and not in config.auth, move it
|
||||||
# deprecated loses to current
|
# deprecated loses to current
|
||||||
# provided beats default, deprecated or not
|
# provided beats default, deprecated or not
|
||||||
|
winning_value = self._find_winning_auth_value(
|
||||||
|
p_opt, fixed_argparse)
|
||||||
|
if winning_value:
|
||||||
|
found_in_argparse = True
|
||||||
|
else:
|
||||||
|
found_in_argparse = False
|
||||||
winning_value = self._find_winning_auth_value(
|
winning_value = self._find_winning_auth_value(
|
||||||
p_opt, config['auth'])
|
p_opt, config['auth'])
|
||||||
if not winning_value:
|
if not winning_value:
|
||||||
winning_value = self._find_winning_auth_value(p_opt, config)
|
winning_value = self._find_winning_auth_value(
|
||||||
|
p_opt, config)
|
||||||
|
|
||||||
# Clean up after ourselves
|
# Clean up after ourselves
|
||||||
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated]:
|
for opt in [p_opt.name] + [o.name for o in p_opt.deprecated]:
|
||||||
opt = opt.replace('-', '_')
|
opt = opt.replace('-', '_')
|
||||||
|
# don't do this if the value came from argparse, because we
|
||||||
|
# don't (yet) know if the value in not-auth came from argparse
|
||||||
|
# overlay or from someone passing in a dict to kwargs
|
||||||
|
# TODO(mordred) Fix that data path too
|
||||||
|
if not found_in_argparse:
|
||||||
config.pop(opt, None)
|
config.pop(opt, None)
|
||||||
config['auth'].pop(opt, None)
|
config['auth'].pop(opt, None)
|
||||||
|
|
||||||
@ -970,6 +998,11 @@ class OpenStackConfig(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
args = self._fix_args(kwargs, argparse=argparse)
|
args = self._fix_args(kwargs, argparse=argparse)
|
||||||
|
# Run the fix just for argparse by itself. We need to
|
||||||
|
# have a copy of the argparse options separately from
|
||||||
|
# any merged copied later in validate_auth so that we
|
||||||
|
# can determine precedence
|
||||||
|
fixed_argparse = self._fix_args(argparse=argparse)
|
||||||
|
|
||||||
if cloud is None:
|
if cloud is None:
|
||||||
if 'cloud' in args:
|
if 'cloud' in args:
|
||||||
@ -1009,7 +1042,7 @@ class OpenStackConfig(object):
|
|||||||
if validate:
|
if validate:
|
||||||
try:
|
try:
|
||||||
loader = self._get_auth_loader(config)
|
loader = self._get_auth_loader(config)
|
||||||
config = self._validate_auth(config, loader)
|
config = self._validate_auth(config, loader, fixed_argparse)
|
||||||
auth_plugin = loader.load_from_options(**config['auth'])
|
auth_plugin = loader.load_from_options(**config['auth'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# We WANT the ksa exception normally
|
# We WANT the ksa exception normally
|
||||||
@ -1019,7 +1052,8 @@ class OpenStackConfig(object):
|
|||||||
self.log.debug("Deferring keystone exception: {e}".format(e=e))
|
self.log.debug("Deferring keystone exception: {e}".format(e=e))
|
||||||
auth_plugin = None
|
auth_plugin = None
|
||||||
try:
|
try:
|
||||||
config = self._validate_auth_ksc(config, cloud)
|
config = self._validate_auth_ksc(
|
||||||
|
config, cloud, fixed_argparse)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user