blob: 3c9c051a9b1d821a8f7f469c36aa442e1db50197 [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"
Matthew Treinish49f40362013-08-27 16:02:53 -040013 echo " -t, --serial Run testr serially"
Attila Fazekasa63a9992013-02-14 16:44:37 +010014 echo " -C, --config Config file location"
Jay Pipesf38eaac2012-06-21 13:37:35 -040015 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050016 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050017 echo " -d, --debug Debug this script -- set -o xtrace"
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090018 echo " -l, --logging Enable logging"
19 echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
Matthew Treinish59eb0b22013-08-07 15:48:21 -040020 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050021}
22
Matthew Treinish59eb0b22013-08-07 15:48:21 -040023testrargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040024just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050025venv=.venv
26with_venv=tools/with_venv.sh
Matthew Treinish49f40362013-08-27 16:02:53 -040027serial=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050028always_venv=0
29never_venv=0
30no_site_packages=0
31force=0
32wrapper=""
Attila Fazekasa63a9992013-02-14 16:44:37 +010033config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050034update=0
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090035logging=0
36logging_config=etc/logging.conf
Attila Fazekasa63a9992013-02-14 16:44:37 +010037
Matthew Treinish96a20bc2013-12-03 11:25:36 -050038if ! options=$(getopt -o VNnfustphdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,pep8,help,debug,config:,logging,logging-config: -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010039then
40 # parse error
41 usage
42 exit 1
43fi
44
45eval set -- $options
46first_uu=yes
47while [ $# -gt 0 ]; do
48 case "$1" in
49 -h|--help) usage; exit;;
50 -V|--virtual-env) always_venv=1; never_venv=0;;
51 -N|--no-virtual-env) always_venv=0; never_venv=1;;
52 -n|--no-site-packages) no_site_packages=1;;
53 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050054 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010055 -d|--debug) set -o xtrace;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010056 -C|--config) config_file=$2; shift;;
57 -p|--pep8) let just_pep8=1;;
Dirk Muellere09001f2013-09-30 15:18:36 +020058 -s|--smoke) testrargs+="smoke"; noseargs+="--attr=type=smoke";;
Matthew Treinish49f40362013-08-27 16:02:53 -040059 -t|--serial) serial=1;;
Mitsuhiko Yamazaki6ffa59c2013-04-11 13:37:07 +090060 -l|--logging) logging=1;;
61 -L|--logging-config) logging_config=$2; shift;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040062 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Sunil Thahaee332b02013-10-10 13:49:19 +100063 *) testrargs="$testrargs $1"; noseargs+=" $1" ;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010064 esac
65 shift
66done
67
68if [ -n "$config_file" ]; then
69 config_file=`readlink -f "$config_file"`
70 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
71 export TEMPEST_CONFIG=`basename "$config_file"`
72fi
73
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090074if [ $logging -eq 1 ]; then
75 if [ ! -f "$logging_config" ]; then
76 echo "No such logging config file: $logging_config"
77 exit 1
78 fi
79 logging_config=`readlink -f "$logging_config"`
80 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
81 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
82fi
83
Attila Fazekasa63a9992013-02-14 16:44:37 +010084cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040085
Matthew Treinish8e937d72012-12-14 11:11:41 -050086if [ $no_site_packages -eq 1 ]; then
87 installvenvopts="--no-site-packages"
88fi
Sean Dague422af972012-11-16 07:30:43 -050089
Matthew Treinish87af1bb2013-06-17 15:29:10 -040090function testr_init {
91 if [ ! -d .testrepository ]; then
92 ${wrapper} testr init
93 fi
94}
95
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050096function run_tests {
Matthew Treinish59eb0b22013-08-07 15:48:21 -040097 testr_init
98 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish49f40362013-08-27 16:02:53 -040099 if [ $serial -eq 1 ]; then
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400100 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish49f40362013-08-27 16:02:53 -0400101 else
102 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -0400103 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500104}
105
Matthew Treinishf0e47472013-08-15 16:54:45 -0400106function run_tests_nose {
Attila Fazekasea88d9f2013-10-03 12:51:44 +0200107 export NOSE_WITH_OPENSTACK=1
108 export NOSE_OPENSTACK_COLOR=1
109 export NOSE_OPENSTACK_RED=15.00
110 export NOSE_OPENSTACK_YELLOW=3.00
111 export NOSE_OPENSTACK_SHOW_ELAPSED=1
112 export NOSE_OPENSTACK_STDOUT=1
113 export TEMPEST_PY26_NOSE_COMPAT=1
Matthew Treinishf0e47472013-08-15 16:54:45 -0400114 if [[ "x$noseargs" =~ "tempest" ]]; then
115 noseargs="$testrargs"
116 else
117 noseargs="$noseargs tempest"
118 fi
119 ${wrapper} nosetests $noseargs
120}
121
Jay Pipesf38eaac2012-06-21 13:37:35 -0400122function run_pep8 {
Kui Shib1b7c712013-08-23 06:40:05 +0800123 echo "Running flake8 ..."
124 if [ $never_venv -eq 1 ]; then
125 echo "**WARNING**:" >&2
126 echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2
127 fi
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700128 ${wrapper} flake8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400129}
130
Matthew Treinish8e937d72012-12-14 11:11:41 -0500131if [ $never_venv -eq 0 ]
132then
133 # Remove the virtual environment if --force used
134 if [ $force -eq 1 ]; then
135 echo "Cleaning virtualenv..."
136 rm -rf ${venv}
137 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500138 if [ $update -eq 1 ]; then
139 echo "Updating virtualenv..."
140 python tools/install_venv.py $installvenvopts
141 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500142 if [ -e ${venv} ]; then
143 wrapper="${with_venv}"
144 else
145 if [ $always_venv -eq 1 ]; then
146 # Automatically install the virtualenv
147 python tools/install_venv.py $installvenvopts
148 wrapper="${with_venv}"
149 else
150 echo -e "No virtual environment found...create one? (Y/n) \c"
151 read use_ve
152 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
153 # Install the virtualenv and run the test suite in it
154 python tools/install_venv.py $installvenvopts
155 wrapper=${with_venv}
156 fi
157 fi
158 fi
159fi
160
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500161if [ $just_pep8 -eq 1 ]; then
162 run_pep8
163 exit
164fi
165
Matthew Treinishf0e47472013-08-15 16:54:45 -0400166py_version=`${wrapper} python --version 2>&1`
167if [[ $py_version =~ "2.6" ]] ; then
168 run_tests_nose
169else
170 run_tests
171fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200172retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400173
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400174if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200175 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400176fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200177
178exit $retval