Finish removing legacy credentials

Change I8c24cd17f643083dde71ab2bd2a38417c54aeccb removed deprecated
legacy configured credentials, but a couple of dependencies were
overlooked. Removing them to complete the clean-up.

Note that this breaks stress for tests not marked as 'use_admin',
but since the stress test is going be depreacted, this should be
acceptable.

Change-Id: Ie814de56d588e438c375ee87e8b5994c6c364c19
This commit is contained in:
Andrea Frittoli (andreaf) 2016-05-26 19:31:49 +01:00
parent b02fa114b8
commit bc0a7a6d80
2 changed files with 17 additions and 30 deletions

View File

@ -73,8 +73,8 @@ def get_credentials_provider(name, network_resources=None,
# the test should be skipped else it would fail. # the test should be skipped else it would fail.
identity_version = identity_version or CONF.identity.auth_version identity_version = identity_version or CONF.identity.auth_version
if CONF.auth.use_dynamic_credentials or force_tenant_isolation: if CONF.auth.use_dynamic_credentials or force_tenant_isolation:
admin_creds = get_configured_credentials( admin_creds = get_configured_admin_credentials(
'identity_admin', fill_in=True, identity_version=identity_version) fill_in=True, identity_version=identity_version)
return dynamic_creds.DynamicCredentialProvider( return dynamic_creds.DynamicCredentialProvider(
name=name, name=name,
network_resources=network_resources, network_resources=network_resources,
@ -111,7 +111,7 @@ def is_admin_available(identity_version):
is_admin = False is_admin = False
else: else:
try: try:
get_configured_credentials('identity_admin', fill_in=False, get_configured_admin_credentials(fill_in=False,
identity_version=identity_version) identity_version=identity_version)
except exceptions.InvalidConfiguration: except exceptions.InvalidConfiguration:
is_admin = False is_admin = False
@ -163,39 +163,32 @@ DEFAULT_PARAMS = {
# Read credentials from configuration, builds a Credentials object # Read credentials from configuration, builds a Credentials object
# based on the specified or configured version # based on the specified or configured version
def get_configured_credentials(credential_type, fill_in=True, def get_configured_admin_credentials(fill_in=True, identity_version=None):
identity_version=None):
identity_version = identity_version or CONF.identity.auth_version identity_version = identity_version or CONF.identity.auth_version
if identity_version not in ('v2', 'v3'): if identity_version not in ('v2', 'v3'):
raise exceptions.InvalidConfiguration( raise exceptions.InvalidConfiguration(
'Unsupported auth version: %s' % identity_version) 'Unsupported auth version: %s' % identity_version)
if credential_type not in CREDENTIAL_TYPES: conf_attributes = ['username', 'password',
raise exceptions.InvalidCredentials() 'project_name']
conf_attributes = ['username', 'password', 'project_name']
if identity_version == 'v3': if identity_version == 'v3':
conf_attributes.append('domain_name') conf_attributes.append('domain_name')
# Read the parts of credentials from config # Read the parts of credentials from config
params = DEFAULT_PARAMS.copy() params = DEFAULT_PARAMS.copy()
section, prefix = CREDENTIAL_TYPES[credential_type]
for attr in conf_attributes: for attr in conf_attributes:
_section = getattr(CONF, section) params[attr] = getattr(CONF.auth, 'admin_' + attr)
if prefix is None:
params[attr] = getattr(_section, attr)
else:
params[attr] = getattr(_section, prefix + "_" + attr)
# Build and validate credentials. We are reading configured credentials, # Build and validate credentials. We are reading configured credentials,
# so validate them even if fill_in is False # so validate them even if fill_in is False
credentials = get_credentials(fill_in=fill_in, credentials = get_credentials(fill_in=fill_in,
identity_version=identity_version, **params) identity_version=identity_version, **params)
if not fill_in: if not fill_in:
if not credentials.is_valid(): if not credentials.is_valid():
msg = ("The %s credentials are incorrectly set in the config file." msg = ("The admin credentials are incorrectly set in the config "
" Double check that all required values are assigned" % "file for identity version %s. Double check that all "
credential_type) "required values are assigned.")
raise exceptions.InvalidConfiguration(msg) raise exceptions.InvalidConfiguration(msg % identity_version)
return credentials return credentials
@ -223,19 +216,10 @@ def get_credentials(fill_in=True, identity_version=None, **kwargs):
# === Credential / client managers # === Credential / client managers
class ConfiguredUserManager(clients.Manager):
"""Manager that uses user credentials for its managed client objects"""
def __init__(self, service=None):
super(ConfiguredUserManager, self).__init__(
credentials=get_configured_credentials('user'),
service=service)
class AdminManager(clients.Manager): class AdminManager(clients.Manager):
"""Manager that uses admin credentials for its managed client objects""" """Manager that uses admin credentials for its managed client objects"""
def __init__(self, service=None): def __init__(self, service=None):
super(AdminManager, self).__init__( super(AdminManager, self).__init__(
credentials=get_configured_credentials('identity_admin'), credentials=get_configured_admin_credentials(),
service=service) service=service)

View File

@ -135,10 +135,13 @@ def stress_openstack(tests, duration, max_runs=None, stop_on_error=False):
break break
if skip: if skip:
break break
# TODO(andreaf) This has to be reworked to use the credential
# provider interface. For now only tests marked as 'use_admin' will
# work.
if test.get('use_admin', False): if test.get('use_admin', False):
manager = admin_manager manager = admin_manager
else: else:
manager = credentials.ConfiguredUserManager() raise NotImplemented('Non admin tests are not supported')
for p_number in moves.xrange(test.get('threads', default_thread_num)): for p_number in moves.xrange(test.get('threads', default_thread_num)):
if test.get('use_isolated_tenants', False): if test.get('use_isolated_tenants', False):
username = data_utils.rand_name("stress_user") username = data_utils.rand_name("stress_user")