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]..." |
Matthew Treinish | 17520e4 | 2014-01-05 13:02:23 -0500 | [diff] [blame] | 5 | echo "Run Tempest unit tests" |
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" |
Matthew Treinish | 49f4036 | 2013-08-27 16:02:53 -0400 | [diff] [blame] | 12 | echo " -t, --serial Run testr serially" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 13 | echo " -p, --pep8 Just run pep8" |
Matthew Treinish | ab836be | 2014-01-11 14:34:58 -0500 | [diff] [blame] | 14 | echo " -c, --coverage Generate coverage report" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 15 | echo " -h, --help Print this usage message" |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 16 | echo " -d, --debug Debug this script -- set -o xtrace" |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 17 | echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr " |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 18 | } |
| 19 | |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 20 | testrargs="" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 21 | just_pep8=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 22 | venv=.venv |
| 23 | with_venv=tools/with_venv.sh |
Matthew Treinish | 49f4036 | 2013-08-27 16:02:53 -0400 | [diff] [blame] | 24 | serial=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 25 | always_venv=0 |
| 26 | never_venv=0 |
| 27 | no_site_packages=0 |
| 28 | force=0 |
Matthew Treinish | ab836be | 2014-01-11 14:34:58 -0500 | [diff] [blame] | 29 | coverage=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 30 | wrapper="" |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 31 | config_file="" |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 32 | update=0 |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 33 | |
Matthew Treinish | ab836be | 2014-01-11 14:34:58 -0500 | [diff] [blame] | 34 | if ! options=$(getopt -o VNnfuctphd -l virtual-env,no-virtual-env,no-site-packages,force,update,serial,coverage,pep8,help,debug -- "$@") |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 35 | then |
| 36 | # parse error |
| 37 | usage |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | eval set -- $options |
| 42 | first_uu=yes |
| 43 | while [ $# -gt 0 ]; do |
| 44 | case "$1" in |
| 45 | -h|--help) usage; exit;; |
| 46 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 47 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 48 | -n|--no-site-packages) no_site_packages=1;; |
| 49 | -f|--force) force=1;; |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 50 | -u|--update) update=1;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 51 | -d|--debug) set -o xtrace;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 52 | -p|--pep8) let just_pep8=1;; |
Matthew Treinish | ab836be | 2014-01-11 14:34:58 -0500 | [diff] [blame] | 53 | -c|--coverage) coverage=1;; |
Matthew Treinish | 49f4036 | 2013-08-27 16:02:53 -0400 | [diff] [blame] | 54 | -t|--serial) serial=1;; |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 55 | --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;; |
Sunil Thaha | ee332b0 | 2013-10-10 13:49:19 +1000 | [diff] [blame] | 56 | *) testrargs="$testrargs $1"; noseargs+=" $1" ;; |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 57 | esac |
| 58 | shift |
| 59 | done |
| 60 | |
Mitsuhiko Yamazaki | 46818aa | 2013-04-18 17:49:17 +0900 | [diff] [blame] | 61 | |
Attila Fazekas | a63a999 | 2013-02-14 16:44:37 +0100 | [diff] [blame] | 62 | cd `dirname "$0"` |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 63 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 64 | if [ $no_site_packages -eq 1 ]; then |
| 65 | installvenvopts="--no-site-packages" |
| 66 | fi |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 67 | |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 68 | function testr_init { |
| 69 | if [ ! -d .testrepository ]; then |
| 70 | ${wrapper} testr init |
| 71 | fi |
| 72 | } |
| 73 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 74 | function run_tests { |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 75 | testr_init |
| 76 | ${wrapper} find . -type f -name "*.pyc" -delete |
Matthew Treinish | 17520e4 | 2014-01-05 13:02:23 -0500 | [diff] [blame] | 77 | export OS_TEST_PATH=./tempest/tests |
Matthew Treinish | 49f4036 | 2013-08-27 16:02:53 -0400 | [diff] [blame] | 78 | if [ $serial -eq 1 ]; then |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 79 | ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py |
Matthew Treinish | 49f4036 | 2013-08-27 16:02:53 -0400 | [diff] [blame] | 80 | else |
| 81 | ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py |
Matthew Treinish | 87af1bb | 2013-06-17 15:29:10 -0400 | [diff] [blame] | 82 | fi |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 85 | function run_pep8 { |
Kui Shi | b1b7c71 | 2013-08-23 06:40:05 +0800 | [diff] [blame] | 86 | echo "Running flake8 ..." |
| 87 | if [ $never_venv -eq 1 ]; then |
| 88 | echo "**WARNING**:" >&2 |
| 89 | echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2 |
| 90 | fi |
Monty Taylor | b2ca5ca | 2013-04-28 18:00:21 -0700 | [diff] [blame] | 91 | ${wrapper} flake8 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 94 | if [ $never_venv -eq 0 ] |
| 95 | then |
| 96 | # Remove the virtual environment if --force used |
| 97 | if [ $force -eq 1 ]; then |
| 98 | echo "Cleaning virtualenv..." |
| 99 | rm -rf ${venv} |
| 100 | fi |
Matthew Treinish | 8f42d3b | 2013-02-15 13:24:05 -0500 | [diff] [blame] | 101 | if [ $update -eq 1 ]; then |
| 102 | echo "Updating virtualenv..." |
| 103 | python tools/install_venv.py $installvenvopts |
| 104 | fi |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 105 | if [ -e ${venv} ]; then |
| 106 | wrapper="${with_venv}" |
| 107 | else |
| 108 | if [ $always_venv -eq 1 ]; then |
| 109 | # Automatically install the virtualenv |
| 110 | python tools/install_venv.py $installvenvopts |
| 111 | wrapper="${with_venv}" |
| 112 | else |
| 113 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 114 | read use_ve |
| 115 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 116 | # Install the virtualenv and run the test suite in it |
| 117 | python tools/install_venv.py $installvenvopts |
| 118 | wrapper=${with_venv} |
| 119 | fi |
| 120 | fi |
| 121 | fi |
| 122 | fi |
| 123 | |
Matthew Treinish | 0cc26b6 | 2013-01-03 18:07:09 -0500 | [diff] [blame] | 124 | if [ $just_pep8 -eq 1 ]; then |
| 125 | run_pep8 |
| 126 | exit |
| 127 | fi |
| 128 | |
Masayuki Igawa | 9a22335 | 2014-01-14 11:02:53 +0900 | [diff] [blame] | 129 | if [ $coverage -eq 1 ]; then |
Matthew Treinish | ab836be | 2014-01-11 14:34:58 -0500 | [diff] [blame] | 130 | $testrargs = "--coverage $testrargs" |
| 131 | fi |
| 132 | |
Matthew Treinish | 17520e4 | 2014-01-05 13:02:23 -0500 | [diff] [blame] | 133 | run_tests |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 134 | retval=$? |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame] | 135 | |
Matthew Treinish | 59eb0b2 | 2013-08-07 15:48:21 -0400 | [diff] [blame] | 136 | if [ -z "$testrargs" ]; then |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 137 | run_pep8 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 138 | fi |
Giulio Fidente | 1e50b3b | 2013-06-03 15:00:54 +0200 | [diff] [blame] | 139 | |
| 140 | exit $retval |