blob: a645b2293175de1fe4a1a74a7fb249a4a4fc656d [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 Treinish87af1bb2013-06-17 15:29:10 -040014 echo " -t, --with-testr Run using testr instead of nose"
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"
20 echo " -S, --stdout Don't capture stdout"
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090021 echo " -l, --logging Enable logging"
22 echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
Attila Fazekasa63a9992013-02-14 16:44:37 +010023 echo " -- [NOSEOPTIONS] After the first '--' you can pass arbitrary arguments to nosetests "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050024}
25
Sean Dague422af972012-11-16 07:30:43 -050026noseargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040027just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050028venv=.venv
29with_venv=tools/with_venv.sh
Matthew Treinish87af1bb2013-06-17 15:29:10 -040030with_testr=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050031always_venv=0
32never_venv=0
33no_site_packages=0
34force=0
35wrapper=""
Matthew Treinishd15705b2012-10-16 14:04:48 -040036nova_coverage=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010037config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050038update=0
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090039logging=0
40logging_config=etc/logging.conf
Attila Fazekasa63a9992013-02-14 16:44:37 +010041
Matthew Treinish87af1bb2013-06-17 15:29:10 -040042if ! options=$(getopt -o VNnfuswtcphdSC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,with-testr,nova-coverage,pep8,help,debug,stdout,config:,logging,logging-config: -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010043then
44 # parse error
45 usage
46 exit 1
47fi
48
49eval set -- $options
50first_uu=yes
51while [ $# -gt 0 ]; do
52 case "$1" in
53 -h|--help) usage; exit;;
54 -V|--virtual-env) always_venv=1; never_venv=0;;
55 -N|--no-virtual-env) always_venv=0; never_venv=1;;
56 -n|--no-site-packages) no_site_packages=1;;
57 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050058 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010059 -d|--debug) set -o xtrace;;
60 -c|--nova-coverage) let nova_coverage=1;;
61 -C|--config) config_file=$2; shift;;
62 -p|--pep8) let just_pep8=1;;
63 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
64 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
Matthew Treinish87af1bb2013-06-17 15:29:10 -040065 -t|--with-testr) with_testr=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010066 -S|--stdout) noseargs="$noseargs -s";;
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090067 -l|--logging) logging=1;;
68 -L|--logging-config) logging_config=$2; shift;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010069 --) [ "yes" == "$first_uu" ] || noseargs="$noseargs $1"; first_uu=no ;;
70 *) noseargs="$noseargs $1"
71 esac
72 shift
73done
74
75if [ -n "$config_file" ]; then
76 config_file=`readlink -f "$config_file"`
77 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
78 export TEMPEST_CONFIG=`basename "$config_file"`
79fi
80
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090081if [ $logging -eq 1 ]; then
82 if [ ! -f "$logging_config" ]; then
83 echo "No such logging config file: $logging_config"
84 exit 1
85 fi
86 logging_config=`readlink -f "$logging_config"`
87 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
88 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
89fi
90
Attila Fazekasa63a9992013-02-14 16:44:37 +010091cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040092
93export NOSE_WITH_OPENSTACK=1
94export NOSE_OPENSTACK_COLOR=1
95export NOSE_OPENSTACK_RED=15.00
96export NOSE_OPENSTACK_YELLOW=3.00
97export NOSE_OPENSTACK_SHOW_ELAPSED=1
98export NOSE_OPENSTACK_STDOUT=1
99
Matthew Treinish8e937d72012-12-14 11:11:41 -0500100if [ $no_site_packages -eq 1 ]; then
101 installvenvopts="--no-site-packages"
102fi
Sean Dague422af972012-11-16 07:30:43 -0500103
104# only add tempest default if we don't specify a test
105if [[ "x$noseargs" =~ "tempest" ]]; then
106 noseargs="$noseargs"
107else
108 noseargs="$noseargs tempest"
109fi
110
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400111function testr_init {
112 if [ ! -d .testrepository ]; then
113 ${wrapper} testr init
114 fi
115}
116
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500117function run_tests {
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400118 if [ $with_testr -eq 1 ]; then
119 testr_init
120 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish0e2d8aa2013-07-18 15:16:37 -0400121 ${wrapper} testr run --parallel --subunit $noseargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400122 else
123 ${wrapper} $NOSETESTS
124 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500125}
126
Jay Pipesf38eaac2012-06-21 13:37:35 -0400127function run_pep8 {
128 echo "Running pep8 ..."
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700129 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400130}
131
Matthew Treinishd15705b2012-10-16 14:04:48 -0400132function run_coverage_start {
133 echo "Starting nova-coverage"
134 ${wrapper} python tools/tempest_coverage.py -c start
135}
136
137function run_coverage_report {
138 echo "Generating nova-coverage report"
139 ${wrapper} python tools/tempest_coverage.py -c report
140}
141
Jay Pipesf38eaac2012-06-21 13:37:35 -0400142NOSETESTS="nosetests $noseargs"
143
Matthew Treinish8e937d72012-12-14 11:11:41 -0500144if [ $never_venv -eq 0 ]
145then
146 # Remove the virtual environment if --force used
147 if [ $force -eq 1 ]; then
148 echo "Cleaning virtualenv..."
149 rm -rf ${venv}
150 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500151 if [ $update -eq 1 ]; then
152 echo "Updating virtualenv..."
153 python tools/install_venv.py $installvenvopts
154 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500155 if [ -e ${venv} ]; then
156 wrapper="${with_venv}"
157 else
158 if [ $always_venv -eq 1 ]; then
159 # Automatically install the virtualenv
160 python tools/install_venv.py $installvenvopts
161 wrapper="${with_venv}"
162 else
163 echo -e "No virtual environment found...create one? (Y/n) \c"
164 read use_ve
165 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
166 # Install the virtualenv and run the test suite in it
167 python tools/install_venv.py $installvenvopts
168 wrapper=${with_venv}
169 fi
170 fi
171 fi
172fi
173
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500174if [ $just_pep8 -eq 1 ]; then
175 run_pep8
176 exit
177fi
178
Matthew Treinishd15705b2012-10-16 14:04:48 -0400179if [ $nova_coverage -eq 1 ]; then
180 run_coverage_start
181fi
182
183run_tests
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200184retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400185
186if [ $nova_coverage -eq 1 ]; then
187 run_coverage_report
188fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400189
190if [ -z "$noseargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200191 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400192fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200193
194exit $retval