blob: af33f7cccf96e36333281733eec52a5c4ec60fad [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"
Jay Pipesf38eaac2012-06-21 13:37:35 -040015 echo " -d. --debug Debug this script -- set -o xtrace"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050016 exit
17}
18
19function process_option {
20 case "$1" in
21 -h|--help) usage;;
Matthew Treinish8e937d72012-12-14 11:11:41 -050022 -V|--virtual-env) always_venv=1; never_venv=0;;
23 -N|--no-virtual-env) always_venv=0; never_venv=1;;
24 -s|--no-site-packages) no_site_packages=1;;
25 -f|--force) force=1;;
Jay Pipesf38eaac2012-06-21 13:37:35 -040026 -d|--debug) set -o xtrace;;
27 -p|--pep8) let just_pep8=1;;
28 -s|--smoke) noseargs="$noseargs --attr=type=smoke";;
Jay Pipes051075a2012-04-28 17:39:37 -040029 -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";;
Jay Pipesf38eaac2012-06-21 13:37:35 -040030 *) noseargs="$noseargs $1"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050031 esac
32}
33
Sean Dague422af972012-11-16 07:30:43 -050034noseargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040035just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050036venv=.venv
37with_venv=tools/with_venv.sh
38always_venv=0
39never_venv=0
40no_site_packages=0
41force=0
42wrapper=""
43
Jay Pipesf38eaac2012-06-21 13:37:35 -040044
45export NOSE_WITH_OPENSTACK=1
46export NOSE_OPENSTACK_COLOR=1
47export NOSE_OPENSTACK_RED=15.00
48export NOSE_OPENSTACK_YELLOW=3.00
49export NOSE_OPENSTACK_SHOW_ELAPSED=1
50export NOSE_OPENSTACK_STDOUT=1
51
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050052for arg in "$@"; do
53 process_option $arg
54done
55
Matthew Treinish8e937d72012-12-14 11:11:41 -050056if [ $no_site_packages -eq 1 ]; then
57 installvenvopts="--no-site-packages"
58fi
Sean Dague422af972012-11-16 07:30:43 -050059
60# only add tempest default if we don't specify a test
61if [[ "x$noseargs" =~ "tempest" ]]; then
62 noseargs="$noseargs"
63else
64 noseargs="$noseargs tempest"
65fi
66
67
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050068function run_tests {
Matthew Treinish8e937d72012-12-14 11:11:41 -050069 ${wrapper} $NOSETESTS
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050070}
71
Jay Pipesf38eaac2012-06-21 13:37:35 -040072function run_pep8 {
73 echo "Running pep8 ..."
Matthew Treinish8b372892012-12-07 17:13:16 -050074 srcfiles="`find tempest -type f -name "*.py"`"
75 srcfiles+=" `find tools -type f -name "*.py"`"
76 srcfiles+=" setup.py"
77
78 ignore='--ignore=N4,E121,E122,E125,E126'
79
Matthew Treinish8e937d72012-12-14 11:11:41 -050080 ${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
Jay Pipesf38eaac2012-06-21 13:37:35 -040081}
82
83NOSETESTS="nosetests $noseargs"
84
85if [ $just_pep8 -eq 1 ]; then
86 run_pep8
87 exit
88fi
89
Matthew Treinish8e937d72012-12-14 11:11:41 -050090if [ $never_venv -eq 0 ]
91then
92 # Remove the virtual environment if --force used
93 if [ $force -eq 1 ]; then
94 echo "Cleaning virtualenv..."
95 rm -rf ${venv}
96 fi
97 if [ -e ${venv} ]; then
98 wrapper="${with_venv}"
99 else
100 if [ $always_venv -eq 1 ]; then
101 # Automatically install the virtualenv
102 python tools/install_venv.py $installvenvopts
103 wrapper="${with_venv}"
104 else
105 echo -e "No virtual environment found...create one? (Y/n) \c"
106 read use_ve
107 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
108 # Install the virtualenv and run the test suite in it
109 python tools/install_venv.py $installvenvopts
110 wrapper=${with_venv}
111 fi
112 fi
113 fi
114fi
115
Justin Shepherd0d9bbd12011-08-11 12:57:44 -0500116run_tests || exit
Jay Pipesf38eaac2012-06-21 13:37:35 -0400117
118if [ -z "$noseargs" ]; then
119 run_pep8
120fi