blob: 8c8f25f5ef66d2f5af2143ae8f4e3b161d146a30 [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 " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
18}
19
20testrargs=""
ghanshyamf5360ff2015-06-29 13:32:01 +090021venv=${VENV:-.venv}
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050022with_venv=tools/with_venv.sh
23serial=0
24always_venv=0
25never_venv=0
26no_site_packages=0
Matthew Treinish1b1eb642014-01-21 19:38:47 +000027debug=0
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050028force=0
29wrapper=""
30config_file=""
31update=0
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050032
Marc Kodererc81c7672015-12-17 12:10:12 +010033if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config: -- "$@")
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050034then
35 # parse error
36 usage
37 exit 1
38fi
39
40eval set -- $options
41first_uu=yes
42while [ $# -gt 0 ]; do
43 case "$1" in
44 -h|--help) usage; exit;;
45 -V|--virtual-env) always_venv=1; never_venv=0;;
46 -N|--no-virtual-env) always_venv=0; never_venv=1;;
47 -n|--no-site-packages) no_site_packages=1;;
48 -f|--force) force=1;;
49 -u|--update) update=1;;
Matthew Treinish1b1eb642014-01-21 19:38:47 +000050 -d|--debug) debug=1;;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050051 -C|--config) config_file=$2; shift;;
Matthew Treinisha74f5d42014-02-07 20:25:44 -050052 -s|--smoke) testrargs+="smoke";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050053 -t|--serial) serial=1;;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050054 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Ryan Bak86607982014-06-01 12:26:35 -060055 *) testrargs="$testrargs $1";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050056 esac
57 shift
58done
59
60if [ -n "$config_file" ]; then
61 config_file=`readlink -f "$config_file"`
62 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
63 export TEMPEST_CONFIG=`basename "$config_file"`
64fi
65
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050066cd `dirname "$0"`
67
68if [ $no_site_packages -eq 1 ]; then
69 installvenvopts="--no-site-packages"
70fi
71
72function testr_init {
73 if [ ! -d .testrepository ]; then
74 ${wrapper} testr init
75 fi
76}
77
78function run_tests {
79 testr_init
80 ${wrapper} find . -type f -name "*.pyc" -delete
81 export OS_TEST_PATH=./tempest/test_discover
Matthew Treinish1b1eb642014-01-21 19:38:47 +000082 if [ $debug -eq 1 ]; then
83 if [ "$testrargs" = "" ]; then
84 testrargs="discover ./tempest/test_discover"
85 fi
86 ${wrapper} python -m testtools.run $testrargs
87 return $?
88 fi
89
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050090 if [ $serial -eq 1 ]; then
Matthew Treinish38984742015-03-11 16:01:47 -040091 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-trace -n -f
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050092 else
Matthew Treinish38984742015-03-11 16:01:47 -040093 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-trace -n -f
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050094 fi
95}
96
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050097if [ $never_venv -eq 0 ]
98then
99 # Remove the virtual environment if --force used
100 if [ $force -eq 1 ]; then
101 echo "Cleaning virtualenv..."
102 rm -rf ${venv}
103 fi
104 if [ $update -eq 1 ]; then
105 echo "Updating virtualenv..."
106 python tools/install_venv.py $installvenvopts
107 fi
108 if [ -e ${venv} ]; then
109 wrapper="${with_venv}"
110 else
111 if [ $always_venv -eq 1 ]; then
112 # Automatically install the virtualenv
113 python tools/install_venv.py $installvenvopts
114 wrapper="${with_venv}"
115 else
116 echo -e "No virtual environment found...create one? (Y/n) \c"
117 read use_ve
118 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
119 # Install the virtualenv and run the test suite in it
120 python tools/install_venv.py $installvenvopts
121 wrapper=${with_venv}
122 fi
123 fi
124 fi
125fi
126
Matthew Treinisha74f5d42014-02-07 20:25:44 -0500127run_tests
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500128retval=$?
129
130exit $retval