blob: 5a9b7425ddeb09f0f9799d3e5b0d568057e3e211 [file] [log] [blame]
Matthew Treinish61f7d5e2014-01-05 13:13:39 -05001#!/usr/bin/env bash
2
3function usage {
4 echo "Usage: $0 [OPTION]..."
5 echo "Run Tempest test suite"
6 echo ""
7 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"
9 echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
10 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
11 echo " -u, --update Update the virtual environment with any newer package versions"
12 echo " -s, --smoke Only run smoke tests"
13 echo " -t, --serial Run testr serially"
14 echo " -C, --config Config file location"
15 echo " -h, --help Print this usage message"
Matthew Treinish1b1eb642014-01-21 19:38:47 +000016 echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB"
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050017 echo " -l, --logging Enable logging"
18 echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
19 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
20}
21
22testrargs=""
23venv=.venv
24with_venv=tools/with_venv.sh
25serial=0
26always_venv=0
27never_venv=0
28no_site_packages=0
Matthew Treinish1b1eb642014-01-21 19:38:47 +000029debug=0
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050030force=0
31wrapper=""
32config_file=""
33update=0
34logging=0
35logging_config=etc/logging.conf
36
37if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config:,logging,logging-config: -- "$@")
38then
39 # parse error
40 usage
41 exit 1
42fi
43
44eval set -- $options
45first_uu=yes
46while [ $# -gt 0 ]; do
47 case "$1" in
48 -h|--help) usage; exit;;
49 -V|--virtual-env) always_venv=1; never_venv=0;;
50 -N|--no-virtual-env) always_venv=0; never_venv=1;;
51 -n|--no-site-packages) no_site_packages=1;;
52 -f|--force) force=1;;
53 -u|--update) update=1;;
Matthew Treinish1b1eb642014-01-21 19:38:47 +000054 -d|--debug) debug=1;;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050055 -C|--config) config_file=$2; shift;;
Matthew Treinisha74f5d42014-02-07 20:25:44 -050056 -s|--smoke) testrargs+="smoke";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050057 -t|--serial) serial=1;;
58 -l|--logging) logging=1;;
59 -L|--logging-config) logging_config=$2; shift;;
60 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Ryan Bak86607982014-06-01 12:26:35 -060061 *) testrargs="$testrargs $1";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050062 esac
63 shift
64done
65
66if [ -n "$config_file" ]; then
67 config_file=`readlink -f "$config_file"`
68 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
69 export TEMPEST_CONFIG=`basename "$config_file"`
70fi
71
72if [ $logging -eq 1 ]; then
73 if [ ! -f "$logging_config" ]; then
74 echo "No such logging config file: $logging_config"
75 exit 1
76 fi
77 logging_config=`readlink -f "$logging_config"`
78 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
79 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
80fi
81
82cd `dirname "$0"`
83
84if [ $no_site_packages -eq 1 ]; then
85 installvenvopts="--no-site-packages"
86fi
87
88function testr_init {
89 if [ ! -d .testrepository ]; then
90 ${wrapper} testr init
91 fi
92}
93
94function run_tests {
95 testr_init
96 ${wrapper} find . -type f -name "*.pyc" -delete
97 export OS_TEST_PATH=./tempest/test_discover
Matthew Treinish1b1eb642014-01-21 19:38:47 +000098 if [ $debug -eq 1 ]; then
99 if [ "$testrargs" = "" ]; then
100 testrargs="discover ./tempest/test_discover"
101 fi
102 ${wrapper} python -m testtools.run $testrargs
103 return $?
104 fi
105
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500106 if [ $serial -eq 1 ]; then
107 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
108 else
109 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
110 fi
111}
112
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500113if [ $never_venv -eq 0 ]
114then
115 # Remove the virtual environment if --force used
116 if [ $force -eq 1 ]; then
117 echo "Cleaning virtualenv..."
118 rm -rf ${venv}
119 fi
120 if [ $update -eq 1 ]; then
121 echo "Updating virtualenv..."
122 python tools/install_venv.py $installvenvopts
123 fi
124 if [ -e ${venv} ]; then
125 wrapper="${with_venv}"
126 else
127 if [ $always_venv -eq 1 ]; then
128 # Automatically install the virtualenv
129 python tools/install_venv.py $installvenvopts
130 wrapper="${with_venv}"
131 else
132 echo -e "No virtual environment found...create one? (Y/n) \c"
133 read use_ve
134 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
135 # Install the virtualenv and run the test suite in it
136 python tools/install_venv.py $installvenvopts
137 wrapper=${with_venv}
138 fi
139 fi
140 fi
141fi
142
Matthew Treinisha74f5d42014-02-07 20:25:44 -0500143run_tests
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500144retval=$?
145
146exit $retval