Fix functional tests and tox 2.0 errors

With the recent update to tox 2.0.x, environment variables such as
OS_AUTH_URL are not passed by default, resulting in tests errors
mentionning Keystone authentication failures.

This patch reads credentials from the 'functional_creds.conf' config
file, like it is done in novaclient (and soon in glanceclient and
neutronclient).

Reading credentials the old way (the environment) is still possible.

Change-Id: I2ec1df481aba7a3866fc8dbc912311de02c22d11
Related-Bug: #1455102
This commit is contained in:
Adrien Vergé 2015-05-18 15:09:58 +02:00
parent f098b02564
commit dec3d08371
3 changed files with 59 additions and 8 deletions

View File

@ -12,10 +12,45 @@
import os
from six.moves import configparser
from tempest_lib.cli import base
from tempest_lib.cli import output_parser
_CREDS_FILE = 'functional_creds.conf'
def credentials():
"""Retrieves credentials to run functional tests
Credentials are either read from the environment or from a config file
('functional_creds.conf'). Environment variables override those from the
config file.
The 'functional_creds.conf' file is the clean and new way to use (by
default tox 2.0 does not pass environment variables).
"""
username = os.environ.get('OS_USERNAME')
password = os.environ.get('OS_PASSWORD')
tenant_name = os.environ.get('OS_TENANT_NAME')
auth_url = os.environ.get('OS_AUTH_URL')
config = configparser.RawConfigParser()
if config.read(_CREDS_FILE):
username = username or config.get('admin', 'user')
password = password or config.get('admin', 'pass')
tenant_name = tenant_name or config.get('admin', 'tenant')
auth_url = auth_url or config.get('auth', 'uri')
return {
'username': username,
'password': password,
'tenant_name': tenant_name,
'uri': auth_url
}
class ClientTestBase(base.ClientTestBase):
"""Cinder base class, issues calls to cinderclient.
@ -30,12 +65,7 @@ class ClientTestBase(base.ClientTestBase):
'OS_CINDERCLIENT_EXEC_DIR',
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
return base.CLIClient(
username=os.environ.get('OS_USERNAME'),
password=os.environ.get('OS_PASSWORD'),
tenant_name=os.environ.get('OS_TENANT_NAME'),
uri=os.environ.get('OS_AUTH_URL'),
cli_dir=cli_dir)
return base.CLIClient(cli_dir=cli_dir, **credentials())
def cinder(self, *args, **kwargs):
return self.clients.cinder(*args,

View File

@ -31,15 +31,28 @@ function generate_testr_results {
export CINDERCLIENT_DIR="$BASE/python-cinderclient"
sudo chown -R jenkins:stack $CINDERCLIENT_DIR
# Get admin credentials
cd $STACK_DIR
source openrc admin admin
# Store these credentials into the config file
CREDS_FILE=$CINDERCLIENT_DIR/functional_creds.conf
cat <<EOF > $CREDS_FILE
# Credentials for functional testing
[auth]
uri = $OS_AUTH_URL
[admin]
user = $OS_USERNAME
tenant = $OS_TENANT_NAME
pass = $OS_PASSWORD
EOF
# Go to the cinderclient dir
cd $CINDERCLIENT_DIR
sudo chown -R jenkins:stack $CINDERCLIENT_DIR
# Run tests
echo "Running cinderclient functional test suite"
set +e

View File

@ -0,0 +1,8 @@
# Credentials for functional testing
[auth]
uri = http://10.42.0.50:5000/v2.0
[admin]
user = admin
tenant = admin
pass = secrete