blob: 414146be206cf40d3a328f7bcb2f3eadb5b70b57 [file] [log] [blame]
Matthew Treinish61f7d5e2014-01-05 13:13:39 -05001#!/usr/bin/env bash
2
Matthew Treinish68c78712016-07-28 14:47:27 -04003echo "WARNING: This script is deprecated and will be removed in the near future. Please migrate to tempest run or another method of launching a test runner"
4
Matthew Treinish61f7d5e2014-01-05 13:13:39 -05005function usage {
6 echo "Usage: $0 [OPTION]..."
7 echo "Run Tempest test suite"
8 echo ""
9 echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
10 echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
11 echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
12 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
13 echo " -u, --update Update the virtual environment with any newer package versions"
14 echo " -s, --smoke Only run smoke tests"
15 echo " -t, --serial Run testr serially"
16 echo " -C, --config Config file location"
17 echo " -h, --help Print this usage message"
Matthew Treinish1b1eb642014-01-21 19:38:47 +000018 echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB"
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050019 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
20}
21
22testrargs=""
ghanshyamf5360ff2015-06-29 13:32:01 +090023venv=${VENV:-.venv}
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050024with_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
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050034
Marc Kodererc81c7672015-12-17 12:10:12 +010035if ! 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 -050036then
37 # parse error
38 usage
39 exit 1
40fi
41
42eval set -- $options
43first_uu=yes
44while [ $# -gt 0 ]; do
45 case "$1" in
46 -h|--help) usage; exit;;
47 -V|--virtual-env) always_venv=1; never_venv=0;;
48 -N|--no-virtual-env) always_venv=0; never_venv=1;;
49 -n|--no-site-packages) no_site_packages=1;;
50 -f|--force) force=1;;
51 -u|--update) update=1;;
Matthew Treinish1b1eb642014-01-21 19:38:47 +000052 -d|--debug) debug=1;;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050053 -C|--config) config_file=$2; shift;;
Matthew Treinisha74f5d42014-02-07 20:25:44 -050054 -s|--smoke) testrargs+="smoke";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050055 -t|--serial) serial=1;;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050056 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Ryan Bak86607982014-06-01 12:26:35 -060057 *) testrargs="$testrargs $1";;
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050058 esac
59 shift
60done
61
62if [ -n "$config_file" ]; then
63 config_file=`readlink -f "$config_file"`
64 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
65 export TEMPEST_CONFIG=`basename "$config_file"`
66fi
67
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050068cd `dirname "$0"`
69
70if [ $no_site_packages -eq 1 ]; then
71 installvenvopts="--no-site-packages"
72fi
73
74function testr_init {
75 if [ ! -d .testrepository ]; then
76 ${wrapper} testr init
77 fi
78}
79
80function run_tests {
81 testr_init
82 ${wrapper} find . -type f -name "*.pyc" -delete
83 export OS_TEST_PATH=./tempest/test_discover
Matthew Treinish1b1eb642014-01-21 19:38:47 +000084 if [ $debug -eq 1 ]; then
85 if [ "$testrargs" = "" ]; then
86 testrargs="discover ./tempest/test_discover"
87 fi
88 ${wrapper} python -m testtools.run $testrargs
89 return $?
90 fi
91
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050092 if [ $serial -eq 1 ]; then
Matthew Treinish38984742015-03-11 16:01:47 -040093 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-trace -n -f
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050094 else
Matthew Treinish38984742015-03-11 16:01:47 -040095 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-trace -n -f
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050096 fi
97}
98
Matthew Treinish61f7d5e2014-01-05 13:13:39 -050099if [ $never_venv -eq 0 ]
100then
101 # Remove the virtual environment if --force used
102 if [ $force -eq 1 ]; then
103 echo "Cleaning virtualenv..."
104 rm -rf ${venv}
105 fi
106 if [ $update -eq 1 ]; then
107 echo "Updating virtualenv..."
Matthew Treinish72e83762016-01-20 20:19:23 -0500108 virtualenv $installvenvopts $venv
109 $venv/bin/pip install -U -r requirements.txt
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500110 fi
111 if [ -e ${venv} ]; then
112 wrapper="${with_venv}"
113 else
114 if [ $always_venv -eq 1 ]; then
115 # Automatically install the virtualenv
Matthew Treinish72e83762016-01-20 20:19:23 -0500116 virtualenv $installvenvopts $venv
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500117 wrapper="${with_venv}"
Matthew Treinish72e83762016-01-20 20:19:23 -0500118 ${wrapper} pip install -U -r requirements.txt
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500119 else
120 echo -e "No virtual environment found...create one? (Y/n) \c"
121 read use_ve
122 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
123 # Install the virtualenv and run the test suite in it
Matthew Treinish72e83762016-01-20 20:19:23 -0500124 virtualenv $installvenvopts $venv
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500125 wrapper=${with_venv}
Matthew Treinish72e83762016-01-20 20:19:23 -0500126 ${wrapper} pip install -U -r requirements.txt
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500127 fi
128 fi
129 fi
130fi
131
Matthew Treinisha74f5d42014-02-07 20:25:44 -0500132run_tests
Matthew Treinish61f7d5e2014-01-05 13:13:39 -0500133retval=$?
134
135exit $retval