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 | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 14 | echo " -c, --nova-coverage Enable Nova coverage collection" |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 15 | echo " -C, --config Config file location" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 16 | echo " -p, --pep8 Just run pep8" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 17 | echo " -h, --help Print this usage message" |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 18 | echo " -d, --debug Debug this script -- set -o xtrace" |
| 19 | echo " -S, --stdout Don't capture stdout" |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 20 | echo " -- [NOSEOPTIONS] After the first '--' you can pass arbitrary arguments to nosetests " |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 21 | } |
| 22 | |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 23 | noseargs="" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 24 | just_pep8=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 25 | venv=.venv |
| 26 | with_venv=tools/with_venv.sh |
| 27 | always_venv=0 |
| 28 | never_venv=0 |
| 29 | no_site_packages=0 |
| 30 | force=0 |
| 31 | wrapper="" |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 32 | nova_coverage=0 |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 33 | config_file="" |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 34 | update=0 |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 35 | |
Matthew Treinish | 4437332 | 2013-02-18 11:21:45 -0500 | [diff] [blame] | 36 | if ! options=$(getopt -o VNnfuswcphdsC: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,whitebox,nova-coverage,pep8,help,debug,stdout,config: -- "$@") |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 37 | then |
| 38 | # parse error |
| 39 | usage |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | eval set -- $options |
| 44 | first_uu=yes |
| 45 | while [ $# -gt 0 ]; do |
| 46 | case "$1" in |
| 47 | -h|--help) usage; exit;; |
| 48 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 49 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 50 | -n|--no-site-packages) no_site_packages=1;; |
| 51 | -f|--force) force=1;; |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 52 | -u|--update) update=1;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 53 | -d|--debug) set -o xtrace;; |
| 54 | -c|--nova-coverage) let nova_coverage=1;; |
| 55 | -C|--config) config_file=$2; shift;; |
| 56 | -p|--pep8) let just_pep8=1;; |
| 57 | -s|--smoke) noseargs="$noseargs --attr=type=smoke";; |
| 58 | -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";; |
| 59 | -S|--stdout) noseargs="$noseargs -s";; |
| 60 | --) [ "yes" == "$first_uu" ] || noseargs="$noseargs $1"; first_uu=no ;; |
| 61 | *) noseargs="$noseargs $1" |
| 62 | esac |
| 63 | shift |
| 64 | done |
| 65 | |
| 66 | if [ -n "$config_file" ]; then |
| 67 | config_file=`readlink -f "$config_file"` |
| 68 | export TEMPEST_CONFIG_DIR=`dirname "$config_file"` |
| 69 | export TEMPEST_CONFIG=`basename "$config_file"` |
| 70 | fi |
| 71 | |
| 72 | cd `dirname "$0"` |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 73 | |
| 74 | export NOSE_WITH_OPENSTACK=1 |
| 75 | export NOSE_OPENSTACK_COLOR=1 |
| 76 | export NOSE_OPENSTACK_RED=15.00 |
| 77 | export NOSE_OPENSTACK_YELLOW=3.00 |
| 78 | export NOSE_OPENSTACK_SHOW_ELAPSED=1 |
| 79 | export NOSE_OPENSTACK_STDOUT=1 |
| 80 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 81 | if [ $no_site_packages -eq 1 ]; then |
| 82 | installvenvopts="--no-site-packages" |
| 83 | fi |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 84 | |
| 85 | # only add tempest default if we don't specify a test |
| 86 | if [[ "x$noseargs" =~ "tempest" ]]; then |
| 87 | noseargs="$noseargs" |
| 88 | else |
| 89 | noseargs="$noseargs tempest" |
| 90 | fi |
| 91 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 92 | function run_tests { |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 93 | ${wrapper} $NOSETESTS |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 96 | function run_pep8 { |
| 97 | echo "Running pep8 ..." |
Matthew Treinish | 8b37289 | 2012-12-07 17:13:16 -0500 | [diff] [blame] | 98 | srcfiles="`find tempest -type f -name "*.py"`" |
| 99 | srcfiles+=" `find tools -type f -name "*.py"`" |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 100 | srcfiles+=" `find stress -type f -name "*.py"`" |
Matthew Treinish | 8b37289 | 2012-12-07 17:13:16 -0500 | [diff] [blame] | 101 | srcfiles+=" setup.py" |
| 102 | |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 103 | ignore='--ignore=E121,E122,E125,E126' |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 104 | |
Sean Dague | 97449cc | 2013-01-04 14:38:26 -0500 | [diff] [blame] | 105 | ${wrapper} python tools/hacking.py ${ignore} ${srcfiles} |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 106 | } |
| 107 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 108 | function run_coverage_start { |
| 109 | echo "Starting nova-coverage" |
| 110 | ${wrapper} python tools/tempest_coverage.py -c start |
| 111 | } |
| 112 | |
| 113 | function run_coverage_report { |
| 114 | echo "Generating nova-coverage report" |
| 115 | ${wrapper} python tools/tempest_coverage.py -c report |
| 116 | } |
| 117 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 118 | NOSETESTS="nosetests $noseargs" |
| 119 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 120 | if [ $never_venv -eq 0 ] |
| 121 | then |
| 122 | # Remove the virtual environment if --force used |
| 123 | if [ $force -eq 1 ]; then |
| 124 | echo "Cleaning virtualenv..." |
| 125 | rm -rf ${venv} |
| 126 | fi |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 127 | if [ $update -eq 1 ]; then |
| 128 | echo "Updating virtualenv..." |
| 129 | python tools/install_venv.py $installvenvopts |
| 130 | fi |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 131 | if [ -e ${venv} ]; then |
| 132 | wrapper="${with_venv}" |
| 133 | else |
| 134 | if [ $always_venv -eq 1 ]; then |
| 135 | # Automatically install the virtualenv |
| 136 | python tools/install_venv.py $installvenvopts |
| 137 | wrapper="${with_venv}" |
| 138 | else |
| 139 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 140 | read use_ve |
| 141 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 142 | # Install the virtualenv and run the test suite in it |
| 143 | python tools/install_venv.py $installvenvopts |
| 144 | wrapper=${with_venv} |
| 145 | fi |
| 146 | fi |
| 147 | fi |
| 148 | fi |
| 149 | |
Matthew Treinish | 0cc26b6 | 2013-01-03 18:07:09 -0500 | [diff] [blame] | 150 | if [ $just_pep8 -eq 1 ]; then |
| 151 | run_pep8 |
| 152 | exit |
| 153 | fi |
| 154 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 155 | if [ $nova_coverage -eq 1 ]; then |
| 156 | run_coverage_start |
| 157 | fi |
| 158 | |
| 159 | run_tests |
| 160 | |
| 161 | if [ $nova_coverage -eq 1 ]; then |
| 162 | run_coverage_report |
| 163 | fi |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 164 | |
| 165 | if [ -z "$noseargs" ]; then |
| 166 | run_pep8 |
| 167 | fi |