From 6c0ad7c5f5fbd2a0808ce268b3ba29627b7682a3 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 27 Mar 2014 08:16:08 -0700 Subject: Import run_cross_tests.sh from oslo-incubator Add the script for running unit tests in other projects so we can more easily establish cross-project gate jobs. Depends on https://review.openstack.org/#/c/83411/ and https://review.openstack.org/#/c/83412/ Change-Id: I0c4b1c425c3aea18b7825c75b9147fd8a1da6914 --- openstack-common.conf | 7 +++++ tools/run_cross_tests.sh | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 openstack-common.conf create mode 100755 tools/run_cross_tests.sh diff --git a/openstack-common.conf b/openstack-common.conf new file mode 100644 index 0000000..3fffac5 --- /dev/null +++ b/openstack-common.conf @@ -0,0 +1,7 @@ +[DEFAULT] + +# The list of modules to copy from oslo-incubator.git +script = tools/run_cross_tests.sh + +# The base module to hold the copy of openstack.common +base=oslotest diff --git a/tools/run_cross_tests.sh b/tools/run_cross_tests.sh new file mode 100755 index 0000000..fb21e65 --- /dev/null +++ b/tools/run_cross_tests.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# +# Run cross-project tests + +# Fail the build if any command fails +set -e + +project_dir="$1" +venv="$2" + +# Set up the virtualenv without running the tests +(cd $project_dir && tox --notest -e $venv) + +tox_envbin=$project_dir/.tox/$venv/bin + +our_name=$(python setup.py --name) + +# Replace the pip-installed package with the version in our source +# tree. Look to see if we are already installed before trying to +# uninstall ourselves, to avoid failures from packages that do not use us +# yet. +if $tox_envbin/pip freeze | grep -q $our_name +then + $tox_envbin/pip uninstall -y $our_name +fi +$tox_envbin/pip install -U . + +# Run the tests +(cd $project_dir && tox -e $venv) +result=$? + + +# The below checks are modified from +# openstack-infra/config/modules/jenkins/files/slave_scripts/run-unittests.sh. + +# They expect to be run in the project being tested. +cd $project_dir + +echo "Begin pip freeze output from test virtualenv:" +echo "======================================================================" +.tox/$venv/bin/pip freeze +echo "======================================================================" + +# We only want to run the next check if the tool is installed, so look +# for it before continuing. +if [ -f /usr/local/jenkins/slave_scripts/subunit2html.py -a -d ".testrepository" ] ; then + if [ -f ".testrepository/0.2" ] ; then + cp .testrepository/0.2 ./subunit_log.txt + elif [ -f ".testrepository/0" ] ; then + .tox/$venv/bin/subunit-1to2 < .testrepository/0 > ./subunit_log.txt + fi + .tox/$venv/bin/python /usr/local/jenkins/slave_scripts/subunit2html.py ./subunit_log.txt testr_results.html + gzip -9 ./subunit_log.txt + gzip -9 ./testr_results.html + + export PYTHON=.tox/$venv/bin/python + set -e + rancount=$(.tox/$venv/bin/testr last | sed -ne 's/Ran \([0-9]\+\).*tests in.*/\1/p') + if [ "$rancount" -eq "0" ] ; then + echo + echo "Zero tests were run. At least one test should have been run." + echo "Failing this test as a result" + echo + exit 1 + fi +fi + +# If we make it this far, report status based on the tests that were +# run. +exit $result -- cgit v1.2.1