blob: 461ec2f77649c9b27b95433fba11f5beb0e701ef [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"
9 echo " -s, --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."
Jay Pipesf38eaac2012-06-21 13:37:35 -040011 echo " -s, --smoke Only run smoke tests"
Jay Pipes051075a2012-04-28 17:39:37 -040012 echo " -w, --whitebox Only run whitebox tests"
Matthew Treinishd15705b2012-10-16 14:04:48 -040013 echo " -c, --nova-coverage Enable Nova coverage collection"
Jay Pipesf38eaac2012-06-21 13:37:35 -040014 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050015 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050016 echo " -d, --debug Debug this script -- set -o xtrace"
17 echo " -S, --stdout Don't capture stdout"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050018 exit
19}
20
21function process_option {
22 case "$1" in
23 -h|--help) usage;;
Matthew Treinish8e937d72012-12-14 11:11:41 -050024 -V|--virtual-env) always_venv=1; never_venv=0;;
25 -N|--no-virtual-env) always_venv=0; never_venv=1;;
26 -s|--no-site-packages) no_site_packages=1;;
27 -f|--force) force=1;;
Jay Pipesf38eaac2012-06-21 13:37:35 -040028 -d|--debug) set -o xtrace;;
Matthew Treinishd15705b2012-10-16 14:04:48 -040029 -c|--nova-coverage) let nova_coverage=1;;
Jay Pipesf38eaac2012-06-21 13:37:35 -040030 -p|--pep8) let just_pep8=1;;
31 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
Jay Pipes051075a2012-04-28 17:39:37 -040032 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
Sean Dague14a60152012-12-13 15:59:40 -050033 -S|--stdout) noseargs="$noseargs -s";;
Jay Pipesf38eaac2012-06-21 13:37:35 -040034 *) noseargs="$noseargs $1"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050035 esac
36}
37
Sean Dague422af972012-11-16 07:30:43 -050038noseargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040039just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050040venv=.venv
41with_venv=tools/with_venv.sh
42always_venv=0
43never_venv=0
44no_site_packages=0
45force=0
46wrapper=""
Matthew Treinishd15705b2012-10-16 14:04:48 -040047nova_coverage=0
Jay Pipesf38eaac2012-06-21 13:37:35 -040048
49export NOSE_WITH_OPENSTACK=1
50export NOSE_OPENSTACK_COLOR=1
51export NOSE_OPENSTACK_RED=15.00
52export NOSE_OPENSTACK_YELLOW=3.00
53export NOSE_OPENSTACK_SHOW_ELAPSED=1
54export NOSE_OPENSTACK_STDOUT=1
55
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050056for arg in "$@"; do
57 process_option $arg
58done
59
Matthew Treinish8e937d72012-12-14 11:11:41 -050060if [ $no_site_packages -eq 1 ]; then
61 installvenvopts="--no-site-packages"
62fi
Sean Dague422af972012-11-16 07:30:43 -050063
64# only add tempest default if we don't specify a test
65if [[ "x$noseargs" =~ "tempest" ]]; then
66 noseargs="$noseargs"
67else
68 noseargs="$noseargs tempest"
69fi
70
71
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050072function run_tests {
Matthew Treinish8e937d72012-12-14 11:11:41 -050073 ${wrapper} $NOSETESTS
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050074}
75
Jay Pipesf38eaac2012-06-21 13:37:35 -040076function run_pep8 {
77 echo "Running pep8 ..."
Matthew Treinish8b372892012-12-07 17:13:16 -050078 srcfiles="`find tempest -type f -name "*.py"`"
79 srcfiles+=" `find tools -type f -name "*.py"`"
80 srcfiles+=" setup.py"
81
82 ignore='--ignore=N4,E121,E122,E125,E126'
Sean Dague14a60152012-12-13 15:59:40 -050083
Matthew Treinish8e937d72012-12-14 11:11:41 -050084 ${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
Jay Pipesf38eaac2012-06-21 13:37:35 -040085}
86
Matthew Treinishd15705b2012-10-16 14:04:48 -040087function run_coverage_start {
88 echo "Starting nova-coverage"
89 ${wrapper} python tools/tempest_coverage.py -c start
90}
91
92function run_coverage_report {
93 echo "Generating nova-coverage report"
94 ${wrapper} python tools/tempest_coverage.py -c report
95}
96
Jay Pipesf38eaac2012-06-21 13:37:35 -040097NOSETESTS="nosetests $noseargs"
98
Matthew Treinish8e937d72012-12-14 11:11:41 -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 [ -e ${venv} ]; then
107 wrapper="${with_venv}"
108 else
109 if [ $always_venv -eq 1 ]; then
110 # Automatically install the virtualenv
111 python tools/install_venv.py $installvenvopts
112 wrapper="${with_venv}"
113 else
114 echo -e "No virtual environment found...create one? (Y/n) \c"
115 read use_ve
116 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
117 # Install the virtualenv and run the test suite in it
118 python tools/install_venv.py $installvenvopts
119 wrapper=${with_venv}
120 fi
121 fi
122 fi
123fi
124
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500125if [ $just_pep8 -eq 1 ]; then
126 run_pep8
127 exit
128fi
129
Matthew Treinishd15705b2012-10-16 14:04:48 -0400130if [ $nova_coverage -eq 1 ]; then
131 run_coverage_start
132fi
133
134run_tests
135
136if [ $nova_coverage -eq 1 ]; then
137 run_coverage_report
138fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400139
140if [ -z "$noseargs" ]; then
141 run_pep8
142fi