Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | function usage { |
| 4 | echo "Usage: $0 [OPTION]..." |
| 5 | echo "Run Tempest test suite" |
| 6 | echo "" |
| 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" |
| 9 | echo " -n, --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." |
| 11 | echo " -u, --update Update the virtual environment with any newer package versions" |
| 12 | echo " -s, --smoke Only run smoke tests" |
| 13 | echo " -t, --serial Run testr serially" |
| 14 | echo " -C, --config Config file location" |
| 15 | echo " -h, --help Print this usage message" |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 16 | echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB" |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 17 | echo " -l, --logging Enable logging" |
| 18 | echo " -L, --logging-config Logging config file location. Default is etc/logging.conf" |
| 19 | echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr " |
| 20 | } |
| 21 | |
| 22 | testrargs="" |
| 23 | venv=.venv |
| 24 | with_venv=tools/with_venv.sh |
| 25 | serial=0 |
| 26 | always_venv=0 |
| 27 | never_venv=0 |
| 28 | no_site_packages=0 |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 29 | debug=0 |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 30 | force=0 |
| 31 | wrapper="" |
| 32 | config_file="" |
| 33 | update=0 |
| 34 | logging=0 |
| 35 | logging_config=etc/logging.conf |
| 36 | |
| 37 | if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config:,logging,logging-config: -- "$@") |
| 38 | then |
| 39 | # parse error |
| 40 | usage |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | eval set -- $options |
| 45 | first_uu=yes |
| 46 | while [ $# -gt 0 ]; do |
| 47 | case "$1" in |
| 48 | -h|--help) usage; exit;; |
| 49 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 50 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 51 | -n|--no-site-packages) no_site_packages=1;; |
| 52 | -f|--force) force=1;; |
| 53 | -u|--update) update=1;; |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 54 | -d|--debug) debug=1;; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 55 | -C|--config) config_file=$2; shift;; |
Matthew Treinish | a74f5d4 | 2014-02-07 20:25:44 -0500 | [diff] [blame] | 56 | -s|--smoke) testrargs+="smoke";; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 57 | -t|--serial) serial=1;; |
| 58 | -l|--logging) logging=1;; |
| 59 | -L|--logging-config) logging_config=$2; shift;; |
| 60 | --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;; |
Ryan Bak | 8660798 | 2014-06-01 12:26:35 -0600 | [diff] [blame] | 61 | *) testrargs="$testrargs $1";; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 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 | if [ $logging -eq 1 ]; then |
| 73 | if [ ! -f "$logging_config" ]; then |
| 74 | echo "No such logging config file: $logging_config" |
| 75 | exit 1 |
| 76 | fi |
| 77 | logging_config=`readlink -f "$logging_config"` |
| 78 | export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"` |
| 79 | export TEMPEST_LOG_CONFIG=`basename "$logging_config"` |
| 80 | fi |
| 81 | |
| 82 | cd `dirname "$0"` |
| 83 | |
| 84 | if [ $no_site_packages -eq 1 ]; then |
| 85 | installvenvopts="--no-site-packages" |
| 86 | fi |
| 87 | |
| 88 | function testr_init { |
| 89 | if [ ! -d .testrepository ]; then |
| 90 | ${wrapper} testr init |
| 91 | fi |
| 92 | } |
| 93 | |
| 94 | function run_tests { |
| 95 | testr_init |
| 96 | ${wrapper} find . -type f -name "*.pyc" -delete |
| 97 | export OS_TEST_PATH=./tempest/test_discover |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 98 | if [ $debug -eq 1 ]; then |
| 99 | if [ "$testrargs" = "" ]; then |
| 100 | testrargs="discover ./tempest/test_discover" |
| 101 | fi |
| 102 | ${wrapper} python -m testtools.run $testrargs |
| 103 | return $? |
| 104 | fi |
| 105 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 106 | if [ $serial -eq 1 ]; then |
| 107 | ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py |
| 108 | else |
| 109 | ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py |
| 110 | fi |
| 111 | } |
| 112 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 113 | if [ $never_venv -eq 0 ] |
| 114 | then |
| 115 | # Remove the virtual environment if --force used |
| 116 | if [ $force -eq 1 ]; then |
| 117 | echo "Cleaning virtualenv..." |
| 118 | rm -rf ${venv} |
| 119 | fi |
| 120 | if [ $update -eq 1 ]; then |
| 121 | echo "Updating virtualenv..." |
| 122 | python tools/install_venv.py $installvenvopts |
| 123 | fi |
| 124 | if [ -e ${venv} ]; then |
| 125 | wrapper="${with_venv}" |
| 126 | else |
| 127 | if [ $always_venv -eq 1 ]; then |
| 128 | # Automatically install the virtualenv |
| 129 | python tools/install_venv.py $installvenvopts |
| 130 | wrapper="${with_venv}" |
| 131 | else |
| 132 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 133 | read use_ve |
| 134 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 135 | # Install the virtualenv and run the test suite in it |
| 136 | python tools/install_venv.py $installvenvopts |
| 137 | wrapper=${with_venv} |
| 138 | fi |
| 139 | fi |
| 140 | fi |
| 141 | fi |
| 142 | |
Matthew Treinish | a74f5d4 | 2014-02-07 20:25:44 -0500 | [diff] [blame] | 143 | run_tests |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 144 | retval=$? |
| 145 | |
| 146 | exit $retval |