From dec3d0837105637a9a9312f42dc9b7bcbbe8cc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 18 May 2015 15:09:58 +0200 Subject: [PATCH] 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 --- cinderclient/tests/functional/base.py | 42 ++++++++++++++++--- .../tests/functional/hooks/post_test_hook.sh | 17 +++++++- functional_creds.conf.sample | 8 ++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 functional_creds.conf.sample diff --git a/cinderclient/tests/functional/base.py b/cinderclient/tests/functional/base.py index 02c07f904..965568b44 100644 --- a/cinderclient/tests/functional/base.py +++ b/cinderclient/tests/functional/base.py @@ -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, diff --git a/cinderclient/tests/functional/hooks/post_test_hook.sh b/cinderclient/tests/functional/hooks/post_test_hook.sh index e610f20ad..186f86452 100755 --- a/cinderclient/tests/functional/hooks/post_test_hook.sh +++ b/cinderclient/tests/functional/hooks/post_test_hook.sh @@ -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 < $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 diff --git a/functional_creds.conf.sample b/functional_creds.conf.sample new file mode 100644 index 000000000..081a73681 --- /dev/null +++ b/functional_creds.conf.sample @@ -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