From: armando-migliaccio Date: Wed, 17 Dec 2014 22:33:42 +0000 (-0800) Subject: Tweak gate hooks scripts to handle both functional and api jobs X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=787fab3053550e5a28c56fa61562cdd96841507e;p=openstack-build%2Fneutron-build.git Tweak gate hooks scripts to handle both functional and api jobs With this change both the API and Functional job will benefit from the use of gate hooks. This is especially useful to make the API job emit the test results the same way other jobs do. NOTE: Changes are applied to both contrib directories under neutron/tests and neutron/tests/functional; these two directories are supposed to be in sync until change [1] merges, after which we can drop neutron/tests/functional/contrib, in favor of neutron/tests/contrib. This was done because of the symlink issue caused by [2]. [1] https://review.openstack.org/#/c/142603/ [2] https://review.openstack.org/#/c/143152/ Change-Id: I0b823b17d6317e9409fd9b5872c5f4674c1b6824 --- diff --git a/neutron/tests/contrib/gate_hook.sh b/neutron/tests/contrib/gate_hook.sh index 8409a3c34..2387c08cb 100644 --- a/neutron/tests/contrib/gate_hook.sh +++ b/neutron/tests/contrib/gate_hook.sh @@ -2,37 +2,41 @@ set -ex -$BASE/new/devstack-gate/devstack-vm-gate.sh - -# Add a rootwrap filter to support test-only -# configuration (e.g. a KillFilter for processes that -# use the python installed in a tox env). -FUNC_FILTER=$BASE/new/neutron/neutron/tests/functional/contrib/filters.template -sed -e "s+\$BASE_PATH+$BASE/new/neutron/.tox/dsvm-functional+" \ - $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null - -# Use devstack functions to install mysql and psql servers -TOP_DIR=$BASE/new/devstack -source $TOP_DIR/functions -source $TOP_DIR/lib/config -source $TOP_DIR/stackrc -source $TOP_DIR/lib/database -source $TOP_DIR/localrc - -disable_service postgresql -enable_service mysql -initialize_database_backends -install_database - -disable_service mysql -enable_service postgresql -initialize_database_backends -install_database - -# Set up the 'openstack_citest' user and database in each backend -tmp_dir=`mktemp -d` - -cat << EOF > $tmp_dir/mysql.sql +venv=${1:-"dsvm-functional"} + +if [ "$venv" == "dsvm-functional" ] +then + $BASE/new/devstack-gate/devstack-vm-gate.sh + + # Add a rootwrap filter to support test-only + # configuration (e.g. a KillFilter for processes that + # use the python installed in a tox env). + FUNC_FILTER=$BASE/new/neutron/neutron/tests/functional/contrib/filters.template + sed -e "s+\$BASE_PATH+$BASE/new/neutron/.tox/dsvm-functional+" \ + $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null + + # Use devstack functions to install mysql and psql servers + TOP_DIR=$BASE/new/devstack + source $TOP_DIR/functions + source $TOP_DIR/lib/config + source $TOP_DIR/stackrc + source $TOP_DIR/lib/database + source $TOP_DIR/localrc + + disable_service postgresql + enable_service mysql + initialize_database_backends + install_database + + disable_service mysql + enable_service postgresql + initialize_database_backends + install_database + + # Set up the 'openstack_citest' user and database in each backend + tmp_dir=`mktemp -d` + + cat << EOF > $tmp_dir/mysql.sql CREATE DATABASE openstack_citest; CREATE USER 'openstack_citest'@'localhost' IDENTIFIED BY 'openstack_citest'; CREATE USER 'openstack_citest' IDENTIFIED BY 'openstack_citest'; @@ -40,12 +44,13 @@ GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'localhost'; GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'; FLUSH PRIVILEGES; EOF -/usr/bin/mysql -u root < $tmp_dir/mysql.sql + /usr/bin/mysql -u root < $tmp_dir/mysql.sql -cat << EOF > $tmp_dir/postgresql.sql + cat << EOF > $tmp_dir/postgresql.sql CREATE USER openstack_citest WITH CREATEDB LOGIN PASSWORD 'openstack_citest'; CREATE DATABASE openstack_citest WITH OWNER openstack_citest; EOF -# User/group postgres needs to be given access to tmp_dir -setfacl -m g:postgres:rwx $tmp_dir -sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql + # User/group postgres needs to be given access to tmp_dir + setfacl -m g:postgres:rwx $tmp_dir + sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql +fi diff --git a/neutron/tests/contrib/post_test_hook.sh b/neutron/tests/contrib/post_test_hook.sh index dd532457e..fce0288d9 100644 --- a/neutron/tests/contrib/post_test_hook.sh +++ b/neutron/tests/contrib/post_test_hook.sh @@ -4,7 +4,8 @@ set -xe NEUTRON_DIR="$BASE/new/neutron" SCRIPTS_DIR="/usr/local/jenkins/slave_scripts" -venv=dsvm-functional + +venv=${1:-"dsvm-functional"} function generate_testr_results { # Give job user rights to access tox logs @@ -18,15 +19,42 @@ function generate_testr_results { fi } -# Run tests as the stack user to allow sudo+rootwrap. -sudo chown -R stack:stack $NEUTRON_DIR -cd $NEUTRON_DIR -echo "Running neutron functional test suite" +function dsvm_functional_prep_func { + : +} + + +function api_prep_func { + TEMPEST_DIR="$BASE/new/tempest" + sudo -H -u $owner tox -e $venv --notest + sudo -H -u $owner .tox/$venv/bin/pip install -e $TEMPEST_DIR +} + + +if [ "$venv" == "dsvm-functional" ] +then + owner=stack + prep_func="dsvm_functional_prep_func" +elif [ "$venv" == "api" ] +then + owner=tempest + prep_func="api_prep_func" +fi + +# Set owner permissions according to job's requirements. +sudo chown -R $owner:stack $NEUTRON_DIR +# Prep the environment according to job's requirements. +$prep_func + +# Run tests +cd $NEUTRON_DIR +echo "Running neutron $venv test suite" set +e -sudo -H -u stack tox -e $venv +sudo -H -u $owner tox -e $venv testr_exit_code=$? set -e +# Collect and parse results generate_testr_results exit $testr_exit_code diff --git a/neutron/tests/functional/contrib/gate_hook.sh b/neutron/tests/functional/contrib/gate_hook.sh index 8409a3c34..2387c08cb 100644 --- a/neutron/tests/functional/contrib/gate_hook.sh +++ b/neutron/tests/functional/contrib/gate_hook.sh @@ -2,37 +2,41 @@ set -ex -$BASE/new/devstack-gate/devstack-vm-gate.sh - -# Add a rootwrap filter to support test-only -# configuration (e.g. a KillFilter for processes that -# use the python installed in a tox env). -FUNC_FILTER=$BASE/new/neutron/neutron/tests/functional/contrib/filters.template -sed -e "s+\$BASE_PATH+$BASE/new/neutron/.tox/dsvm-functional+" \ - $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null - -# Use devstack functions to install mysql and psql servers -TOP_DIR=$BASE/new/devstack -source $TOP_DIR/functions -source $TOP_DIR/lib/config -source $TOP_DIR/stackrc -source $TOP_DIR/lib/database -source $TOP_DIR/localrc - -disable_service postgresql -enable_service mysql -initialize_database_backends -install_database - -disable_service mysql -enable_service postgresql -initialize_database_backends -install_database - -# Set up the 'openstack_citest' user and database in each backend -tmp_dir=`mktemp -d` - -cat << EOF > $tmp_dir/mysql.sql +venv=${1:-"dsvm-functional"} + +if [ "$venv" == "dsvm-functional" ] +then + $BASE/new/devstack-gate/devstack-vm-gate.sh + + # Add a rootwrap filter to support test-only + # configuration (e.g. a KillFilter for processes that + # use the python installed in a tox env). + FUNC_FILTER=$BASE/new/neutron/neutron/tests/functional/contrib/filters.template + sed -e "s+\$BASE_PATH+$BASE/new/neutron/.tox/dsvm-functional+" \ + $FUNC_FILTER | sudo tee /etc/neutron/rootwrap.d/functional.filters > /dev/null + + # Use devstack functions to install mysql and psql servers + TOP_DIR=$BASE/new/devstack + source $TOP_DIR/functions + source $TOP_DIR/lib/config + source $TOP_DIR/stackrc + source $TOP_DIR/lib/database + source $TOP_DIR/localrc + + disable_service postgresql + enable_service mysql + initialize_database_backends + install_database + + disable_service mysql + enable_service postgresql + initialize_database_backends + install_database + + # Set up the 'openstack_citest' user and database in each backend + tmp_dir=`mktemp -d` + + cat << EOF > $tmp_dir/mysql.sql CREATE DATABASE openstack_citest; CREATE USER 'openstack_citest'@'localhost' IDENTIFIED BY 'openstack_citest'; CREATE USER 'openstack_citest' IDENTIFIED BY 'openstack_citest'; @@ -40,12 +44,13 @@ GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'@'localhost'; GRANT ALL PRIVILEGES ON *.* TO 'openstack_citest'; FLUSH PRIVILEGES; EOF -/usr/bin/mysql -u root < $tmp_dir/mysql.sql + /usr/bin/mysql -u root < $tmp_dir/mysql.sql -cat << EOF > $tmp_dir/postgresql.sql + cat << EOF > $tmp_dir/postgresql.sql CREATE USER openstack_citest WITH CREATEDB LOGIN PASSWORD 'openstack_citest'; CREATE DATABASE openstack_citest WITH OWNER openstack_citest; EOF -# User/group postgres needs to be given access to tmp_dir -setfacl -m g:postgres:rwx $tmp_dir -sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql + # User/group postgres needs to be given access to tmp_dir + setfacl -m g:postgres:rwx $tmp_dir + sudo -u postgres /usr/bin/psql --file=$tmp_dir/postgresql.sql +fi diff --git a/neutron/tests/functional/contrib/post_test_hook.sh b/neutron/tests/functional/contrib/post_test_hook.sh index dd532457e..fce0288d9 100644 --- a/neutron/tests/functional/contrib/post_test_hook.sh +++ b/neutron/tests/functional/contrib/post_test_hook.sh @@ -4,7 +4,8 @@ set -xe NEUTRON_DIR="$BASE/new/neutron" SCRIPTS_DIR="/usr/local/jenkins/slave_scripts" -venv=dsvm-functional + +venv=${1:-"dsvm-functional"} function generate_testr_results { # Give job user rights to access tox logs @@ -18,15 +19,42 @@ function generate_testr_results { fi } -# Run tests as the stack user to allow sudo+rootwrap. -sudo chown -R stack:stack $NEUTRON_DIR -cd $NEUTRON_DIR -echo "Running neutron functional test suite" +function dsvm_functional_prep_func { + : +} + + +function api_prep_func { + TEMPEST_DIR="$BASE/new/tempest" + sudo -H -u $owner tox -e $venv --notest + sudo -H -u $owner .tox/$venv/bin/pip install -e $TEMPEST_DIR +} + + +if [ "$venv" == "dsvm-functional" ] +then + owner=stack + prep_func="dsvm_functional_prep_func" +elif [ "$venv" == "api" ] +then + owner=tempest + prep_func="api_prep_func" +fi + +# Set owner permissions according to job's requirements. +sudo chown -R $owner:stack $NEUTRON_DIR +# Prep the environment according to job's requirements. +$prep_func + +# Run tests +cd $NEUTRON_DIR +echo "Running neutron $venv test suite" set +e -sudo -H -u stack tox -e $venv +sudo -H -u $owner tox -e $venv testr_exit_code=$? set -e +# Collect and parse results generate_testr_results exit $testr_exit_code