|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -cd django-openstack |
4 |
| -python bootstrap.py |
5 |
| -bin/buildout |
6 |
| -bin/test |
7 |
| -# get results of the django-openstack tests |
8 |
| -OPENSTACK_RESULT=$? |
9 |
| - |
10 |
| -cd ../openstack-dashboard |
11 |
| -python tools/install_venv.py |
12 |
| - |
13 |
| -cp local/local_settings.py.example local/local_settings.py |
14 |
| -tools/with_venv.sh dashboard/manage.py test |
15 |
| -# get results of the openstack-dashboard tests |
16 |
| -DASHBOARD_RESULT=$? |
17 |
| - |
18 |
| -exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT)) |
| 3 | +function usage { |
| 4 | + echo "Usage: $0 [OPTION]..." |
| 5 | + echo "Run Maestro's test suite(s)" |
| 6 | + echo "" |
| 7 | + echo " -V, --virtual-env Always use virtualenv. Install automatically" |
| 8 | + echo " if not present" |
| 9 | + echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local" |
| 10 | + echo " environment" |
| 11 | + echo " -f, --force Force a clean re-build of the virtual" |
| 12 | + echo " environment. Useful when dependencies have" |
| 13 | + echo " been added." |
| 14 | + echo " -p, --pep8 Just run pep8" |
| 15 | + echo " -y, --pylint Just run pylint" |
| 16 | + echo " -h, --help Print this usage message" |
| 17 | + echo "" |
| 18 | + echo "Note: with no options specified, the script will try to run the tests in" |
| 19 | + echo " a virtual environment, If no virtualenv is found, the script will ask" |
| 20 | + echo " if you would like to create one. If you prefer to run tests NOT in a" |
| 21 | + echo " virtual environment, simply pass the -N option." |
| 22 | + exit |
| 23 | +} |
| 24 | + |
| 25 | +function process_option { |
| 26 | + case "$1" in |
| 27 | + -h|--help) usage;; |
| 28 | + -V|--virtual-env) let always_venv=1; let never_venv=0;; |
| 29 | + -N|--no-virtual-env) let always_venv=0; let never_venv=1;; |
| 30 | + -p|--pep8) let just_pep8=1;; |
| 31 | + -y|--pylint) let just_pylint=1;; |
| 32 | + -f|--force) let force=1;; |
| 33 | + *) testargs="$testargs $1" |
| 34 | + esac |
| 35 | +} |
| 36 | + |
| 37 | +function run_pylint { |
| 38 | + echo "Running pylint ..." |
| 39 | + PYLINT_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack" |
| 40 | + ${wrapper} pylint --rcfile=.pylintrc -f parseable $PYLINT_INCLUDE > pylint.txt |
| 41 | + CODE=$? |
| 42 | + grep Global -A2 pylint.txt |
| 43 | + if [ $CODE -lt 32 ] |
| 44 | + then |
| 45 | + exit 0 |
| 46 | + else |
| 47 | + exit $CODE |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +function run_pep8 { |
| 52 | + echo "Running pep8 ..." |
| 53 | + PEP8_EXCLUDE=vcsversion.py |
| 54 | + PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source" |
| 55 | + PEP8_INCLUDE="openstack-dashboard/dashboard django-openstack/django_openstack" |
| 56 | + ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt |
| 57 | + #perl string strips out the [ and ] characters |
| 58 | + #${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +# DEFAULTS FOR RUN_TESTS.SH |
| 63 | +# |
| 64 | +venv=openstack-dashboard/.dashboard-venv |
| 65 | +django_with_venv=openstack-dashboard/tools/with_venv.sh |
| 66 | +dashboard_with_venv=tools/with_venv.sh |
| 67 | +always_venv=0 |
| 68 | +never_venv=0 |
| 69 | +force=0 |
| 70 | +testargs="" |
| 71 | +django_wrapper="" |
| 72 | +dashboard_wrapper="" |
| 73 | +just_pep8=0 |
| 74 | +just_pylint=0 |
| 75 | + |
| 76 | +# PROCESS ARGUMENTS, OVERRIDE DEFAULTS |
| 77 | +for arg in "$@"; do |
| 78 | + process_option $arg |
| 79 | +done |
| 80 | + |
| 81 | +if [ $never_venv -eq 0 ] |
| 82 | +then |
| 83 | + # Remove the virtual environment if --force used |
| 84 | + if [ $force -eq 1 ]; then |
| 85 | + echo "Cleaning virtualenv..." |
| 86 | + rm -rf ${venv} |
| 87 | + fi |
| 88 | + if [ -e ${venv} ]; then |
| 89 | + django_wrapper="${django_with_venv}" |
| 90 | + dashboard_wrapper="${dashboard_with_venv}" |
| 91 | + else |
| 92 | + if [ $always_venv -eq 1 ]; then |
| 93 | + # Automatically install the virtualenv |
| 94 | + python tools/install_venv.py |
| 95 | + django_wrapper="${django_with_venv}" |
| 96 | + dashboard_wrapper="${dashboard_with_venv}" |
| 97 | + else |
| 98 | + echo -e "No virtual environment found...create one? (Y/n) \c" |
| 99 | + read use_ve |
| 100 | + if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 101 | + # Install the virtualenv and run the test suite in it |
| 102 | + python tools/install_venv.py |
| 103 | + django_wrapper="${django_with_venv}" |
| 104 | + dashboard_wrapper="${dashboard_with_venv}" |
| 105 | + fi |
| 106 | + fi |
| 107 | + fi |
| 108 | +fi |
| 109 | + |
| 110 | +function run_tests { |
| 111 | + echo "Running django-openstack (core django) tests" |
| 112 | + ${django_wrapper} coverage erase |
| 113 | + cd django-openstack |
| 114 | + python bootstrap.py |
| 115 | + bin/buildout |
| 116 | + cd .. |
| 117 | + ${django_wrapper} coverage run django-openstack/bin/test |
| 118 | + # get results of the django-openstack tests |
| 119 | + OPENSTACK_RESULT=$? |
| 120 | + |
| 121 | + echo "Running openstack-dashboard (django website) tests" |
| 122 | + cd openstack-dashboard |
| 123 | + cp local/local_settings.py.example local/local_settings.py |
| 124 | + ${dashboard_wrapper} coverage run dashboard/manage.py test |
| 125 | + # get results of the openstack-dashboard tests |
| 126 | + DASHBOARD_RESULT=$? |
| 127 | + cd .. |
| 128 | + |
| 129 | + echo "Generating coverage reports" |
| 130 | + ${django_wrapper} coverage combine |
| 131 | + ${django_wrapper} coverage xml --omit='/usr*,setup.py,*egg*' |
| 132 | + ${django_wrapper} coverage html --omit='/usr*,setup.py,*egg*' -d reports |
| 133 | + exit $(($OPENSTACK_RESULT || $DASHBOARD_RESULT)) |
| 134 | +} |
| 135 | + |
| 136 | +if [ $just_pep8 -eq 1 ]; then |
| 137 | + run_pep8 |
| 138 | + exit $? |
| 139 | +fi |
| 140 | + |
| 141 | +if [ $just_pylint -eq 1 ]; then |
| 142 | + run_pylint |
| 143 | + exit $? |
| 144 | +fi |
| 145 | + |
| 146 | +run_tests || exit |
0 commit comments