From c054d2583b96383f6ac47edfd2e06ead4b5723b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Sat, 16 May 2015 17:58:27 +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, glanceclient, manilaclient and soon in cinderclient. Reading credentials the old way (the environment) is still possible. Conflicts: neutronclient/tests/functional/test_clientlib.py Change-Id: Ief0f050044ecd90a14bbaf044e2b93ade0a6173f Closes-Bug: #1455102 (cherry picked from commit 7eb3241650ad87d2f6ca5aa45b3a2415eafe7207) --- functional_creds.conf.sample | 8 ++++ neutronclient/tests/functional/base.py | 48 ++++++++++++++++--- .../tests/functional/hooks/post_test_hook.sh | 17 ++++++- 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 functional_creds.conf.sample 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 diff --git a/neutronclient/tests/functional/base.py b/neutronclient/tests/functional/base.py index 48561d6c7..d70fc77b0 100644 --- a/neutronclient/tests/functional/base.py +++ b/neutronclient/tests/functional/base.py @@ -12,9 +12,44 @@ import os +from six.moves import configparser from tempest_lib.cli import base +_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, + 'auth_url': auth_url + } + + class ClientTestBase(base.ClientTestBase): """This is a first pass at a simple read only python-neutronclient test. This only exercises client commands that are read only. @@ -28,16 +63,15 @@ class ClientTestBase(base.ClientTestBase): """ def _get_clients(self): + creds = credentials() cli_dir = os.environ.get( 'OS_NEUTRONCLIENT_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(username=creds['username'], + password=creds['password'], + tenant_name=creds['tenant_name'], + uri=creds['auth_url'], + cli_dir=cli_dir) def neutron(self, *args, **kwargs): return self.clients.neutron(*args, diff --git a/neutronclient/tests/functional/hooks/post_test_hook.sh b/neutronclient/tests/functional/hooks/post_test_hook.sh index e0c966939..68f906a24 100755 --- a/neutronclient/tests/functional/hooks/post_test_hook.sh +++ b/neutronclient/tests/functional/hooks/post_test_hook.sh @@ -28,15 +28,28 @@ function generate_testr_results { export NEUTRONCLIENT_DIR="$BASE/new/python-neutronclient" +sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR + # Get admin credentials cd $BASE/new/devstack source openrc admin admin +# Store these credentials into the config file +CREDS_FILE=$NEUTRONCLIENT_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 neutronclient dir cd $NEUTRONCLIENT_DIR -sudo chown -R jenkins:stack $NEUTRONCLIENT_DIR - # Run tests echo "Running neutronclient functional test suite" set +e