blob: 366564e6c057f3f027bf26e9828ffcfd2e98df68 [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 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"
19 echo " -S, --stdout Don't capture stdout"
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"
Attila Fazekasa63a9992013-02-14 16:44:37 +010022 echo " -- [NOSEOPTIONS] After the first '--' you can pass arbitrary arguments to nosetests "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050023}
24
Sean Dague422af972012-11-16 07:30:43 -050025noseargs=""
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
29always_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
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090040if ! options=$(getopt -o VNnfuswcphdSC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,nova-coverage,pep8,help,debug,stdout,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;;
61 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
62 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
63 -S|--stdout) noseargs="$noseargs -s";;
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090064 -l|--logging) logging=1;;
65 -L|--logging-config) logging_config=$2; shift;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010066 --) [ "yes" == "$first_uu" ] || noseargs="$noseargs $1"; first_uu=no ;;
67 *) noseargs="$noseargs $1"
68 esac
69 shift
70done
71
72if [ -n "$config_file" ]; then
73 config_file=`readlink -f "$config_file"`
74 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
75 export TEMPEST_CONFIG=`basename "$config_file"`
76fi
77
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090078if [ $logging -eq 1 ]; then
79 if [ ! -f "$logging_config" ]; then
80 echo "No such logging config file: $logging_config"
81 exit 1
82 fi
83 logging_config=`readlink -f "$logging_config"`
84 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
85 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
86fi
87
Attila Fazekasa63a9992013-02-14 16:44:37 +010088cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040089
90export NOSE_WITH_OPENSTACK=1
91export NOSE_OPENSTACK_COLOR=1
92export NOSE_OPENSTACK_RED=15.00
93export NOSE_OPENSTACK_YELLOW=3.00
94export NOSE_OPENSTACK_SHOW_ELAPSED=1
95export NOSE_OPENSTACK_STDOUT=1
96
Matthew Treinish8e937d72012-12-14 11:11:41 -050097if [ $no_site_packages -eq 1 ]; then
98 installvenvopts="--no-site-packages"
99fi
Sean Dague422af972012-11-16 07:30:43 -0500100
101# only add tempest default if we don't specify a test
102if [[ "x$noseargs" =~ "tempest" ]]; then
103 noseargs="$noseargs"
104else
105 noseargs="$noseargs tempest"
106fi
107
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500108function run_tests {
Matthew Treinish8e937d72012-12-14 11:11:41 -0500109 ${wrapper} $NOSETESTS
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500110}
111
Jay Pipesf38eaac2012-06-21 13:37:35 -0400112function run_pep8 {
113 echo "Running pep8 ..."
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700114 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400115}
116
Matthew Treinishd15705b2012-10-16 14:04:48 -0400117function run_coverage_start {
118 echo "Starting nova-coverage"
119 ${wrapper} python tools/tempest_coverage.py -c start
120}
121
122function run_coverage_report {
123 echo "Generating nova-coverage report"
124 ${wrapper} python tools/tempest_coverage.py -c report
125}
126
Jay Pipesf38eaac2012-06-21 13:37:35 -0400127NOSETESTS="nosetests $noseargs"
128
Matthew Treinish8e937d72012-12-14 11:11:41 -0500129if [ $never_venv -eq 0 ]
130then
131 # Remove the virtual environment if --force used
132 if [ $force -eq 1 ]; then
133 echo "Cleaning virtualenv..."
134 rm -rf ${venv}
135 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500136 if [ $update -eq 1 ]; then
137 echo "Updating virtualenv..."
138 python tools/install_venv.py $installvenvopts
139 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500140 if [ -e ${venv} ]; then
141 wrapper="${with_venv}"
142 else
143 if [ $always_venv -eq 1 ]; then
144 # Automatically install the virtualenv
145 python tools/install_venv.py $installvenvopts
146 wrapper="${with_venv}"
147 else
148 echo -e "No virtual environment found...create one? (Y/n) \c"
149 read use_ve
150 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
151 # Install the virtualenv and run the test suite in it
152 python tools/install_venv.py $installvenvopts
153 wrapper=${with_venv}
154 fi
155 fi
156 fi
157fi
158
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500159if [ $just_pep8 -eq 1 ]; then
160 run_pep8
161 exit
162fi
163
Matthew Treinishd15705b2012-10-16 14:04:48 -0400164if [ $nova_coverage -eq 1 ]; then
165 run_coverage_start
166fi
167
168run_tests
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200169retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400170
171if [ $nova_coverage -eq 1 ]; then
172 run_coverage_report
173fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400174
175if [ -z "$noseargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200176 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400177fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200178
179exit $retval