blob: 710fbaa6be759bfa524c92d5635c2c1c7e2fc650 [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]..."
5 echo "Run Tempest test suite"
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"
Jay Pipesf38eaac2012-06-21 13:37:35 -040012 echo " -s, --smoke Only run smoke tests"
Matthew Treinish49f40362013-08-27 16:02:53 -040013 echo " -t, --serial Run testr serially"
Matthew Treinishd15705b2012-10-16 14:04:48 -040014 echo " -c, --nova-coverage Enable Nova coverage collection"
Attila Fazekasa63a9992013-02-14 16:44:37 +010015 echo " -C, --config Config file location"
Jay Pipesf38eaac2012-06-21 13:37:35 -040016 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050017 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050018 echo " -d, --debug Debug this script -- set -o xtrace"
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090019 echo " -l, --logging Enable logging"
20 echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
Matthew Treinish59eb0b22013-08-07 15:48:21 -040021 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050022}
23
Matthew Treinish59eb0b22013-08-07 15:48:21 -040024testrargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040025just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050026venv=.venv
27with_venv=tools/with_venv.sh
Matthew Treinish49f40362013-08-27 16:02:53 -040028serial=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050029always_venv=0
30never_venv=0
31no_site_packages=0
32force=0
33wrapper=""
Matthew Treinishd15705b2012-10-16 14:04:48 -040034nova_coverage=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010035config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050036update=0
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090037logging=0
38logging_config=etc/logging.conf
Attila Fazekasa63a9992013-02-14 16:44:37 +010039
Matthew Treinishde8378b2013-09-11 14:19:46 -040040if ! options=$(getopt -o VNnfustcphdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,nova-coverage,pep8,help,debug,config:,logging,logging-config: -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010041then
42 # parse error
43 usage
44 exit 1
45fi
46
47eval set -- $options
48first_uu=yes
49while [ $# -gt 0 ]; do
50 case "$1" in
51 -h|--help) usage; exit;;
52 -V|--virtual-env) always_venv=1; never_venv=0;;
53 -N|--no-virtual-env) always_venv=0; never_venv=1;;
54 -n|--no-site-packages) no_site_packages=1;;
55 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050056 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010057 -d|--debug) set -o xtrace;;
58 -c|--nova-coverage) let nova_coverage=1;;
59 -C|--config) config_file=$2; shift;;
60 -p|--pep8) let just_pep8=1;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040061 -s|--smoke) testrargs="$testrargs smoke";;
Matthew Treinish49f40362013-08-27 16:02:53 -040062 -t|--serial) serial=1;;
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090063 -l|--logging) logging=1;;
64 -L|--logging-config) logging_config=$2; shift;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040065 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
66 *) testrargs="$testrargs $1"
Attila Fazekasa63a9992013-02-14 16:44:37 +010067 esac
68 shift
69done
70
71if [ -n "$config_file" ]; then
72 config_file=`readlink -f "$config_file"`
73 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
74 export TEMPEST_CONFIG=`basename "$config_file"`
75fi
76
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090077if [ $logging -eq 1 ]; then
78 if [ ! -f "$logging_config" ]; then
79 echo "No such logging config file: $logging_config"
80 exit 1
81 fi
82 logging_config=`readlink -f "$logging_config"`
83 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
84 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
85fi
86
Attila Fazekasa63a9992013-02-14 16:44:37 +010087cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040088
Matthew Treinish8e937d72012-12-14 11:11:41 -050089if [ $no_site_packages -eq 1 ]; then
90 installvenvopts="--no-site-packages"
91fi
Sean Dague422af972012-11-16 07:30:43 -050092
Matthew Treinish87af1bb2013-06-17 15:29:10 -040093function testr_init {
94 if [ ! -d .testrepository ]; then
95 ${wrapper} testr init
96 fi
97}
98
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050099function run_tests {
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400100 testr_init
101 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish49f40362013-08-27 16:02:53 -0400102 if [ $serial -eq 1 ]; then
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400103 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish49f40362013-08-27 16:02:53 -0400104 else
105 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400106 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500107}
108
Matthew Treinishf0e47472013-08-15 16:54:45 -0400109function run_tests_nose {
110 NOSE_WITH_OPENSTACK=1
111 NOSE_OPENSTACK_COLOR=1
112 NOSE_OPENSTACK_RED=15.00
113 NOSE_OPENSTACK_YELLOW=3.00
114 NOSE_OPENSTACK_SHOW_ELAPSED=1
115 NOSE_OPENSTACK_STDOUT=1
116 if [[ "x$noseargs" =~ "tempest" ]]; then
117 noseargs="$testrargs"
118 else
119 noseargs="$noseargs tempest"
120 fi
121 ${wrapper} nosetests $noseargs
122}
123
Jay Pipesf38eaac2012-06-21 13:37:35 -0400124function run_pep8 {
Kui Shib1b7c712013-08-23 06:40:05 +0800125 echo "Running flake8 ..."
126 if [ $never_venv -eq 1 ]; then
127 echo "**WARNING**:" >&2
128 echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2
129 fi
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700130 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400131}
132
Matthew Treinishd15705b2012-10-16 14:04:48 -0400133function run_coverage_start {
134 echo "Starting nova-coverage"
135 ${wrapper} python tools/tempest_coverage.py -c start
136}
137
138function run_coverage_report {
139 echo "Generating nova-coverage report"
140 ${wrapper} python tools/tempest_coverage.py -c report
141}
142
Matthew Treinish8e937d72012-12-14 11:11:41 -0500143if [ $never_venv -eq 0 ]
144then
145 # Remove the virtual environment if --force used
146 if [ $force -eq 1 ]; then
147 echo "Cleaning virtualenv..."
148 rm -rf ${venv}
149 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500150 if [ $update -eq 1 ]; then
151 echo "Updating virtualenv..."
152 python tools/install_venv.py $installvenvopts
153 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500154 if [ -e ${venv} ]; then
155 wrapper="${with_venv}"
156 else
157 if [ $always_venv -eq 1 ]; then
158 # Automatically install the virtualenv
159 python tools/install_venv.py $installvenvopts
160 wrapper="${with_venv}"
161 else
162 echo -e "No virtual environment found...create one? (Y/n) \c"
163 read use_ve
164 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
165 # Install the virtualenv and run the test suite in it
166 python tools/install_venv.py $installvenvopts
167 wrapper=${with_venv}
168 fi
169 fi
170 fi
171fi
172
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500173if [ $just_pep8 -eq 1 ]; then
174 run_pep8
175 exit
176fi
177
Matthew Treinishd15705b2012-10-16 14:04:48 -0400178if [ $nova_coverage -eq 1 ]; then
179 run_coverage_start
180fi
181
Matthew Treinishf0e47472013-08-15 16:54:45 -0400182
183py_version=`${wrapper} python --version 2>&1`
184if [[ $py_version =~ "2.6" ]] ; then
185 run_tests_nose
186else
187 run_tests
188fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200189retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400190
191if [ $nova_coverage -eq 1 ]; then
192 run_coverage_report
193fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400194
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400195if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200196 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400197fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200198
199exit $retval