blob: f995cde4767f5cbc9caf6313e4cf7fcf8b38ec27 [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 Treinish59eb0b22013-08-07 15:48:21 -040014 echo " -t, --parallel Run testr parallel"
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 Treinish59eb0b22013-08-07 15:48:21 -040029parallel=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 Treinish59eb0b22013-08-07 15:48:21 -040041if ! options=$(getopt -o VNnfuswtcphdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,parallel,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";;
64 -t|--parallel) parallel=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
104 if [ $parallel -eq 1 ]; then
105 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400106 else
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400107 ${wrapper} testr run --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 {
127 echo "Running pep8 ..."
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700128 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400129}
130
Matthew Treinishd15705b2012-10-16 14:04:48 -0400131function run_coverage_start {
132 echo "Starting nova-coverage"
133 ${wrapper} python tools/tempest_coverage.py -c start
134}
135
136function run_coverage_report {
137 echo "Generating nova-coverage report"
138 ${wrapper} python tools/tempest_coverage.py -c report
139}
140
Matthew Treinish8e937d72012-12-14 11:11:41 -0500141if [ $never_venv -eq 0 ]
142then
143 # Remove the virtual environment if --force used
144 if [ $force -eq 1 ]; then
145 echo "Cleaning virtualenv..."
146 rm -rf ${venv}
147 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500148 if [ $update -eq 1 ]; then
149 echo "Updating virtualenv..."
150 python tools/install_venv.py $installvenvopts
151 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500152 if [ -e ${venv} ]; then
153 wrapper="${with_venv}"
154 else
155 if [ $always_venv -eq 1 ]; then
156 # Automatically install the virtualenv
157 python tools/install_venv.py $installvenvopts
158 wrapper="${with_venv}"
159 else
160 echo -e "No virtual environment found...create one? (Y/n) \c"
161 read use_ve
162 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
163 # Install the virtualenv and run the test suite in it
164 python tools/install_venv.py $installvenvopts
165 wrapper=${with_venv}
166 fi
167 fi
168 fi
169fi
170
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500171if [ $just_pep8 -eq 1 ]; then
172 run_pep8
173 exit
174fi
175
Matthew Treinishd15705b2012-10-16 14:04:48 -0400176if [ $nova_coverage -eq 1 ]; then
177 run_coverage_start
178fi
179
Matthew Treinishf0e47472013-08-15 16:54:45 -0400180
181py_version=`${wrapper} python --version 2>&1`
182if [[ $py_version =~ "2.6" ]] ; then
183 run_tests_nose
184else
185 run_tests
186fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200187retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400188
189if [ $nova_coverage -eq 1 ]; then
190 run_coverage_report
191fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400192
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400193if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200194 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400195fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200196
197exit $retval