diff --git a/.gitignore b/.gitignore index fefb88c8..e43ec847 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ pip-log.txt .coverage .tox nosetests.xml +functional_creds.conf # Translations *.mo diff --git a/functional_creds.conf.sample b/functional_creds.conf.sample new file mode 100644 index 00000000..cb9ae965 --- /dev/null +++ b/functional_creds.conf.sample @@ -0,0 +1,12 @@ +# Credentials for functional testing +[auth] +uri = http://10.42.0.50:5000/v2.0 + +[admin] +user = admin +tenant = admin +pass = secrete +[demo] +user = demo +tenant = demo +pass = demo_secret \ No newline at end of file diff --git a/functionaltests/run_tests.sh b/functionaltests/run_tests.sh index 751b47ea..d4c4d570 100644 --- a/functionaltests/run_tests.sh +++ b/functionaltests/run_tests.sh @@ -22,13 +22,37 @@ fi echo "Successfully contacted Mistral API" -# Where tempest code lives -TEMPEST_DIR=${TEMPEST_DIR:-/opt/stack/new/tempest} +export BASE=/opt/stack +export MISTRALCLIENT_DIR="$BASE/new/python-mistralclient" -# Add tempest source tree to PYTHONPATH -export PYTHONPATH=$PYTHONPATH:$TEMPEST_DIR +# Get demo credentials. +cd ${BASE}/new/devstack +source openrc demo demo -#installing requirements for tempest -pip install -r $TEMPEST_DIR/requirements.txt +export OS_ALT_USERNAME=${OS_USERNAME} +export OS_ALT_TENANT_NAME=${OS_TENANT_NAME} +export OS_ALT_PASSWORD=${OS_PASSWORD} -nosetests -sv mistralclient/tests/functional/ +# Get admin credentials. +source openrc admin admin + +# Store these credentials into the config file. +CREDS_FILE=${MISTRALCLIENT_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 +[demo] +user = $OS_ALT_USERNAME +tenant = $OS_ALT_TENANT_NAME +pass = $OS_ALT_PASSWORD +EOF + +cd $MISTRALCLIENT_DIR + +# Run tests +tox -efunctional -- nosetests -sv mistralclient/tests/functional diff --git a/mistralclient/tests/functional/cli/base.py b/mistralclient/tests/functional/cli/base.py index 791db41a..55200216 100644 --- a/mistralclient/tests/functional/cli/base.py +++ b/mistralclient/tests/functional/cli/base.py @@ -14,10 +14,51 @@ import os -from tempest import config +from six.moves import configparser from tempest_lib.cli import base -CONF = config.CONF + +CLI_DIR = os.environ.get( + 'OS_MISTRALCLIENT_EXEC_DIR', + os.path.join(os.path.abspath('.'), '.tox/functional/bin') +) +_CREDS_FILE = 'functional_creds.conf' + + +def credentials(group='admin'): + """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). + """ + if group == 'admin': + username = os.environ.get('OS_USERNAME') + password = os.environ.get('OS_PASSWORD') + tenant_name = os.environ.get('OS_TENANT_NAME') + else: + username = os.environ.get('OS_ALT_USERNAME') + password = os.environ.get('OS_ALT_PASSWORD') + tenant_name = os.environ.get('OS_ALT_TENANT_NAME') + + auth_url = os.environ.get('OS_AUTH_URL') + + config = configparser.RawConfigParser() + if config.read(_CREDS_FILE): + username = username or config.get(group, 'user') + password = password or config.get(group, 'pass') + tenant_name = tenant_name or config.get(group, 'tenant') + auth_url = auth_url or config.get('auth', 'uri') + + return { + 'username': username, + 'password': password, + 'tenant_name': tenant_name, + 'auth_url': auth_url + } class MistralCLIAuth(base.ClientTestBase): @@ -25,12 +66,15 @@ class MistralCLIAuth(base.ClientTestBase): _mistral_url = None def _get_admin_clients(self): + creds = credentials() + clients = base.CLIClient( - username=CONF.identity.admin_username, - password=CONF.identity.admin_password, - tenant_name=CONF.identity.admin_tenant_name, - uri=CONF.identity.uri, - cli_dir='/usr/local/bin') + username=creds['username'], + password=creds['password'], + tenant_name=creds['tenant_name'], + uri=creds['auth_url'], + cli_dir=CLI_DIR + ) return clients @@ -56,12 +100,15 @@ class MistralCLIAltAuth(base.ClientTestBase): _mistral_url = None def _get_alt_clients(self): + creds = credentials('demo') + clients = base.CLIClient( - username=CONF.identity.alt_username, - password=CONF.identity.alt_password, - tenant_name=CONF.identity.alt_tenant_name, - uri=CONF.identity.uri, - cli_dir='/usr/local/bin') + username=creds['username'], + password=creds['password'], + tenant_name=creds['tenant_name'], + uri=creds['auth_url'], + cli_dir=CLI_DIR + ) return clients diff --git a/test-requirements.txt b/test-requirements.txt index 45e1c647..1209793b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,4 +8,5 @@ unittest2 fixtures>=0.3.14 mock>=1.0 nose +tempest-lib>=0.6.1 testtools>=1.4.0 diff --git a/tox.ini b/tox.ini index 452f9902..1570c245 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,11 @@ deps = -r{toxinidir}/test-requirements.txt commands = nosetests mistralclient/tests/unit +[testenv:functional] +setenv = + OS_TEST_PATH = ./mistralclient/tests/functional +commands = {posargs} + [testenv:pep8] commands = flake8 {posargs}