blob: f50b695c9310253faa358e5d56fb4de7597e0fcd [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"
Jay Pipesf38eaac2012-06-21 13:37:35 -040013 echo " -p, --pep8 Just run pep8"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050014 echo " -h, --help Print this usage message"
Sean Dague14a60152012-12-13 15:59:40 -050015 echo " -d, --debug Debug this script -- set -o xtrace"
16 echo " -S, --stdout Don't capture stdout"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050017 exit
18}
19
20function process_option {
21 case "$1" in
22 -h|--help) usage;;
Matthew Treinish8e937d72012-12-14 11:11:41 -050023 -V|--virtual-env) always_venv=1; never_venv=0;;
24 -N|--no-virtual-env) always_venv=0; never_venv=1;;
25 -s|--no-site-packages) no_site_packages=1;;
26 -f|--force) force=1;;
Jay Pipesf38eaac2012-06-21 13:37:35 -040027 -d|--debug) set -o xtrace;;
28 -p|--pep8) let just_pep8=1;;
29 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
Jay Pipes051075a2012-04-28 17:39:37 -040030 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
Sean Dague14a60152012-12-13 15:59:40 -050031 -S|--stdout) noseargs="$noseargs -s";;
Jay Pipesf38eaac2012-06-21 13:37:35 -040032 *) noseargs="$noseargs $1"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050033 esac
34}
35
Sean Dague422af972012-11-16 07:30:43 -050036noseargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040037just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050038venv=.venv
39with_venv=tools/with_venv.sh
40always_venv=0
41never_venv=0
42no_site_packages=0
43force=0
44wrapper=""
45
Jay Pipesf38eaac2012-06-21 13:37:35 -040046
47export NOSE_WITH_OPENSTACK=1
48export NOSE_OPENSTACK_COLOR=1
49export NOSE_OPENSTACK_RED=15.00
50export NOSE_OPENSTACK_YELLOW=3.00
51export NOSE_OPENSTACK_SHOW_ELAPSED=1
52export NOSE_OPENSTACK_STDOUT=1
53
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050054for arg in "$@"; do
55 process_option $arg
56done
57
Matthew Treinish8e937d72012-12-14 11:11:41 -050058if [ $no_site_packages -eq 1 ]; then
59 installvenvopts="--no-site-packages"
60fi
Sean Dague422af972012-11-16 07:30:43 -050061
62# only add tempest default if we don't specify a test
63if [[ "x$noseargs" =~ "tempest" ]]; then
64 noseargs="$noseargs"
65else
66 noseargs="$noseargs tempest"
67fi
68
69
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050070function run_tests {
Matthew Treinish8e937d72012-12-14 11:11:41 -050071 ${wrapper} $NOSETESTS
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050072}
73
Jay Pipesf38eaac2012-06-21 13:37:35 -040074function run_pep8 {
75 echo "Running pep8 ..."
Matthew Treinish8b372892012-12-07 17:13:16 -050076 srcfiles="`find tempest -type f -name "*.py"`"
77 srcfiles+=" `find tools -type f -name "*.py"`"
78 srcfiles+=" setup.py"
79
Sean Dagued18cfe52013-01-04 14:53:00 -050080 ignore='--ignore=T401,T402,E121,E122,E125,E126'
Sean Dague14a60152012-12-13 15:59:40 -050081
Sean Dague97449cc2013-01-04 14:38:26 -050082 ${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
Jay Pipesf38eaac2012-06-21 13:37:35 -040083}
84
85NOSETESTS="nosetests $noseargs"
86
Matthew Treinish8e937d72012-12-14 11:11:41 -050087if [ $never_venv -eq 0 ]
88then
89 # Remove the virtual environment if --force used
90 if [ $force -eq 1 ]; then
91 echo "Cleaning virtualenv..."
92 rm -rf ${venv}
93 fi
94 if [ -e ${venv} ]; then
95 wrapper="${with_venv}"
96 else
97 if [ $always_venv -eq 1 ]; then
98 # Automatically install the virtualenv
99 python tools/install_venv.py $installvenvopts
100 wrapper="${with_venv}"
101 else
102 echo -e "No virtual environment found...create one? (Y/n) \c"
103 read use_ve
104 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
105 # Install the virtualenv and run the test suite in it
106 python tools/install_venv.py $installvenvopts
107 wrapper=${with_venv}
108 fi
109 fi
110 fi
111fi
112
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500113if [ $just_pep8 -eq 1 ]; then
114 run_pep8
115 exit
116fi
117
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500118run_tests || exit
Jay Pipesf38eaac2012-06-21 13:37:35 -0400119
120if [ -z "$noseargs" ]; then
121 run_pep8
122fi