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" |
| 9 | echo " -s, --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." |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 11 | echo " -s, --smoke Only run smoke tests" |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 12 | echo " -w, --whitebox Only run whitebox tests" |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame^] | 13 | echo " -c, --nova-coverage Enable Nova coverage collection" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 14 | echo " -p, --pep8 Just run pep8" |
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" |
| 17 | echo " -S, --stdout Don't capture stdout" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 18 | exit |
| 19 | } |
| 20 | |
| 21 | function process_option { |
| 22 | case "$1" in |
| 23 | -h|--help) usage;; |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 24 | -V|--virtual-env) always_venv=1; never_venv=0;; |
| 25 | -N|--no-virtual-env) always_venv=0; never_venv=1;; |
| 26 | -s|--no-site-packages) no_site_packages=1;; |
| 27 | -f|--force) force=1;; |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 28 | -d|--debug) set -o xtrace;; |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame^] | 29 | -c|--nova-coverage) let nova_coverage=1;; |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 30 | -p|--pep8) let just_pep8=1;; |
| 31 | -s|--smoke) noseargs="$noseargs --attr=type=smoke";; |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 32 | -w|--whitebox) noseargs="$noseargs --attr=type=whitebox";; |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 33 | -S|--stdout) noseargs="$noseargs -s";; |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 34 | *) noseargs="$noseargs $1" |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 35 | esac |
| 36 | } |
| 37 | |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 38 | noseargs="" |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 39 | just_pep8=0 |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 40 | venv=.venv |
| 41 | with_venv=tools/with_venv.sh |
| 42 | always_venv=0 |
| 43 | never_venv=0 |
| 44 | no_site_packages=0 |
| 45 | force=0 |
| 46 | wrapper="" |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame^] | 47 | nova_coverage=0 |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 48 | |
| 49 | export NOSE_WITH_OPENSTACK=1 |
| 50 | export NOSE_OPENSTACK_COLOR=1 |
| 51 | export NOSE_OPENSTACK_RED=15.00 |
| 52 | export NOSE_OPENSTACK_YELLOW=3.00 |
| 53 | export NOSE_OPENSTACK_SHOW_ELAPSED=1 |
| 54 | export NOSE_OPENSTACK_STDOUT=1 |
| 55 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 56 | for arg in "$@"; do |
| 57 | process_option $arg |
| 58 | done |
| 59 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 60 | if [ $no_site_packages -eq 1 ]; then |
| 61 | installvenvopts="--no-site-packages" |
| 62 | fi |
Sean Dague | 422af97 | 2012-11-16 07:30:43 -0500 | [diff] [blame] | 63 | |
| 64 | # only add tempest default if we don't specify a test |
| 65 | if [[ "x$noseargs" =~ "tempest" ]]; then |
| 66 | noseargs="$noseargs" |
| 67 | else |
| 68 | noseargs="$noseargs tempest" |
| 69 | fi |
| 70 | |
| 71 | |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 72 | function run_tests { |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 73 | ${wrapper} $NOSETESTS |
Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 76 | function run_pep8 { |
| 77 | echo "Running pep8 ..." |
Matthew Treinish | 8b37289 | 2012-12-07 17:13:16 -0500 | [diff] [blame] | 78 | srcfiles="`find tempest -type f -name "*.py"`" |
| 79 | srcfiles+=" `find tools -type f -name "*.py"`" |
| 80 | srcfiles+=" setup.py" |
| 81 | |
| 82 | ignore='--ignore=N4,E121,E122,E125,E126' |
Sean Dague | 14a6015 | 2012-12-13 15:59:40 -0500 | [diff] [blame] | 83 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -0500 | [diff] [blame] | 84 | ${wrapper} python tools/hacking.py ${ignore} ${srcfiles} |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame^] | 87 | function run_coverage_start { |
| 88 | echo "Starting nova-coverage" |
| 89 | ${wrapper} python tools/tempest_coverage.py -c start |
| 90 | } |
| 91 | |
| 92 | function run_coverage_report { |
| 93 | echo "Generating nova-coverage report" |
| 94 | ${wrapper} python tools/tempest_coverage.py -c report |
| 95 | } |
| 96 | |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 97 | NOSETESTS="nosetests $noseargs" |
| 98 | |
Matthew Treinish | 8e937d7 | 2012-12-14 11:11:41 -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 [ -e ${venv} ]; then |
| 107 | wrapper="${with_venv}" |
| 108 | else |
| 109 | if [ $always_venv -eq 1 ]; then |
| 110 | # Automatically install the virtualenv |
| 111 | python tools/install_venv.py $installvenvopts |
| 112 | wrapper="${with_venv}" |
| 113 | else |
| 114 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 115 | read use_ve |
| 116 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 117 | # Install the virtualenv and run the test suite in it |
| 118 | python tools/install_venv.py $installvenvopts |
| 119 | wrapper=${with_venv} |
| 120 | fi |
| 121 | fi |
| 122 | fi |
| 123 | fi |
| 124 | |
Matthew Treinish | 0cc26b6 | 2013-01-03 18:07:09 -0500 | [diff] [blame] | 125 | if [ $just_pep8 -eq 1 ]; then |
| 126 | run_pep8 |
| 127 | exit |
| 128 | fi |
| 129 | |
Matthew Treinish | d15705b | 2012-10-16 14:04:48 -0400 | [diff] [blame^] | 130 | if [ $nova_coverage -eq 1 ]; then |
| 131 | run_coverage_start |
| 132 | fi |
| 133 | |
| 134 | run_tests |
| 135 | |
| 136 | if [ $nova_coverage -eq 1 ]; then |
| 137 | run_coverage_report |
| 138 | fi |
Jay Pipes | f38eaac | 2012-06-21 13:37:35 -0400 | [diff] [blame] | 139 | |
| 140 | if [ -z "$noseargs" ]; then |
| 141 | run_pep8 |
| 142 | fi |