Attila Fazekas | 5abb253 | 2012-12-04 11:30:49 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 2 | |
| 3 | function usage { |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 4 | echo "Usage: $0 [OPTION]..." |
| 5 | echo "Run Tempest test suite" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 6 | echo "" |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 7 | 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 Frittoli | 1cfbc4a | 2013-01-31 19:44:10 +0000 | [diff] [blame] | 9 | echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment" |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 10 | echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 11 | echo " -u, --update Update the virtual environment with any newer package versions" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 12 | echo " -s, --smoke Only run smoke tests" |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 13 | echo " -w, --whitebox Only run whitebox tests" |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 14 | echo " -t, --with-testr Run using testr instead of nose" |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 15 | echo " -c, --nova-coverage Enable Nova coverage collection" |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 16 | echo " -C, --config Config file location" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 17 | echo " -p, --pep8 Just run pep8" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 18 | echo " -h, --help Print this usage message" |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 19 | echo " -d, --debug Debug this script -- set -o xtrace" |
| 20 | echo " -S, --stdout Don't capture stdout" |
Mitsuhiko Yamazaki | 6ffa59c | 2013-04-11 13:37:07 +0900 | [diff] [blame] | 21 | echo " -l, --logging Enable logging" |
| 22 | echo " -L, --logging-config Logging config file location. Default is etc/logging.conf" |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 23 | echo " -- [NOSEOPTIONS] After the first '--' you can pass arbitrary arguments to nosetests " |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 24 | } |
| 25 | |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 26 | noseargs="" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 27 | just_pep8=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 28 | venv=.venv |
| 29 | with_venv=tools/with_venv.sh |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 30 | with_testr=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 31 | always_venv=0 |
| 32 | never_venv=0 |
| 33 | no_site_packages=0 |
| 34 | force=0 |
| 35 | wrapper="" |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 36 | nova_coverage=0 |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 37 | config_file="" |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 38 | update=0 |
Mitsuhiko Yamazaki | 6ffa59c | 2013-04-11 13:37:07 +0900 | [diff] [blame] | 39 | logging=0 |
| 40 | logging_config=etc/logging.conf |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 41 | |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 42 | if ! options=$(getopt -o VNnfuswtcphdSC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,with-testr,nova-coverage,pep8,help,debug,stdout,config:,logging,logging-config: -- "$@") |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 43 | then |
| 44 | # parse error |
| 45 | usage |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | eval set -- $options |
| 50 | first_uu=yes |
| 51 | while [ $# -gt 0 ]; do |
| 52 | case "$1" in |
| 53 | -h|--help) usage; exit;; |
| 54 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 55 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 56 | -n|--no-site-packages) no_site_packages=1;; |
| 57 | -f|--force) force=1;; |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 58 | -u|--update) update=1;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 59 | -d|--debug) set -o xtrace;; |
| 60 | -c|--nova-coverage) let nova_coverage=1;; |
| 61 | -C|--config) config_file=$2; shift;; |
| 62 | -p|--pep8) let just_pep8=1;; |
| 63 | -s|--smoke) noseargs="$noseargs --attr=type=smoke";; |
| 64 | -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";; |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 65 | -t|--with-testr) with_testr=1;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 66 | -S|--stdout) noseargs="$noseargs -s";; |
Mitsuhiko Yamazaki | 6ffa59c | 2013-04-11 13:37:07 +0900 | [diff] [blame] | 67 | -l|--logging) logging=1;; |
| 68 | -L|--logging-config) logging_config=$2; shift;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 69 | --) [ "yes" == "$first_uu" ] || noseargs="$noseargs $1"; first_uu=no ;; |
| 70 | *) noseargs="$noseargs $1" |
| 71 | esac |
| 72 | shift |
| 73 | done |
| 74 | |
| 75 | if [ -n "$config_file" ]; then |
| 76 | config_file=`readlink -f "$config_file"` |
| 77 | export TEMPEST_CONFIG_DIR=`dirname "$config_file"` |
| 78 | export TEMPEST_CONFIG=`basename "$config_file"` |
| 79 | fi |
| 80 | |
Mitsuhiko Yamazaki | 46818aa | 2013-04-18 17:49:17 +0900 | [diff] [blame] | 81 | if [ $logging -eq 1 ]; then |
| 82 | if [ ! -f "$logging_config" ]; then |
| 83 | echo "No such logging config file: $logging_config" |
| 84 | exit 1 |
| 85 | fi |
| 86 | logging_config=`readlink -f "$logging_config"` |
| 87 | export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"` |
| 88 | export TEMPEST_LOG_CONFIG=`basename "$logging_config"` |
| 89 | fi |
| 90 | |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 91 | cd `dirname "$0"` |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 92 | |
| 93 | export NOSE_WITH_OPENSTACK=1 |
| 94 | export NOSE_OPENSTACK_COLOR=1 |
| 95 | export NOSE_OPENSTACK_RED=15.00 |
| 96 | export NOSE_OPENSTACK_YELLOW=3.00 |
| 97 | export NOSE_OPENSTACK_SHOW_ELAPSED=1 |
| 98 | export NOSE_OPENSTACK_STDOUT=1 |
| 99 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 100 | if [ $no_site_packages -eq 1 ]; then |
| 101 | installvenvopts="--no-site-packages" |
| 102 | fi |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 103 | |
| 104 | # only add tempest default if we don't specify a test |
| 105 | if [[ "x$noseargs" =~ "tempest" ]]; then |
| 106 | noseargs="$noseargs" |
| 107 | else |
| 108 | noseargs="$noseargs tempest" |
| 109 | fi |
| 110 | |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 111 | function testr_init { |
| 112 | if [ ! -d .testrepository ]; then |
| 113 | ${wrapper} testr init |
| 114 | fi |
| 115 | } |
| 116 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 117 | function run_tests { |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 118 | if [ $with_testr -eq 1 ]; then |
| 119 | testr_init |
| 120 | ${wrapper} find . -type f -name "*.pyc" -delete |
Matthew Treinish | 0e2d8aa | 2013-07-18 15:16:37 -0400 | [diff] [blame^] | 121 | ${wrapper} testr run --parallel --subunit $noseargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 122 | else |
| 123 | ${wrapper} $NOSETESTS |
| 124 | fi |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 127 | function run_pep8 { |
| 128 | echo "Running pep8 ..." |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 129 | ${wrapper} flake8 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 130 | } |
| 131 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 132 | function run_coverage_start { |
| 133 | echo "Starting nova-coverage" |
| 134 | ${wrapper} python tools/tempest_coverage.py -c start |
| 135 | } |
| 136 | |
| 137 | function run_coverage_report { |
| 138 | echo "Generating nova-coverage report" |
| 139 | ${wrapper} python tools/tempest_coverage.py -c report |
| 140 | } |
| 141 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 142 | NOSETESTS="nosetests $noseargs" |
| 143 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 144 | if [ $never_venv -eq 0 ] |
| 145 | then |
| 146 | # Remove the virtual environment if --force used |
| 147 | if [ $force -eq 1 ]; then |
| 148 | echo "Cleaning virtualenv..." |
| 149 | rm -rf ${venv} |
| 150 | fi |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 151 | if [ $update -eq 1 ]; then |
| 152 | echo "Updating virtualenv..." |
| 153 | python tools/install_venv.py $installvenvopts |
| 154 | fi |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 155 | if [ -e ${venv} ]; then |
| 156 | wrapper="${with_venv}" |
| 157 | else |
| 158 | if [ $always_venv -eq 1 ]; then |
| 159 | # Automatically install the virtualenv |
| 160 | python tools/install_venv.py $installvenvopts |
| 161 | wrapper="${with_venv}" |
| 162 | else |
| 163 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 164 | read use_ve |
| 165 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 166 | # Install the virtualenv and run the test suite in it |
| 167 | python tools/install_venv.py $installvenvopts |
| 168 | wrapper=${with_venv} |
| 169 | fi |
| 170 | fi |
| 171 | fi |
| 172 | fi |
| 173 | |
Matthew Treinish | 0cc26b6 | 2013-01-03 18:07:09 -0500 | [diff] [blame] | 174 | if [ $just_pep8 -eq 1 ]; then |
| 175 | run_pep8 |
| 176 | exit |
| 177 | fi |
| 178 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 179 | if [ $nova_coverage -eq 1 ]; then |
| 180 | run_coverage_start |
| 181 | fi |
| 182 | |
| 183 | run_tests |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 184 | retval=$? |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 185 | |
| 186 | if [ $nova_coverage -eq 1 ]; then |
| 187 | run_coverage_report |
| 188 | fi |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 189 | |
| 190 | if [ -z "$noseargs" ]; then |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 191 | run_pep8 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 192 | fi |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 193 | |
| 194 | exit $retval |