From a2ebd8704baa2f23846db4a01019187d06504000 Mon Sep 17 00:00:00 2001 From: fumihiko kakuma Date: Thu, 4 Aug 2016 13:03:33 +0900 Subject: [PATCH] Allow to run functional tests This change allows to run functional tests adding gate_hook.sh and post_test_hook.sh scripts. Partial-Bug: #1560003 Change-Id: I1d34e4f3eaf2ea8de9aab070513c6590e8e785dd --- neutron_dynamic_routing/tests/contrib/README | 3 ++ .../tests/contrib/gate_hook.sh | 33 +++++++++++++ .../tests/contrib/post_test_hook.sh | 46 +++++++++++++++++++ .../tests/functional/__init__.py | 0 tox.ini | 2 +- 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 neutron_dynamic_routing/tests/contrib/README create mode 100644 neutron_dynamic_routing/tests/contrib/gate_hook.sh create mode 100644 neutron_dynamic_routing/tests/contrib/post_test_hook.sh create mode 100644 neutron_dynamic_routing/tests/functional/__init__.py diff --git a/neutron_dynamic_routing/tests/contrib/README b/neutron_dynamic_routing/tests/contrib/README new file mode 100644 index 00000000..ec45d27f --- /dev/null +++ b/neutron_dynamic_routing/tests/contrib/README @@ -0,0 +1,3 @@ +The files in this directory are intended for use by the +infra jobs that run the various functional test +suite in the gate for the neutron-dynamic-routing repo. diff --git a/neutron_dynamic_routing/tests/contrib/gate_hook.sh b/neutron_dynamic_routing/tests/contrib/gate_hook.sh new file mode 100644 index 00000000..12a6423b --- /dev/null +++ b/neutron_dynamic_routing/tests/contrib/gate_hook.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -xe + +PROJECT_NAME=neutron-dynamic-routing +GATE_DEST=$BASE/new +NEUTRON_PATH=$GATE_DEST/neutron +DR_PATH=$GATE_DEST/$PROJECT_NAME +DEVSTACK_PATH=$GATE_DEST/devstack + +VENV=${1:-"dsvm-functional"} + + +if [[ "$VENV" == dsvm-functional* ]] +then + # The following need to be set before sourcing + # configure_for_func_testing. + GATE_STACK_USER=stack + IS_GATE=True + + source $DEVSTACK_PATH/functions + source $NEUTRON_PATH/devstack/lib/ovs + source $NEUTRON_PATH/tools/configure_for_func_testing.sh + + enable_plugin $PROJECT_NAME https://git.openstack.org/openstack/$PROJECT_NAME + + # Make the workspace owned by the stack user + sudo chown -R $STACK_USER:$STACK_USER $BASE + +else + echo "Unrecognized environment $VENV". + exit 1 +fi diff --git a/neutron_dynamic_routing/tests/contrib/post_test_hook.sh b/neutron_dynamic_routing/tests/contrib/post_test_hook.sh new file mode 100644 index 00000000..0507aad0 --- /dev/null +++ b/neutron_dynamic_routing/tests/contrib/post_test_hook.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -xe + +PROJECT_NAME=neutron-dynamic-routing +GATE_DEST=$BASE/new +NEUTRON_PATH=$GATE_DEST/neutron +DR_PATH=$GATE_DEST/$PROJECT_NAME +SCRIPTS_PATH="/usr/os-testr-env/bin/" + +VENV=${1:-"dsvm-functional"} + +function generate_testr_results { + # Give job user rights to access tox logs + sudo -H -u $OWNER chmod o+rw . + sudo -H -u $OWNER chmod o+rw -R .testrepository + if [ -f ".testrepository/0" ] ; then + .tox/$VENV/bin/subunit-1to2 < .testrepository/0 > ./testrepository.subunit + $SCRIPTS_PATH/subunit2html ./testrepository.subunit testr_results.html + gzip -9 ./testrepository.subunit + gzip -9 ./testr_results.html + sudo mv ./*.gz /opt/stack/logs/ + fi +} + +if [[ "$VENV" == dsvm-functional* ]] +then + OWNER=stack + SUDO_ENV= + + # Set owner permissions according to job's requirements. + sudo chown -R $OWNER:stack $NEUTRON_PATH + sudo chown -R $OWNER:stack $DR_PATH + cd $DR_PATH + + # Run tests + echo "Running $PROJECT_NAME $VENV test suite" + set +e + sudo -H -u $OWNER $SUDO_ENV tox -e $VENV + testr_exit_code=$? + set -e + + # Collect and parse results + generate_testr_results + exit $testr_exit_code +fi diff --git a/neutron_dynamic_routing/tests/functional/__init__.py b/neutron_dynamic_routing/tests/functional/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tox.ini b/tox.ini index 94add150..47772a20 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,7 @@ whitelist_externals = cp sudo commands = - python setup.py testr --slowest --testr-args='{posargs}' + sh tools/pretty_tox.sh '{posargs}' [testenv:releasenotes] # TODO(ihrachys): remove once infra supports constraints for this target