blob: 968f9a359431db82ac62737eacdca7e01d007c35 [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"
Jay Pipes051075a2012-04-28 17:39:37 -040013 echo " -w, --whitebox Only run whitebox tests"
Matthew Treinishd15705b2012-10-16 14:04:48 -040014 echo " -c, --nova-coverage Enable Nova coverage collection"
Attila Fazekasa63a9992013-02-14 16:44:37 +010015 echo " -C, --config Config file location"
Jay Pipesf38eaac2012-06-21 13:37:35 -040016 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050017 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050018 echo " -d, --debug Debug this script -- set -o xtrace"
19 echo " -S, --stdout Don't capture stdout"
Attila Fazekasa63a9992013-02-14 16:44:37 +010020 echo " -- [NOSEOPTIONS] After the first '--' you can pass arbitrary arguments to nosetests "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050021}
22
Sean Dague422af972012-11-16 07:30:43 -050023noseargs=""
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
27always_venv=0
28never_venv=0
29no_site_packages=0
30force=0
31wrapper=""
Matthew Treinishd15705b2012-10-16 14:04:48 -040032nova_coverage=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010033config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050034update=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010035
36if ! options=$(getopt -o VNnfswcphdsC: -l virtual-env,no-virtual-env,no-site-packages,force,smoke,whitebox,nova-coverage,pep8,help,debug,stdout,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;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050052 -u|--update) update=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010053 -d|--debug) set -o xtrace;;
54 -c|--nova-coverage) let nova_coverage=1;;
55 -C|--config) config_file=$2; shift;;
56 -p|--pep8) let just_pep8=1;;
57 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
58 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
59 -S|--stdout) noseargs="$noseargs -s";;
60 --) [ "yes" == "$first_uu" ] || noseargs="$noseargs $1"; first_uu=no ;;
61 *) noseargs="$noseargs $1"
62 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
72cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040073
74export NOSE_WITH_OPENSTACK=1
75export NOSE_OPENSTACK_COLOR=1
76export NOSE_OPENSTACK_RED=15.00
77export NOSE_OPENSTACK_YELLOW=3.00
78export NOSE_OPENSTACK_SHOW_ELAPSED=1
79export NOSE_OPENSTACK_STDOUT=1
80
Matthew Treinish8e937d72012-12-14 11:11:41 -050081if [ $no_site_packages -eq 1 ]; then
82 installvenvopts="--no-site-packages"
83fi
Sean Dague422af972012-11-16 07:30:43 -050084
85# only add tempest default if we don't specify a test
86if [[ "x$noseargs" =~ "tempest" ]]; then
87 noseargs="$noseargs"
88else
89 noseargs="$noseargs tempest"
90fi
91
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050092function run_tests {
Matthew Treinish8e937d72012-12-14 11:11:41 -050093 ${wrapper} $NOSETESTS
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050094}
95
Jay Pipesf38eaac2012-06-21 13:37:35 -040096function run_pep8 {
97 echo "Running pep8 ..."
Matthew Treinish8b372892012-12-07 17:13:16 -050098 srcfiles="`find tempest -type f -name "*.py"`"
99 srcfiles+=" `find tools -type f -name "*.py"`"
Sean Daguef237ccb2013-01-04 15:19:14 -0500100 srcfiles+=" `find stress -type f -name "*.py"`"
Matthew Treinish8b372892012-12-07 17:13:16 -0500101 srcfiles+=" setup.py"
102
Sean Daguef237ccb2013-01-04 15:19:14 -0500103 ignore='--ignore=E121,E122,E125,E126'
Sean Dague14a60152012-12-13 15:59:40 -0500104
Sean Dague97449cc2013-01-04 14:38:26 -0500105 ${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
Jay Pipesf38eaac2012-06-21 13:37:35 -0400106}
107
Matthew Treinishd15705b2012-10-16 14:04:48 -0400108function run_coverage_start {
109 echo "Starting nova-coverage"
110 ${wrapper} python tools/tempest_coverage.py -c start
111}
112
113function run_coverage_report {
114 echo "Generating nova-coverage report"
115 ${wrapper} python tools/tempest_coverage.py -c report
116}
117
Jay Pipesf38eaac2012-06-21 13:37:35 -0400118NOSETESTS="nosetests $noseargs"
119
Matthew Treinish8e937d72012-12-14 11:11:41 -0500120if [ $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
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500127 if [ $update -eq 1 ]; then
128 echo "Updating virtualenv..."
129 python tools/install_venv.py $installvenvopts
130 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500131 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
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500150if [ $just_pep8 -eq 1 ]; then
151 run_pep8
152 exit
153fi
154
Matthew Treinishd15705b2012-10-16 14:04:48 -0400155if [ $nova_coverage -eq 1 ]; then
156 run_coverage_start
157fi
158
159run_tests
160
161if [ $nova_coverage -eq 1 ]; then
162 run_coverage_report
163fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400164
165if [ -z "$noseargs" ]; then
166 run_pep8
167fi