blob: be9b38a76fdd9d0cd1f50c43c7634fc5d5e3a0f2 [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"
16 echo " -d, --debug Debug this script -- set -o xtrace"
17 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
29force=0
30wrapper=""
31config_file=""
32update=0
33logging=0
34logging_config=etc/logging.conf
35
36if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config:,logging,logging-config: -- "$@")
37then
38 # parse error
39 usage
40 exit 1
41fi
42
43eval set -- $options
44first_uu=yes
45while [ $# -gt 0 ]; do
46 case "$1" in
47 -h|--help) usage; exit;;
48 -V|--virtual-env) always_venv=1; never_venv=0;;
49 -N|--no-virtual-env) always_venv=0; never_venv=1;;
50 -n|--no-site-packages) no_site_packages=1;;
51 -f|--force) force=1;;
52 -u|--update) update=1;;
53 -d|--debug) set -o xtrace;;
54 -C|--config) config_file=$2; shift;;
55 -s|--smoke) testrargs+="smoke"; noseargs+="--attr=type=smoke";;
56 -t|--serial) serial=1;;
57 -l|--logging) logging=1;;
58 -L|--logging-config) logging_config=$2; shift;;
59 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
60 *) testrargs="$testrargs $1"; noseargs+=" $1" ;;
61 esac
62 shift
63done
64
65if [ -n "$config_file" ]; then
66 config_file=`readlink -f "$config_file"`
67 export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
68 export TEMPEST_CONFIG=`basename "$config_file"`
69fi
70
71if [ $logging -eq 1 ]; then
72 if [ ! -f "$logging_config" ]; then
73 echo "No such logging config file: $logging_config"
74 exit 1
75 fi
76 logging_config=`readlink -f "$logging_config"`
77 export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
78 export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
79fi
80
81cd `dirname "$0"`
82
83if [ $no_site_packages -eq 1 ]; then
84 installvenvopts="--no-site-packages"
85fi
86
87function testr_init {
88 if [ ! -d .testrepository ]; then
89 ${wrapper} testr init
90 fi
91}
92
93function run_tests {
94 testr_init
95 ${wrapper} find . -type f -name "*.pyc" -delete
96 export OS_TEST_PATH=./tempest/test_discover
97 if [ $serial -eq 1 ]; then
98 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
99 else
100 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
101 fi
102}
103
104function run_tests_nose {
105 export NOSE_WITH_OPENSTACK=1
106 export NOSE_OPENSTACK_COLOR=1
107 export NOSE_OPENSTACK_RED=15.00
108 export NOSE_OPENSTACK_YELLOW=3.00
109 export NOSE_OPENSTACK_SHOW_ELAPSED=1
110 export NOSE_OPENSTACK_STDOUT=1
111 export TEMPEST_PY26_NOSE_COMPAT=1
112 if [[ "x$noseargs" =~ "tempest" ]]; then
113 noseargs="$testrargs"
114 else
115 noseargs="$noseargs tempest"
116 fi
117 ${wrapper} nosetests $noseargs
118}
119
120if [ $never_venv -eq 0 ]
121then
122 # Remove the virtual environment if --force used
123 if [ $force -eq 1 ]; then
124 echo "Cleaning virtualenv..."
125 rm -rf ${venv}
126 fi
127 if [ $update -eq 1 ]; then
128 echo "Updating virtualenv..."
129 python tools/install_venv.py $installvenvopts
130 fi
131 if [ -e ${venv} ]; then
132 wrapper="${with_venv}"
133 else
134 if [ $always_venv -eq 1 ]; then
135 # Automatically install the virtualenv
136 python tools/install_venv.py $installvenvopts
137 wrapper="${with_venv}"
138 else
139 echo -e "No virtual environment found...create one? (Y/n) \c"
140 read use_ve
141 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
142 # Install the virtualenv and run the test suite in it
143 python tools/install_venv.py $installvenvopts
144 wrapper=${with_venv}
145 fi
146 fi
147 fi
148fi
149
150py_version=`${wrapper} python --version 2>&1`
151if [[ $py_version =~ "2.6" ]] ; then
152 run_tests_nose
153else
154 run_tests
155fi
156retval=$?
157
158exit $retval