diff --git a/.gitignore b/.gitignore index 7a467f7..ce8609f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ dist AUTHORS ChangeLog releasenotes/build +.idea/ diff --git a/cloudkittyclient/tests/functional/base.py b/cloudkittyclient/tests/functional/base.py index b1d0489..444017d 100644 --- a/cloudkittyclient/tests/functional/base.py +++ b/cloudkittyclient/tests/functional/base.py @@ -15,26 +15,57 @@ # import json import os -import shlex import subprocess from cloudkittyclient.tests import utils +from oslo_log import log + +LOG = log.getLogger(__name__) + class BaseFunctionalTest(utils.BaseTestCase): + # DevStack is using VENV by default. Therefore, to execute the commands, + # we need to activate the VENV. And, to do that, we need the VENV path. + # This path is hardcoded here because we could not find a variable in this + # Python code to retrieve the VENV variable from the test machine. + # It seems that because of the stack TOX -> stestr -> this python code, and + # so on, we are not able to access the DevStack variables here. + # + # If somebody finds a solution, we can remove the hardcoded path here. + DEV_STACK_VENV_BASE_PATH = "/opt/stack/data/venv" + + BASE_COMMAND_WITH_VENV = "source %s/bin/activate && %s " + def _run(self, executable, action, flags='', params='', fmt='-f json', stdin=None, has_output=True): if not has_output: fmt = '' + + does_venv_exist = not os.system("ls -lah /opt/stack/data/venv") + LOG.info("Test to check if the VENV file exist returned: [%s].", + does_venv_exist) + + system_variables = os.environ.copy() + LOG.info("System variables [%s] found when executing the tests.", + system_variables) + cmd = ' '.join([executable, flags, action, params, fmt]) - cmd = shlex.split(cmd) + + actual_command_with_venv = self.BASE_COMMAND_WITH_VENV % ( + self.DEV_STACK_VENV_BASE_PATH, cmd) + + LOG.info("Command being executed: [%s].", actual_command_with_venv) + p = subprocess.Popen( - cmd, env=os.environ.copy(), shell=False, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=subprocess.PIPE if stdin else None, + ["bash", "-c", actual_command_with_venv], + env=os.environ.copy(), shell=False, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=subprocess.PIPE if stdin else None ) stdout, stderr = p.communicate(input=stdin) + LOG.info("Standard output [%s] and error output [%s] for command " + "[%s]. ", stdout, stderr, actual_command_with_venv) if p.returncode != 0: raise RuntimeError('"{cmd}" returned {val}: {msg}'.format( cmd=' '.join(cmd), val=p.returncode, msg=stderr)) diff --git a/tox.ini b/tox.ini index ef4327d..455afda 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ basepython = python3 usedevelop = True install_command = pip install -U {opts} {packages} setenv = + DEVSTACK_VENV={env:DEVSTACK_VENV} VIRTUAL_ENV={envdir} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt @@ -29,12 +30,40 @@ commands = commands = oslo_debug_helper -t cloudkittyclient/tests {posargs} [testenv:functional-v1] -passenv = OS_CLOUD OS_PROJECT_DOMAIN_ID OS_USER_DOMAIN_ID OS_PROJECT_DOMAIN_NAME OS_USER_DOMAIN_NAME OS_PROJECT_NAME OS_IDENTITY_API_VERSION OS_PASSWORD OS_AUTH_TYPE OS_AUTH_URL OS_USERNAME OS_ENDPOINT +passenv = + OS_CLOUD + OS_PROJECT_DOMAIN_ID + OS_USER_DOMAIN_ID + OS_PROJECT_DOMAIN_NAME + OS_USER_DOMAIN_NAME + OS_PROJECT_NAME + OS_IDENTITY_API_VERSION + OS_PASSWORD + OS_AUTH_TYPE + OS_AUTH_URL + OS_USERNAME + OS_ENDPOINT + DEVSTACK_VENV + VIRTUAL_ENV setenv = OS_RATING_API_VERSION=1 commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v1 [testenv:functional-v2] -passenv = OS_CLOUD OS_PROJECT_DOMAIN_ID OS_USER_DOMAIN_ID OS_PROJECT_DOMAIN_NAME OS_USER_DOMAIN_NAME OS_PROJECT_NAME OS_IDENTITY_API_VERSION OS_PASSWORD OS_AUTH_TYPE OS_AUTH_URL OS_USERNAME OS_ENDPOINT +passenv = + OS_CLOUD + OS_PROJECT_DOMAIN_ID + OS_USER_DOMAIN_ID + OS_PROJECT_DOMAIN_NAME + OS_USER_DOMAIN_NAME + OS_PROJECT_NAME + OS_IDENTITY_API_VERSION + OS_PASSWORD + OS_AUTH_TYPE + OS_AUTH_URL + OS_USERNAME + OS_ENDPOINT + DEVSTACK_VENV + VIRTUAL_ENV setenv = OS_RATING_API_VERSION=2 commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v2