From 34e217b357457eadec9cc668b722fa7fd3f43ee9 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Wed, 9 Nov 2011 12:32:54 -0800 Subject: [PATCH] Added sanity checks and environment versioning to run_tests.sh. Implements blueprint environment-versioning. Fixed bug 887885. The script will bail if the seleniumrc or test scripts are missing, preventing the hang, or the possibility of bad environments. Change-Id: I3cdeb71660c897e8b2adbf81d3794333d1847204 --- .gitignore | 1 + horizon/horizon/tests/testsettings.py | 2 +- openstack-dashboard/dashboard/tests.py | 1 + openstack-dashboard/dashboard/views.py | 2 - run_tests.sh | 122 ++++++++++++++++++------- 5 files changed, 92 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index b56094fe7f..ac626da47e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.pyc *.swp +.environment_version .selenium_log .coverage coverage.xml diff --git a/horizon/horizon/tests/testsettings.py b/horizon/horizon/tests/testsettings.py index c769150b4c..37fb982743 100644 --- a/horizon/horizon/tests/testsettings.py +++ b/horizon/horizon/tests/testsettings.py @@ -27,7 +27,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '/tmp/horizon.db', - 'TEST_NAME': '/tmp/test_horizon.db',}} + 'TEST_NAME': '/tmp/test_horizon.db'}} INSTALLED_APPS = ( 'django.contrib.sessions', diff --git a/openstack-dashboard/dashboard/tests.py b/openstack-dashboard/dashboard/tests.py index 5482e0f44b..050aa94b47 100644 --- a/openstack-dashboard/dashboard/tests.py +++ b/openstack-dashboard/dashboard/tests.py @@ -1,6 +1,7 @@ from django import test from noseselenium.cases import SeleniumTestCaseMixin + class SeleniumTests(test.TestCase, SeleniumTestCaseMixin): def test_splash(self): self.selenium.open("/") diff --git a/openstack-dashboard/dashboard/views.py b/openstack-dashboard/dashboard/views.py index fbbfcaa53b..bd4bd0be5d 100644 --- a/openstack-dashboard/dashboard/views.py +++ b/openstack-dashboard/dashboard/views.py @@ -46,5 +46,3 @@ def splash(request): return handled return shortcuts.render(request, 'splash.html', {'form': form}) - - diff --git a/run_tests.sh b/run_tests.sh index fe6a1e0d7d..87360c0b02 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,5 +1,14 @@ #!/bin/bash +set -o errexit + +# ---------------UPDATE ME-------------------------------# +# Increment me any time the environment should be rebuilt. +# This includes dependncy changes, directory renames, etc. +# Simple integer secuence: 1, 2, 3... +environment_version=1 +#--------------------------------------------------------# + function usage { echo "Usage: $0 [OPTION]..." echo "Run Horizon's test suite(s)" @@ -14,6 +23,7 @@ function usage { echo " been added." echo " -p, --pep8 Just run pep8" echo " -y, --pylint Just run pylint" + echo " -q, --quiet Run non-interactively. (Relatively) quiet." echo " --skip-selenium Run unit tests but skip Selenium tests" echo " --runserver Run the Django development server for" echo " openstack-dashboard in the virtual" @@ -31,15 +41,16 @@ function usage { function process_option { case "$1" in -h|--help) usage;; - -V|--virtual-env) let always_venv=1; let never_venv=0;; - -N|--no-virtual-env) let always_venv=0; let never_venv=1;; - -p|--pep8) let just_pep8=1;; - -y|--pylint) let just_pylint=1;; - -f|--force) let force=1;; - -c|--coverage) let with_coverage=1;; - --skip-selenium) let selenium=-1;; - --docs) let just_docs=1;; - --runserver) let runserver=1;; + -V|--virtual-env) always_venv=1; never_venv=0;; + -N|--no-virtual-env) always_venv=0; never_venv=1;; + -p|--pep8) just_pep8=1;; + -y|--pylint) just_pylint=1;; + -f|--force) force=1;; + -q|--quiet) quiet=1;; + -c|--coverage) with_coverage=1;; + --skip-selenium) selenium=-1;; + --docs) just_docs=1;; + --runserver) runserver=1;; *) testargs="$testargs $1" esac } @@ -65,13 +76,14 @@ function run_pylint { function run_pep8 { echo "Running pep8 ..." + rm -f pep8.txt PEP8_EXCLUDE=vcsversion.py PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat" PEP8_INCLUDE="openstack-dashboard/dashboard horizon/horizon" echo "${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt" #${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt #perl string strips out the [ and ] characters - ${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE | perl -ple 's/: ([WE]\d+)/: [$1]/' > pep8.txt + ${django_wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE > pep8.txt } function run_sphinx { @@ -99,12 +111,64 @@ just_pep8=0 just_pylint=0 just_docs=0 runserver=0 +quiet=0 # PROCESS ARGUMENTS, OVERRIDE DEFAULTS for arg in "$@"; do process_option $arg done +function environment_check { + echo "Checking environment." + if [ -f .environment_version ]; then + ENV_VERS=`cat .environment_version` + if [ $ENV_VERS -eq $environment_version ]; then + echo "Environment is up to date." + return 0 + fi + fi + if [ $quiet -eq 1 ]; then + install_venv + else + # If we didn't pass our check, ask about upgrading the environment. + echo -e "Your environment appears to be out of date. Update? (Y/n) \c" + read update_env + if [ "x$update_env" = "xY" -o "x$update_env" = "x" -o "x$update_env" = "xy" ]; then + install_venv + fi + fi +} + +function sanity_check { + # Anything that should be determined prior to running the tests, server, etc. + if [ ! -f horizon/bin/test ]; then + echo "Error: Test script not found at horizon/bin/test. Did buildout succeed?" + exit 1 + fi + if [ ! -f horizon/bin/coverage ]; then + echo "Error: Coverage script not found at horizon/bin/coverage. Did buildout succeed?" + exit 1 + fi + if [ ! -f horizon/bin/seleniumrc ]; then + echo "Error: Selenium script not found at horizon/bin/seleniumrc. Did buildout succeed?" + exit 1 + fi +} + +function install_venv { + cd openstack-dashboard + python tools/install_venv.py + cd .. + cd horizon + python bootstrap.py + bin/buildout + cd .. + django_wrapper="${django_with_venv}" + dashboard_wrapper="${dashboard_with_venv}" + sanity_check + echo $environment_version > .environment_version +} + if [ $never_venv -eq 0 ] then # Remove the virtual environment if --force used @@ -118,29 +182,17 @@ then else if [ $always_venv -eq 1 ]; then # Automatically install the virtualenv - cd openstack-dashboard - python tools/install_venv.py - cd .. - cd horizon - python bootstrap.py - bin/buildout - cd .. - django_wrapper="${django_with_venv}" - dashboard_wrapper="${dashboard_with_venv}" + install_venv else - echo -e "No virtual environment found...create one? (Y/n) \c" - read use_ve - if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then - # Install the virtualenv and run the test suite in it - cd openstack-dashboard - python tools/install_venv.py - cd .. - cd horizon - python bootstrap.py - bin/buildout - cd .. - django_wrapper="${django_with_venv}" - dashboard_wrapper="${dashboard_with_venv}" + if [ $quiet -eq 1 ]; then + echo -e "No virtual environment found...create one? (Y/n) \c" + read use_ve + if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then + # Install the virtualenv and run the test suite in it + install_venv + fi + else + install_venv fi fi fi @@ -159,6 +211,8 @@ function wait_for_selenium { } function run_tests { + sanity_check + if [ $selenium -eq 0 ]; then echo "Starting Selenium server..." ${django_wrapper} horizon/bin/seleniumrc > .selenium_log & @@ -208,12 +262,14 @@ function run_tests { kill `echo "${SELENIUM_JOB}" | awk '{print $4}'` echo "Selenium process stopped." else - echo "Selenium process not found. This may require manual claenup." + echo "Selenium process not found. This may require manual cleanup." fi rm -f .selenium_log fi } +environment_check + if [ $just_docs -eq 1 ]; then run_sphinx exit $?