blob: f8636c1224a17a81b2042a2c7d8adaa84d46bb0f [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
Jay Pipesf38eaac2012-06-21 13:37:35 -0400111function run_pep8 {
112 echo "Running pep8 ..."
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700113 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400114}
115
Matthew Treinishd15705b2012-10-16 14:04:48 -0400116function run_coverage_start {
117 echo "Starting nova-coverage"
118 ${wrapper} python tools/tempest_coverage.py -c start
119}
120
121function run_coverage_report {
122 echo "Generating nova-coverage report"
123 ${wrapper} python tools/tempest_coverage.py -c report
124}
125
Matthew Treinish8e937d72012-12-14 11:11:41 -0500126if [ $never_venv -eq 0 ]
127then
128 # Remove the virtual environment if --force used
129 if [ $force -eq 1 ]; then
130 echo "Cleaning virtualenv..."
131 rm -rf ${venv}
132 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500133 if [ $update -eq 1 ]; then
134 echo "Updating virtualenv..."
135 python tools/install_venv.py $installvenvopts
136 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500137 if [ -e ${venv} ]; then
138 wrapper="${with_venv}"
139 else
140 if [ $always_venv -eq 1 ]; then
141 # Automatically install the virtualenv
142 python tools/install_venv.py $installvenvopts
143 wrapper="${with_venv}"
144 else
145 echo -e "No virtual environment found...create one? (Y/n) \c"
146 read use_ve
147 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
148 # Install the virtualenv and run the test suite in it
149 python tools/install_venv.py $installvenvopts
150 wrapper=${with_venv}
151 fi
152 fi
153 fi
154fi
155
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500156if [ $just_pep8 -eq 1 ]; then
157 run_pep8
158 exit
159fi
160
Matthew Treinishd15705b2012-10-16 14:04:48 -0400161if [ $nova_coverage -eq 1 ]; then
162 run_coverage_start
163fi
164
165run_tests
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200166retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400167
168if [ $nova_coverage -eq 1 ]; then
169 run_coverage_report
170fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400171
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400172if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200173 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400174fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200175
176exit $retval