Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Matthew Treinish | 68c7871 | 2016-07-28 14:47:27 -0400 | [diff] [blame] | 3 | echo "WARNING: This script is deprecated and will be removed in the near future. Please migrate to tempest run or another method of launching a test runner" |
| 4 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 5 | function usage { |
| 6 | echo "Usage: $0 [OPTION]..." |
| 7 | echo "Run Tempest test suite" |
| 8 | echo "" |
| 9 | echo " -V, --virtual-env Always use virtualenv. Install automatically if not present" |
| 10 | echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" |
| 11 | echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment" |
| 12 | echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." |
| 13 | echo " -u, --update Update the virtual environment with any newer package versions" |
| 14 | echo " -s, --smoke Only run smoke tests" |
| 15 | echo " -t, --serial Run testr serially" |
| 16 | echo " -C, --config Config file location" |
| 17 | echo " -h, --help Print this usage message" |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 18 | 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] | 19 | echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr " |
| 20 | } |
| 21 | |
| 22 | testrargs="" |
ghanshyam | f5360ff | 2015-06-29 13:32:01 +0900 | [diff] [blame] | 23 | venv=${VENV:-.venv} |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 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 |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 34 | |
Marc Koderer | c81c767 | 2015-12-17 12:10:12 +0100 | [diff] [blame] | 35 | if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config: -- "$@") |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 36 | then |
| 37 | # parse error |
| 38 | usage |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | eval set -- $options |
| 43 | first_uu=yes |
| 44 | while [ $# -gt 0 ]; do |
| 45 | case "$1" in |
| 46 | -h|--help) usage; exit;; |
| 47 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 48 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 49 | -n|--no-site-packages) no_site_packages=1;; |
| 50 | -f|--force) force=1;; |
| 51 | -u|--update) update=1;; |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 52 | -d|--debug) debug=1;; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 53 | -C|--config) config_file=$2; shift;; |
Matthew Treinish | a74f5d4 | 2014-02-07 20:25:44 -0500 | [diff] [blame] | 54 | -s|--smoke) testrargs+="smoke";; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 55 | -t|--serial) serial=1;; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 56 | --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;; |
Ryan Bak | 8660798 | 2014-06-01 12:26:35 -0600 | [diff] [blame] | 57 | *) testrargs="$testrargs $1";; |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 58 | esac |
| 59 | shift |
| 60 | done |
| 61 | |
| 62 | if [ -n "$config_file" ]; then |
| 63 | config_file=`readlink -f "$config_file"` |
| 64 | export TEMPEST_CONFIG_DIR=`dirname "$config_file"` |
| 65 | export TEMPEST_CONFIG=`basename "$config_file"` |
| 66 | fi |
| 67 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 68 | cd `dirname "$0"` |
| 69 | |
| 70 | if [ $no_site_packages -eq 1 ]; then |
| 71 | installvenvopts="--no-site-packages" |
| 72 | fi |
| 73 | |
| 74 | function testr_init { |
| 75 | if [ ! -d .testrepository ]; then |
| 76 | ${wrapper} testr init |
| 77 | fi |
| 78 | } |
| 79 | |
| 80 | function run_tests { |
| 81 | testr_init |
| 82 | ${wrapper} find . -type f -name "*.pyc" -delete |
| 83 | export OS_TEST_PATH=./tempest/test_discover |
Matthew Treinish | 1b1eb64 | 2014-01-21 19:38:47 +0000 | [diff] [blame] | 84 | if [ $debug -eq 1 ]; then |
| 85 | if [ "$testrargs" = "" ]; then |
| 86 | testrargs="discover ./tempest/test_discover" |
| 87 | fi |
| 88 | ${wrapper} python -m testtools.run $testrargs |
| 89 | return $? |
| 90 | fi |
| 91 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 92 | if [ $serial -eq 1 ]; then |
Matthew Treinish | 3898474 | 2015-03-11 16:01:47 -0400 | [diff] [blame] | 93 | ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-trace -n -f |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 94 | else |
Matthew Treinish | 3898474 | 2015-03-11 16:01:47 -0400 | [diff] [blame] | 95 | ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-trace -n -f |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 96 | fi |
| 97 | } |
| 98 | |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 99 | if [ $never_venv -eq 0 ] |
| 100 | then |
| 101 | # Remove the virtual environment if --force used |
| 102 | if [ $force -eq 1 ]; then |
| 103 | echo "Cleaning virtualenv..." |
| 104 | rm -rf ${venv} |
| 105 | fi |
| 106 | if [ $update -eq 1 ]; then |
| 107 | echo "Updating virtualenv..." |
Matthew Treinish | 72e8376 | 2016-01-20 20:19:23 -0500 | [diff] [blame] | 108 | virtualenv $installvenvopts $venv |
| 109 | $venv/bin/pip install -U -r requirements.txt |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 110 | fi |
| 111 | if [ -e ${venv} ]; then |
| 112 | wrapper="${with_venv}" |
| 113 | else |
| 114 | if [ $always_venv -eq 1 ]; then |
| 115 | # Automatically install the virtualenv |
Matthew Treinish | 72e8376 | 2016-01-20 20:19:23 -0500 | [diff] [blame] | 116 | virtualenv $installvenvopts $venv |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 117 | wrapper="${with_venv}" |
Matthew Treinish | 72e8376 | 2016-01-20 20:19:23 -0500 | [diff] [blame] | 118 | ${wrapper} pip install -U -r requirements.txt |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 119 | else |
| 120 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 121 | read use_ve |
| 122 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 123 | # Install the virtualenv and run the test suite in it |
Matthew Treinish | 72e8376 | 2016-01-20 20:19:23 -0500 | [diff] [blame] | 124 | virtualenv $installvenvopts $venv |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 125 | wrapper=${with_venv} |
Matthew Treinish | 72e8376 | 2016-01-20 20:19:23 -0500 | [diff] [blame] | 126 | ${wrapper} pip install -U -r requirements.txt |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 127 | fi |
| 128 | fi |
| 129 | fi |
| 130 | fi |
| 131 | |
Matthew Treinish | a74f5d4 | 2014-02-07 20:25:44 -0500 | [diff] [blame] | 132 | run_tests |
Matthew Treinish | 61f7d5e | 2014-01-05 13:13:39 -0500 | [diff] [blame] | 133 | retval=$? |
| 134 | |
| 135 | exit $retval |