blob: d672b6213fb121b0c8ef8b0703ddaa996ea4b4cf [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"
Jay Pipes051075a2012-04-28 17:39:37 -040013 echo " -w, --whitebox Only run whitebox tests"
Matthew Treinish49f40362013-08-27 16:02:53 -040014 echo " -t, --serial Run testr serially"
Matthew Treinishd15705b2012-10-16 14:04:48 -040015 echo " -c, --nova-coverage Enable Nova coverage collection"
Attila Fazekasa63a9992013-02-14 16:44:37 +010016 echo " -C, --config Config file location"
Jay Pipesf38eaac2012-06-21 13:37:35 -040017 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050018 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050019 echo " -d, --debug Debug this script -- set -o xtrace"
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090020 echo " -l, --logging Enable logging"
21 echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
Matthew Treinish59eb0b22013-08-07 15:48:21 -040022 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050023}
24
Matthew Treinish59eb0b22013-08-07 15:48:21 -040025testrargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040026just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050027venv=.venv
28with_venv=tools/with_venv.sh
Matthew Treinish49f40362013-08-27 16:02:53 -040029serial=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050030always_venv=0
31never_venv=0
32no_site_packages=0
33force=0
34wrapper=""
Matthew Treinishd15705b2012-10-16 14:04:48 -040035nova_coverage=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010036config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050037update=0
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090038logging=0
39logging_config=etc/logging.conf
Attila Fazekasa63a9992013-02-14 16:44:37 +010040
Matthew Treinish49f40362013-08-27 16:02:53 -040041if ! options=$(getopt -o VNnfuswtcphdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,serial,nova-coverage,pep8,help,debug,config:,logging,logging-config: -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010042then
43 # parse error
44 usage
45 exit 1
46fi
47
48eval set -- $options
49first_uu=yes
50while [ $# -gt 0 ]; do
51 case "$1" in
52 -h|--help) usage; exit;;
53 -V|--virtual-env) always_venv=1; never_venv=0;;
54 -N|--no-virtual-env) always_venv=0; never_venv=1;;
55 -n|--no-site-packages) no_site_packages=1;;
56 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050057 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010058 -d|--debug) set -o xtrace;;
59 -c|--nova-coverage) let nova_coverage=1;;
60 -C|--config) config_file=$2; shift;;
61 -p|--pep8) let just_pep8=1;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040062 -s|--smoke) testrargs="$testrargs smoke";;
63 -w|--whitebox) testrargs="$testrargs whitebox";;
Matthew Treinish49f40362013-08-27 16:02:53 -040064 -t|--serial) serial=1;;
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090065 -l|--logging) logging=1;;
66 -L|--logging-config) logging_config=$2; shift;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040067 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
68 *) testrargs="$testrargs $1"
Attila Fazekasa63a9992013-02-14 16:44:37 +010069 esac
70 shift
71done
72
73if [ -n "$config_file" ]; then
74 config_file=`readlink -f "$config_file"`
75 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
76 export TEMPEST_CONFIG=`basename "$config_file"`
77fi
78
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090079if [ $logging -eq 1 ]; then
80 if [ ! -f "$logging_config" ]; then
81 echo "No such logging config file: $logging_config"
82 exit 1
83 fi
84 logging_config=`readlink -f "$logging_config"`
85 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
86 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
87fi
88
Attila Fazekasa63a9992013-02-14 16:44:37 +010089cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040090
Matthew Treinish8e937d72012-12-14 11:11:41 -050091if [ $no_site_packages -eq 1 ]; then
92 installvenvopts="--no-site-packages"
93fi
Sean Dague422af972012-11-16 07:30:43 -050094
Matthew Treinish87af1bb2013-06-17 15:29:10 -040095function testr_init {
96 if [ ! -d .testrepository ]; then
97 ${wrapper} testr init
98 fi
99}
100
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500101function run_tests {
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400102 testr_init
103 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish49f40362013-08-27 16:02:53 -0400104 if [ $serial -eq 1 ]; then
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400105 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish49f40362013-08-27 16:02:53 -0400106 else
107 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400108 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500109}
110
Matthew Treinishf0e47472013-08-15 16:54:45 -0400111function run_tests_nose {
112 NOSE_WITH_OPENSTACK=1
113 NOSE_OPENSTACK_COLOR=1
114 NOSE_OPENSTACK_RED=15.00
115 NOSE_OPENSTACK_YELLOW=3.00
116 NOSE_OPENSTACK_SHOW_ELAPSED=1
117 NOSE_OPENSTACK_STDOUT=1
118 if [[ "x$noseargs" =~ "tempest" ]]; then
119 noseargs="$testrargs"
120 else
121 noseargs="$noseargs tempest"
122 fi
123 ${wrapper} nosetests $noseargs
124}
125
Jay Pipesf38eaac2012-06-21 13:37:35 -0400126function run_pep8 {
Kui Shib1b7c712013-08-23 06:40:05 +0800127 echo "Running flake8 ..."
128 if [ $never_venv -eq 1 ]; then
129 echo "**WARNING**:" >&2
130 echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2
131 fi
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700132 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400133}
134
Matthew Treinishd15705b2012-10-16 14:04:48 -0400135function run_coverage_start {
136 echo "Starting nova-coverage"
137 ${wrapper} python tools/tempest_coverage.py -c start
138}
139
140function run_coverage_report {
141 echo "Generating nova-coverage report"
142 ${wrapper} python tools/tempest_coverage.py -c report
143}
144
Matthew Treinish8e937d72012-12-14 11:11:41 -0500145if [ $never_venv -eq 0 ]
146then
147 # Remove the virtual environment if --force used
148 if [ $force -eq 1 ]; then
149 echo "Cleaning virtualenv..."
150 rm -rf ${venv}
151 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500152 if [ $update -eq 1 ]; then
153 echo "Updating virtualenv..."
154 python tools/install_venv.py $installvenvopts
155 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500156 if [ -e ${venv} ]; then
157 wrapper="${with_venv}"
158 else
159 if [ $always_venv -eq 1 ]; then
160 # Automatically install the virtualenv
161 python tools/install_venv.py $installvenvopts
162 wrapper="${with_venv}"
163 else
164 echo -e "No virtual environment found...create one? (Y/n) \c"
165 read use_ve
166 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
167 # Install the virtualenv and run the test suite in it
168 python tools/install_venv.py $installvenvopts
169 wrapper=${with_venv}
170 fi
171 fi
172 fi
173fi
174
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500175if [ $just_pep8 -eq 1 ]; then
176 run_pep8
177 exit
178fi
179
Matthew Treinishd15705b2012-10-16 14:04:48 -0400180if [ $nova_coverage -eq 1 ]; then
181 run_coverage_start
182fi
183
Matthew Treinishf0e47472013-08-15 16:54:45 -0400184
185py_version=`${wrapper} python --version 2>&1`
186if [[ $py_version =~ "2.6" ]] ; then
187 run_tests_nose
188else
189 run_tests
190fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200191retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400192
193if [ $nova_coverage -eq 1 ]; then
194 run_coverage_report
195fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400196
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400197if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200198 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400199fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200200
201exit $retval