blob: 3f00453cbf5b8f37ce1e7ff91296ed85f75d8b61 [file] [log] [blame]
Attila Fazekas5abb2532012-12-04 11:30:49 +01001#!/usr/bin/env bash
Justin Shepherd0d9bbd12011-08-11 12:57:44 -05002
3function usage {
Jay Pipesf38eaac2012-06-21 13:37:35 -04004 echo "Usage: $0 [OPTION]..."
Matthew Treinish17520e42014-01-05 13:02:23 -05005 echo "Run Tempest unit tests"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -05006 echo ""
Matthew Treinish8e937d72012-12-14 11:11:41 -05007 echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
8 echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
Andrea Frittoli1cfbc4a2013-01-31 19:44:10 +00009 echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
Matthew Treinish8e937d72012-12-14 11:11:41 -050010 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050011 echo " -u, --update Update the virtual environment with any newer package versions"
Matthew Treinish49f40362013-08-27 16:02:53 -040012 echo " -t, --serial Run testr serially"
Jay Pipesf38eaac2012-06-21 13:37:35 -040013 echo " -p, --pep8 Just run pep8"
Matthew Treinishab836be2014-01-11 14:34:58 -050014 echo " -c, --coverage Generate coverage report"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050015 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050016 echo " -d, --debug Debug this script -- set -o xtrace"
Matthew Treinish59eb0b22013-08-07 15:48:21 -040017 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050018}
19
Matthew Treinish59eb0b22013-08-07 15:48:21 -040020testrargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040021just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050022venv=.venv
23with_venv=tools/with_venv.sh
Matthew Treinish49f40362013-08-27 16:02:53 -040024serial=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050025always_venv=0
26never_venv=0
27no_site_packages=0
28force=0
Matthew Treinishab836be2014-01-11 14:34:58 -050029coverage=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050030wrapper=""
Attila Fazekasa63a9992013-02-14 16:44:37 +010031config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050032update=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010033
Matthew Treinishab836be2014-01-11 14:34:58 -050034if ! options=$(getopt -o VNnfuctphd -l virtual-env,no-virtual-env,no-site-packages,force,update,serial,coverage,pep8,help,debug -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010035then
36 # parse error
37 usage
38 exit 1
39fi
40
41eval set -- $options
42first_uu=yes
43while [ $# -gt 0 ]; do
44 case "$1" in
45 -h|--help) usage; exit;;
46 -V|--virtual-env) always_venv=1; never_venv=0;;
47 -N|--no-virtual-env) always_venv=0; never_venv=1;;
48 -n|--no-site-packages) no_site_packages=1;;
49 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050050 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010051 -d|--debug) set -o xtrace;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010052 -p|--pep8) let just_pep8=1;;
Matthew Treinishab836be2014-01-11 14:34:58 -050053 -c|--coverage) coverage=1;;
Matthew Treinish49f40362013-08-27 16:02:53 -040054 -t|--serial) serial=1;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040055 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Sunil Thahaee332b02013-10-10 13:49:19 +100056 *) testrargs="$testrargs $1"; noseargs+=" $1" ;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010057 esac
58 shift
59done
60
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090061
Attila Fazekasa63a9992013-02-14 16:44:37 +010062cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040063
Matthew Treinish8e937d72012-12-14 11:11:41 -050064if [ $no_site_packages -eq 1 ]; then
65 installvenvopts="--no-site-packages"
66fi
Sean Dague422af972012-11-16 07:30:43 -050067
Matthew Treinish87af1bb2013-06-17 15:29:10 -040068function testr_init {
69 if [ ! -d .testrepository ]; then
70 ${wrapper} testr init
71 fi
72}
73
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050074function run_tests {
Matthew Treinish59eb0b22013-08-07 15:48:21 -040075 testr_init
76 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish17520e42014-01-05 13:02:23 -050077 export OS_TEST_PATH=./tempest/tests
Matthew Treinish49f40362013-08-27 16:02:53 -040078 if [ $serial -eq 1 ]; then
Matthew Treinish59eb0b22013-08-07 15:48:21 -040079 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish49f40362013-08-27 16:02:53 -040080 else
81 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -040082 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050083}
84
Jay Pipesf38eaac2012-06-21 13:37:35 -040085function run_pep8 {
Kui Shib1b7c712013-08-23 06:40:05 +080086 echo "Running flake8 ..."
87 if [ $never_venv -eq 1 ]; then
88 echo "**WARNING**:" >&2
89 echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2
90 fi
Monty Taylorb2ca5ca2013-04-28 18:00:21 -070091 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -040092}
93
Matthew Treinish8e937d72012-12-14 11:11:41 -050094if [ $never_venv -eq 0 ]
95then
96 # Remove the virtual environment if --force used
97 if [ $force -eq 1 ]; then
98 echo "Cleaning virtualenv..."
99 rm -rf ${venv}
100 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500101 if [ $update -eq 1 ]; then
102 echo "Updating virtualenv..."
103 python tools/install_venv.py $installvenvopts
104 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500105 if [ -e ${venv} ]; then
106 wrapper="${with_venv}"
107 else
108 if [ $always_venv -eq 1 ]; then
109 # Automatically install the virtualenv
110 python tools/install_venv.py $installvenvopts
111 wrapper="${with_venv}"
112 else
113 echo -e "No virtual environment found...create one? (Y/n) \c"
114 read use_ve
115 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
116 # Install the virtualenv and run the test suite in it
117 python tools/install_venv.py $installvenvopts
118 wrapper=${with_venv}
119 fi
120 fi
121 fi
122fi
123
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500124if [ $just_pep8 -eq 1 ]; then
125 run_pep8
126 exit
127fi
128
Masayuki Igawa9a223352014-01-14 11:02:53 +0900129if [ $coverage -eq 1 ]; then
Matthew Treinishab836be2014-01-11 14:34:58 -0500130 $testrargs = "--coverage $testrargs"
131fi
132
Matthew Treinish17520e42014-01-05 13:02:23 -0500133run_tests
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200134retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400135
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400136if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200137 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400138fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200139
140exit $retval