summaryrefslogtreecommitdiff
path: root/cinderclient/tests/functional/base.py
diff options
context:
space:
mode:
authorAdrien Vergé <adrienverge@gmail.com>2015-05-18 15:09:58 +0200
committerAdrien Vergé <adrienverge@gmail.com>2015-05-18 15:09:58 +0200
commitdec3d0837105637a9a9312f42dc9b7bcbbe8cc39 (patch)
treed914f448c5fe4fb3fa209d6dcda1ac450f6e09aa /cinderclient/tests/functional/base.py
parentf098b02564344c5b4e7a33fb664f5fb98313bc96 (diff)
downloadpython-cinderclient-dec3d0837105637a9a9312f42dc9b7bcbbe8cc39.tar.gz
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
Diffstat (limited to 'cinderclient/tests/functional/base.py')
-rw-r--r--cinderclient/tests/functional/base.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/cinderclient/tests/functional/base.py b/cinderclient/tests/functional/base.py
index 02c07f9..965568b 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,