Fix passenv declaration in tox.ini and function tests python env
While running the tests with the latest tox I was getting the following error message: ``` failed with pass_env values cannot contain whitespace, use comma to have multiple values in a single line' ``` That error is happening because of the passenv declaration. This patch is proposing a fix for that. Besides the `tox` issue, we also needed to create a patch for the use of virtual env inside DevStack. This patches presents a solution to run tests using the virtual env of DevStack. Change-Id: Id8249ebb15d4047dcc6181908eae66eb39722863
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@ dist
|
|||||||
AUTHORS
|
AUTHORS
|
||||||
ChangeLog
|
ChangeLog
|
||||||
releasenotes/build
|
releasenotes/build
|
||||||
|
.idea/
|
||||||
|
@@ -15,26 +15,57 @@
|
|||||||
#
|
#
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from cloudkittyclient.tests import utils
|
from cloudkittyclient.tests import utils
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseFunctionalTest(utils.BaseTestCase):
|
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,
|
def _run(self, executable, action,
|
||||||
flags='', params='', fmt='-f json', stdin=None, has_output=True):
|
flags='', params='', fmt='-f json', stdin=None, has_output=True):
|
||||||
if not has_output:
|
if not has_output:
|
||||||
fmt = ''
|
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 = ' '.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(
|
p = subprocess.Popen(
|
||||||
cmd, env=os.environ.copy(), shell=False,
|
["bash", "-c", actual_command_with_venv],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
env=os.environ.copy(), shell=False, stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE if stdin else None,
|
stderr=subprocess.PIPE, stdin=subprocess.PIPE if stdin else None
|
||||||
)
|
)
|
||||||
stdout, stderr = p.communicate(input=stdin)
|
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:
|
if p.returncode != 0:
|
||||||
raise RuntimeError('"{cmd}" returned {val}: {msg}'.format(
|
raise RuntimeError('"{cmd}" returned {val}: {msg}'.format(
|
||||||
cmd=' '.join(cmd), val=p.returncode, msg=stderr))
|
cmd=' '.join(cmd), val=p.returncode, msg=stderr))
|
||||||
|
33
tox.ini
33
tox.ini
@@ -9,6 +9,7 @@ basepython = python3
|
|||||||
usedevelop = True
|
usedevelop = True
|
||||||
install_command = pip install -U {opts} {packages}
|
install_command = pip install -U {opts} {packages}
|
||||||
setenv =
|
setenv =
|
||||||
|
DEVSTACK_VENV={env:DEVSTACK_VENV}
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
@@ -29,12 +30,40 @@ commands =
|
|||||||
commands = oslo_debug_helper -t cloudkittyclient/tests {posargs}
|
commands = oslo_debug_helper -t cloudkittyclient/tests {posargs}
|
||||||
|
|
||||||
[testenv:functional-v1]
|
[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
|
setenv = OS_RATING_API_VERSION=1
|
||||||
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v1
|
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v1
|
||||||
|
|
||||||
[testenv:functional-v2]
|
[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
|
setenv = OS_RATING_API_VERSION=2
|
||||||
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v2
|
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v2
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user