blob: e26c51cb4a738023f8a9bc3e4bdf9126cff3675f [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."
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;;
Andrea Frittoli1cfbc4a2013-01-31 19:44:10 +000026 -n|--no-site-packages) no_site_packages=1;;
Matthew Treinish8e937d72012-12-14 11:11:41 -050027 -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"`"
Sean Daguef237ccb2013-01-04 15:19:14 -050080 srcfiles+=" `find stress -type f -name "*.py"`"
Matthew Treinish8b372892012-12-07 17:13:16 -050081 srcfiles+=" setup.py"
82
Sean Daguef237ccb2013-01-04 15:19:14 -050083 ignore='--ignore=E121,E122,E125,E126'
Sean Dague14a60152012-12-13 15:59:40 -050084
Sean Dague97449cc2013-01-04 14:38:26 -050085 ${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
Jay Pipesf38eaac2012-06-21 13:37:35 -040086}
87
Matthew Treinishd15705b2012-10-16 14:04:48 -040088function run_coverage_start {
89 echo "Starting nova-coverage"
90 ${wrapper} python tools/tempest_coverage.py -c start
91}
92
93function run_coverage_report {
94 echo "Generating nova-coverage report"
95 ${wrapper} python tools/tempest_coverage.py -c report
96}
97
Jay Pipesf38eaac2012-06-21 13:37:35 -040098NOSETESTS="nosetests $noseargs"
99
Matthew Treinish8e937d72012-12-14 11:11:41 -0500100if [ $never_venv -eq 0 ]
101then
102 # Remove the virtual environment if --force used
103 if [ $force -eq 1 ]; then
104 echo "Cleaning virtualenv..."
105 rm -rf ${venv}
106 fi
107 if [ -e ${venv} ]; then
108 wrapper="${with_venv}"
109 else
110 if [ $always_venv -eq 1 ]; then
111 # Automatically install the virtualenv
112 python tools/install_venv.py $installvenvopts
113 wrapper="${with_venv}"
114 else
115 echo -e "No virtual environment found...create one? (Y/n) \c"
116 read use_ve
117 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
118 # Install the virtualenv and run the test suite in it
119 python tools/install_venv.py $installvenvopts
120 wrapper=${with_venv}
121 fi
122 fi
123 fi
124fi
125
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500126if [ $just_pep8 -eq 1 ]; then
127 run_pep8
128 exit
129fi
130
Matthew Treinishd15705b2012-10-16 14:04:48 -0400131if [ $nova_coverage -eq 1 ]; then
132 run_coverage_start
133fi
134
135run_tests
136
137if [ $nova_coverage -eq 1 ]; then
138 run_coverage_report
139fi
Jay Pipesf38eaac2012-06-21 13:37:35 -0400140
141if [ -z "$noseargs" ]; then
142 run_pep8
143fi