Skip to content

Commit

Permalink
Merge "Factor up config dependent credential classes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Nov 18, 2015
2 parents bf19dd1 + 290b3e1 commit bf57df1
Show file tree
Hide file tree
Showing 25 changed files with 429 additions and 347 deletions.
10 changes: 5 additions & 5 deletions doc/source/configuration.rst
Expand Up @@ -127,16 +127,16 @@ to the tests using the credentials, and failure to do this will likely cause
unexpected failures in some tests.


Non-locking test accounts (aka credentials config options)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Legacy test accounts (aka credentials config options)
"""""""""""""""""""""""""""""""""""""""""""""""""""""
**Starting in the Liberty release this mechanism was deprecated and will be
removed in a future release**

When Tempest was refactored to allow for locking test accounts, the original
non-tenant isolated case was converted to internally work similarly to the
accounts.yaml file. This mechanism was then called the non-locking test accounts
provider. To use the non-locking test accounts provider you can specify the sets
of credentials in the configuration file like detailed above with following 9
accounts.yaml file. This mechanism was then called the legacy test accounts
provider. To use the legacy test accounts provider you can specify the sets of
credentials in the configuration file like detailed above with following 9
options in the identity section:

#. username
Expand Down
4 changes: 2 additions & 2 deletions tempest/api/identity/admin/v3/test_trusts.py
Expand Up @@ -18,7 +18,7 @@

from tempest.api.identity import base
from tempest import clients
from tempest.common import cred_provider
from tempest.common import credentials_factory as common_creds
from tempest.common.utils import data_utils
from tempest import config
from tempest import test
Expand Down Expand Up @@ -89,7 +89,7 @@ def create_trustor_and_roles(self):
self.assertIsNotNone(self.trustee_user_id)

# Initialize a new client with the trustor credentials
creds = cred_provider.get_credentials(
creds = common_creds.get_credentials(
identity_version='v3',
username=self.trustor_username,
password=self.trustor_password,
Expand Down
12 changes: 6 additions & 6 deletions tempest/api/identity/base.py
Expand Up @@ -16,7 +16,7 @@
from oslo_log import log as logging
from tempest_lib import exceptions as lib_exc

from tempest.common import cred_provider
from tempest.common import credentials_factory as common_creds
from tempest.common.utils import data_utils
from tempest import config
import tempest.test
Expand Down Expand Up @@ -195,11 +195,11 @@ def __init__(self, client):

@property
def test_credentials(self):
return cred_provider.get_credentials(username=self.test_user,
user_id=self.user['id'],
password=self.test_password,
tenant_name=self.test_tenant,
tenant_id=self.tenant['id'])
return common_creds.get_credentials(username=self.test_user,
user_id=self.user['id'],
password=self.test_password,
tenant_name=self.test_tenant,
tenant_id=self.tenant['id'])

def setup_test_user(self):
"""Set up a test user."""
Expand Down
4 changes: 2 additions & 2 deletions tempest/api/orchestration/stacks/test_neutron_resources.py
Expand Up @@ -16,7 +16,7 @@
import netaddr

from tempest.api.orchestration import base
from tempest import clients
from tempest.common import credentials_factory as credentials
from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
Expand All @@ -38,7 +38,7 @@ def skip_checks(cls):
@classmethod
def setup_credentials(cls):
super(NeutronResourcesTestJSON, cls).setup_credentials()
cls.os = clients.Manager()
cls.os = credentials.ConfiguredUserManager()

@classmethod
def setup_clients(cls):
Expand Down
17 changes: 1 addition & 16 deletions tempest/clients.py
Expand Up @@ -38,7 +38,6 @@
from tempest_lib.services.identity.v2.token_client import TokenClient
from tempest_lib.services.identity.v3.token_client import V3TokenClient

from tempest.common import cred_provider
from tempest.common import negative_rest_client
from tempest import config
from tempest import exceptions
Expand Down Expand Up @@ -175,7 +174,7 @@ class Manager(manager.Manager):
}
default_params_with_timeout_values.update(default_params)

def __init__(self, credentials=None, service=None):
def __init__(self, credentials, service=None):
super(Manager, self).__init__(credentials=credentials)

self._set_compute_clients()
Expand Down Expand Up @@ -484,17 +483,3 @@ def _set_object_storage_clients(self):
self.account_client = AccountClient(self.auth_provider, **params)
self.container_client = ContainerClient(self.auth_provider, **params)
self.object_client = ObjectClient(self.auth_provider, **params)


class AdminManager(Manager):

"""
Manager object that uses the admin credentials for its
managed client objects
"""

def __init__(self, service=None):
super(AdminManager, self).__init__(
credentials=cred_provider.get_configured_credentials(
'identity_admin'),
service=service)
8 changes: 4 additions & 4 deletions tempest/cmd/cleanup.py
Expand Up @@ -58,7 +58,7 @@

from tempest import clients
from tempest.cmd import cleanup_service
from tempest.common import cred_provider
from tempest.common import credentials_factory as credentials
from tempest import config

SAVED_STATE_JSON = "saved_state.json"
Expand All @@ -75,7 +75,7 @@ def __init__(self, app, cmd):
def take_action(self, parsed_args):
cleanup_service.init_conf()
self.options = parsed_args
self.admin_mgr = clients.AdminManager()
self.admin_mgr = credentials.AdminManager()
self.dry_run_data = {}
self.json_data = {}

Expand Down Expand Up @@ -162,7 +162,7 @@ def _clean_tenant(self, tenant):
kwargs = {"username": CONF.auth.admin_username,
"password": CONF.auth.admin_password,
"tenant_name": tenant['name']}
mgr = clients.Manager(credentials=cred_provider.get_credentials(
mgr = clients.Manager(credentials=credentials.get_credentials(
**kwargs))
kwargs = {'data': tenant_data,
'is_dry_run': is_dry_run,
Expand Down Expand Up @@ -235,7 +235,7 @@ def _remove_admin_role(self, tenant_id):
LOG.debug("Remove admin user role for tenant: %s" % tenant_id)
# Must initialize AdminManager for each user role
# Otherwise authentication exception is thrown, weird
id_cl = clients.AdminManager().identity_client
id_cl = credentials.AdminManager().identity_client
if (self._tenant_exists(tenant_id)):
try:
id_cl.remove_user_role(tenant_id, self.admin_id,
Expand Down
4 changes: 2 additions & 2 deletions tempest/cmd/cleanup_service.py
Expand Up @@ -16,7 +16,7 @@

from oslo_log import log as logging

from tempest import clients
from tempest.common import credentials_factory as credentials
from tempest import config
from tempest import test

Expand Down Expand Up @@ -82,7 +82,7 @@ def init_conf():


def _get_network_id(net_name, tenant_name):
am = clients.AdminManager()
am = credentials.AdminManager()
net_cl = am.networks_client
id_cl = am.identity_client

Expand Down
2 changes: 1 addition & 1 deletion tempest/cmd/verify_tempest_config.py
Expand Up @@ -24,7 +24,7 @@
from six.moves.urllib import parse as urlparse

from tempest import clients
from tempest.common import credentials
from tempest.common import credentials_factory as credentials
from tempest import config


Expand Down
73 changes: 0 additions & 73 deletions tempest/common/cred_provider.py
Expand Up @@ -18,83 +18,10 @@
import six
from tempest_lib import auth

from tempest import config
from tempest import exceptions

CONF = config.CONF
LOG = logging.getLogger(__name__)

# Type of credentials available from configuration
CREDENTIAL_TYPES = {
'identity_admin': ('auth', 'admin'),
'user': ('identity', None),
'alt_user': ('identity', 'alt')
}

DEFAULT_PARAMS = {
'disable_ssl_certificate_validation':
CONF.identity.disable_ssl_certificate_validation,
'ca_certs': CONF.identity.ca_certificates_file,
'trace_requests': CONF.debug.trace_requests
}


# Read credentials from configuration, builds a Credentials object
# based on the specified or configured version
def get_configured_credentials(credential_type, fill_in=True,
identity_version=None):
identity_version = identity_version or CONF.identity.auth_version
if identity_version not in ('v2', 'v3'):
raise exceptions.InvalidConfiguration(
'Unsupported auth version: %s' % identity_version)
if credential_type not in CREDENTIAL_TYPES:
raise exceptions.InvalidCredentials()
conf_attributes = ['username', 'password', 'tenant_name']
if identity_version == 'v3':
conf_attributes.append('domain_name')
# Read the parts of credentials from config
params = DEFAULT_PARAMS.copy()
section, prefix = CREDENTIAL_TYPES[credential_type]
for attr in conf_attributes:
_section = getattr(CONF, section)
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,
# so validate them even if fill_in is False
credentials = get_credentials(fill_in=fill_in,
identity_version=identity_version, **params)
if not fill_in:
if not credentials.is_valid():
msg = ("The %s credentials are incorrectly set in the config file."
" Double check that all required values are assigned" %
credential_type)
raise exceptions.InvalidConfiguration(msg)
return credentials


# Wrapper around auth.get_credentials to use the configured identity version
# is none is specified
def get_credentials(fill_in=True, identity_version=None, **kwargs):
params = dict(DEFAULT_PARAMS, **kwargs)
identity_version = identity_version or CONF.identity.auth_version
# In case of "v3" add the domain from config if not specified
if identity_version == 'v3':
domain_fields = set(x for x in auth.KeystoneV3Credentials.ATTRIBUTES
if 'domain' in x)
if not domain_fields.intersection(kwargs.keys()):
domain_name = CONF.auth.default_credentials_domain_name
params['user_domain_name'] = domain_name

auth_url = CONF.identity.uri_v3
else:
auth_url = CONF.identity.uri
return auth.get_credentials(auth_url,
fill_in=fill_in,
identity_version=identity_version,
**params)


@six.add_metaclass(abc.ABCMeta)
class CredentialProvider(object):
Expand Down
110 changes: 0 additions & 110 deletions tempest/common/credentials.py

This file was deleted.

0 comments on commit bf57df1

Please sign in to comment.