From d25bdcf76dda7c3d7b77e942d138cf5e0df6e04c Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Thu, 3 Aug 2017 01:17:58 +0300 Subject: [PATCH] [ci] Rework launching cli job There are 2 critical blocking issues related to cli job: * bug related to db conflict between 2 tests (samples and lib check). We already spent ~ a month reserching the root of an issue and trying to fix it. Unfortunately, we did not succeded. Since we are planning to rework samples mechanism, the applied solution in this patch should not look like a dirty workaround - split launching main cli tests and samples check. To do this, we need to modify out pytest launcher a bit * Rally-CI has two cli jobs for mysql and postgres backends. While porting them to use `tox -ecli` command, passing the proper env variable was missed and sqlite is used now in both cases. Passing the right environment variable is not only required step, setting serial mode of pytest is important too, since we do not want to have conflicts in tests connecting to the one db. Also, this patch removes unused option (--timeout) of pytest launcher. Change-Id: I7fc109ee5785f426211fbff7eb9b4553a3671ba7 --- tests/check_samples/__init__.py | 0 .../test_task_samples.py | 0 tests/ci/pytest_launcher.py | 9 ++++---- tests/ci/rally_cli_job.sh | 21 +++++++++++++++++++ tox.ini | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 tests/check_samples/__init__.py rename tests/{functional => check_samples}/test_task_samples.py (100%) create mode 100755 tests/ci/rally_cli_job.sh diff --git a/tests/check_samples/__init__.py b/tests/check_samples/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/functional/test_task_samples.py b/tests/check_samples/test_task_samples.py similarity index 100% rename from tests/functional/test_task_samples.py rename to tests/check_samples/test_task_samples.py diff --git a/tests/ci/pytest_launcher.py b/tests/ci/pytest_launcher.py index d1e76d1072..911acd44bd 100755 --- a/tests/ci/pytest_launcher.py +++ b/tests/ci/pytest_launcher.py @@ -25,7 +25,7 @@ PYTEST_ARGUMENTS = ("py.test" # base command " --html=%(html_report)s" # html report " --self-contained-html" # embedded css " --durations=10" # get a list of the slowest 10 tests - " -n auto" # launch tests in parallel + " -n %(concurrency)s" # launch tests in parallel " %(path)s" ) @@ -42,9 +42,8 @@ def main(args): parser.add_argument("--posargs", metavar="", type=str, default="", help="TOX posargs. Currently supported only string to " "partial test or tests group to launch.") - parser.add_argument("--timeout", metavar="", type=int, default=60, - help="Timeout for individual test execution. " - "Defaults to 60") + parser.add_argument("--concurrency", metavar="", type=int, + help="Number of parallel processes.") args = parser.parse_args(args[1:]) # We allow only one parameter - path to partial test or tests group @@ -99,7 +98,7 @@ def main(args): args = PYTEST_ARGUMENTS % {"html_report": pytest_report, "path": path, - "timeout": args.timeout} + "concurrency": args.concurrency or "auto"} try: subprocess.check_call(args.split(" "), stderr=subprocess.STDOUT) diff --git a/tests/ci/rally_cli_job.sh b/tests/ci/rally_cli_job.sh new file mode 100755 index 0000000000..1fe87b47b1 --- /dev/null +++ b/tests/ci/rally_cli_job.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +LOCAL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +DB_CONNECTION="$(rally-manage db show)" + +if [[ $DB_CONNECTION == sqlite* ]]; then + CONCURRENCY=0 +else + # in case of not sqlite db backends we cannot launch tests in parallel due + # to possible conflicts + CONCURRENCY=1 + # currently, RCI_KEEP_DB variable is used to not create new databases per + # each test + export RCI_KEEP_DB=1 +fi + + +python $LOCAL_DIR/pytest_launcher.py "tests/functional" --concurrency $CONCURRENCY + +python $LOCAL_DIR/pytest_launcher.py "tests/check_samples" diff --git a/tox.ini b/tox.ini index f132cde34d..599f44909d 100644 --- a/tox.ini +++ b/tox.ini @@ -57,7 +57,7 @@ commands = oslo_debug_helper -t tests {posargs} sitepackages = True commands = find . -type f -name "*.pyc" -delete - python {toxinidir}/tests/ci/pytest_launcher.py "tests/functional" --timeout -1 --posargs={posargs} + {toxinidir}/tests/ci/rally_cli_job.sh [testenv:cover] commands = {toxinidir}/tests/ci/cover.sh {posargs}