Skip to content

Commit 244f229

Browse files
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
1 parent 0835706 commit 244f229

3 files changed

Lines changed: 68 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ dist
1616
AUTHORS
1717
ChangeLog
1818
releasenotes/build
19+
.idea/

cloudkittyclient/tests/functional/base.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,57 @@
1515
#
1616
import json
1717
import os
18-
import shlex
1918
import subprocess
2019

2120
from cloudkittyclient.tests import utils
2221

22+
from oslo_log import log
23+
24+
LOG = log.getLogger(__name__)
25+
2326

2427
class BaseFunctionalTest(utils.BaseTestCase):
2528

29+
# DevStack is using VENV by default. Therefore, to execute the commands,
30+
# we need to activate the VENV. And, to do that, we need the VENV path.
31+
# This path is hardcoded here because we could not find a variable in this
32+
# Python code to retrieve the VENV variable from the test machine.
33+
# It seems that because of the stack TOX -> stestr -> this python code, and
34+
# so on, we are not able to access the DevStack variables here.
35+
#
36+
# If somebody finds a solution, we can remove the hardcoded path here.
37+
DEV_STACK_VENV_BASE_PATH = "/opt/stack/data/venv"
38+
39+
BASE_COMMAND_WITH_VENV = "source %s/bin/activate && %s "
40+
2641
def _run(self, executable, action,
2742
flags='', params='', fmt='-f json', stdin=None, has_output=True):
2843
if not has_output:
2944
fmt = ''
45+
46+
does_venv_exist = not os.system("ls -lah /opt/stack/data/venv")
47+
LOG.info("Test to check if the VENV file exist returned: [%s].",
48+
does_venv_exist)
49+
50+
system_variables = os.environ.copy()
51+
LOG.info("System variables [%s] found when executing the tests.",
52+
system_variables)
53+
3054
cmd = ' '.join([executable, flags, action, params, fmt])
31-
cmd = shlex.split(cmd)
55+
56+
actual_command_with_venv = self.BASE_COMMAND_WITH_VENV % (
57+
self.DEV_STACK_VENV_BASE_PATH, cmd)
58+
59+
LOG.info("Command being executed: [%s].", actual_command_with_venv)
60+
3261
p = subprocess.Popen(
33-
cmd, env=os.environ.copy(), shell=False,
34-
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
35-
stdin=subprocess.PIPE if stdin else None,
62+
["bash", "-c", actual_command_with_venv],
63+
env=os.environ.copy(), shell=False, stdout=subprocess.PIPE,
64+
stderr=subprocess.PIPE, stdin=subprocess.PIPE if stdin else None
3665
)
3766
stdout, stderr = p.communicate(input=stdin)
67+
LOG.info("Standard output [%s] and error output [%s] for command "
68+
"[%s]. ", stdout, stderr, actual_command_with_venv)
3869
if p.returncode != 0:
3970
raise RuntimeError('"{cmd}" returned {val}: {msg}'.format(
4071
cmd=' '.join(cmd), val=p.returncode, msg=stderr))

tox.ini

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ basepython = python3
99
usedevelop = True
1010
install_command = pip install -U {opts} {packages}
1111
setenv =
12+
DEVSTACK_VENV={env:DEVSTACK_VENV}
1213
VIRTUAL_ENV={envdir}
1314
deps = -r{toxinidir}/requirements.txt
1415
-r{toxinidir}/test-requirements.txt
@@ -29,12 +30,40 @@ commands =
2930
commands = oslo_debug_helper -t cloudkittyclient/tests {posargs}
3031

3132
[testenv:functional-v1]
32-
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
33+
passenv =
34+
OS_CLOUD
35+
OS_PROJECT_DOMAIN_ID
36+
OS_USER_DOMAIN_ID
37+
OS_PROJECT_DOMAIN_NAME
38+
OS_USER_DOMAIN_NAME
39+
OS_PROJECT_NAME
40+
OS_IDENTITY_API_VERSION
41+
OS_PASSWORD
42+
OS_AUTH_TYPE
43+
OS_AUTH_URL
44+
OS_USERNAME
45+
OS_ENDPOINT
46+
DEVSTACK_VENV
47+
VIRTUAL_ENV
3348
setenv = OS_RATING_API_VERSION=1
3449
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v1
3550

3651
[testenv:functional-v2]
37-
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
52+
passenv =
53+
OS_CLOUD
54+
OS_PROJECT_DOMAIN_ID
55+
OS_USER_DOMAIN_ID
56+
OS_PROJECT_DOMAIN_NAME
57+
OS_USER_DOMAIN_NAME
58+
OS_PROJECT_NAME
59+
OS_IDENTITY_API_VERSION
60+
OS_PASSWORD
61+
OS_AUTH_TYPE
62+
OS_AUTH_URL
63+
OS_USERNAME
64+
OS_ENDPOINT
65+
DEVSTACK_VENV
66+
VIRTUAL_ENV
3867
setenv = OS_RATING_API_VERSION=2
3968
commands = stestr run --concurrency=1 --test-path ./cloudkittyclient/tests/functional/v2
4069

0 commit comments

Comments
 (0)