From 75b1482a9f744cd06697d32c1a2bbc91fe849078 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Thu, 6 Aug 2015 16:22:33 +0300 Subject: [PATCH] Fix postgresql unit tests running - access to the "openstack_citest" db under the "openstack_citest" user in case if tests run on Jenkins gate, do not run commands under the 'sudo' because sudo access is revoked on Jenkins gates - add one more argument that determines in how many threads tests will be run (by default tests will be run in 1 thread, otherwise tests fail because of incorrect cleanup mechanism in unit tests) Change-Id: If332e8661f9309f71a3a0174144026de99df463e --- run_tests.sh | 44 ++++++++++++++++++++++++++++++++++++-------- tox.ini | 1 + 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 3220d6629..e1b0b62b1 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -26,6 +26,8 @@ function usage { echo " Default: \$(pwd)" echo " --db-type Database type" echo " Default: sqlite" + echo " --parallel Determines whether the tests are run in one thread or not" + echo " Default: false" echo "" echo "Note: with no options specified, the script will try to run the tests in a virtual environment," echo " If no virtualenv is found, the script will ask if you would like to create one. If you " @@ -65,6 +67,10 @@ function process_options { (( i++ )) db_type=${!i} ;; + --parallel) + (( i++ )) + parallel=${!i} + ;; -*) testropts="$testropts ${!i}";; *) testrargs="$testrargs ${!i}" esac @@ -73,6 +79,7 @@ function process_options { } db_type=${db_type:-sqlite} +parallel=${parallel:-false} tool_path=${tools_path:-$(pwd)} venv_path=${venv_path:-$(pwd)} venv_dir=${venv_name:-.venv} @@ -96,6 +103,8 @@ LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=C +ZUUL_PROJECT=${ZUUL_PROJECT:-""} + process_options $@ # Make our paths available to other scripts we call export venv_path @@ -117,12 +126,25 @@ function setup_db { postgresql ) echo "Setting up Mistral DB in PostgreSQL" - # Create the user and database. - # Assume trust is setup on localhost in the postgresql config file. - sudo -u postgres psql -c "DROP DATABASE IF EXISTS mistral;" - sudo -u postgres psql -c "DROP USER IF EXISTS mistral;" - sudo -u postgres psql -c "CREATE USER mistral WITH ENCRYPTED PASSWORD 'm1stral';" - sudo -u postgres psql -c "CREATE DATABASE mistral OWNER mistral;" + # If ZUUL_PROJECT is specified it means that this script is executing on + # Jenkins gate, so we should use already created postgresql db + if ! [ -n "$ZUUL_PROJECT"] + then + echo "PostgreSQL is initialized. 'openstack_citest' db will be used." + dbname="openstack_citest" + username="openstack_citest" + password="openstack_citest" + else + # Create the user and database. + # Assume trust is setup on localhost in the postgresql config file. + dbname="mistral" + username="mistral" + password="m1stral" + sudo -u postgres psql -c "DROP DATABASE IF EXISTS $dbname;" + sudo -u postgres psql -c "DROP USER IF EXISTS $username;" + sudo -u postgres psql -c "CREATE USER $username WITH ENCRYPTED PASSWORD '$password';" + sudo -u postgres psql -c "CREATE DATABASE $dbname OWNER $username;" + fi ;; esac } @@ -143,7 +165,7 @@ function setup_db_cfg { ;; postgresql ) oslo-config-generator --config-file ./tools/config/config-generator.mistral.conf --output-file .mistral.conf - sed -i "s/#connection = /connection = postgresql:\/\/mistral:m1stral@localhost\/mistral/g" .mistral.conf + sed -i "s/#connection = /connection = postgresql:\/\/$username:$password@localhost\/$dbname/g" .mistral.conf ;; esac } @@ -179,7 +201,13 @@ function run_tests { # Just run the test suites in current environment set +e testrargs=$(echo "$testrargs" | sed -e's/^\s*\(.*\)\s*$/\1/') - TESTRTESTS="$TESTRTESTS --testr-args='--subunit $testropts $testrargs'" + if [ $parallel = true ] + then + runoptions="--subunit" + else + runoptions="--concurrency=1 --subunit" + fi + TESTRTESTS="$TESTRTESTS --testr-args='$runoptions $testropts $testrargs'" OS_TEST_PATH=$(echo $testrargs|grep -o 'mistral\.tests[^[:space:]:]*\+'|tr . /) if [ -d "$OS_TEST_PATH" ]; then wrapper="OS_TEST_PATH=$OS_TEST_PATH $wrapper" diff --git a/tox.ini b/tox.ini index c2cc6a10d..b68e9b1d4 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,7 @@ whitelist_externals = rm [testenv:unit-postgresql] setenv = VIRTUAL_ENV={envdir} +passenv = ZUUL_PROJECT commands = ./run_tests.sh -V --db-type postgresql [testenv:pep8]