From 408b009ccda94a95d3b3999f6db2bd62e92cdfb9 Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Thu, 15 Mar 2012 23:21:55 +0000 Subject: [PATCH] Allow skipping exercises. - Catch a special exit signal 55 to notify that we want to skip an excercise. - Move is_enabled_service to functions. - Fix bug 928390. Change-Id: Iebf7a6f30a0f305a2a70173fb6b988bc07e34292 --- HACKING.rst | 4 ++++ exercise.sh | 5 ++++- exercises/swift.sh | 3 +++ functions | 24 +++++++++++++++++++++++- stack.sh | 24 ------------------------ 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index a105a66e9a..7262cff63d 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -136,6 +136,10 @@ These scripts are executed serially by ``exercise.sh`` in testing situations. FLOATING_IP=`euca-allocate-address | cut -f2` die_if_not_set FLOATING_IP "Failure allocating floating IP" +* If you want an exercise to be skipped when for example a service wasn't + enabled for the exercise to be run, you can exit your exercise with the + special exitcode 55 and it will be detected as skipped. + * The exercise scripts should only use the various OpenStack client binaries to interact with OpenStack. This specifically excludes any ``*-manage`` tools as those assume direct access to configuration and databases, as well as direct diff --git a/exercise.sh b/exercise.sh index 2072b23bef..15f264f4f8 100755 --- a/exercise.sh +++ b/exercise.sh @@ -32,7 +32,10 @@ for script in $basenames; do echo Running $script echo "=====================================================================" $EXERCISE_DIR/$script.sh - if [[ $? -ne 0 ]] ; then + exitcode=$? + if [[ $exitcode == 55 ]]; then + skips="$skips $script" + elif [[ $exitcode -ne 0 ]] ; then failures="$failures $script" else passes="$passes $script" diff --git a/exercises/swift.sh b/exercises/swift.sh index d8b41a330f..732445d350 100755 --- a/exercises/swift.sh +++ b/exercises/swift.sh @@ -36,6 +36,9 @@ source $TOP_DIR/exerciserc # Container name CONTAINER=ex-swift +# If swift is not enabled we exit with exitcode 55 which mean +# exercise is skipped. +is_service_enabled swift || exit 55 # Testing Swift # ============= diff --git a/functions b/functions index 7fd37c0011..75c20d7577 100644 --- a/functions +++ b/functions @@ -115,6 +115,28 @@ function git_clone { } +# is_service_enabled() checks if the service(s) specified as arguments are +# enabled by the user in **ENABLED_SERVICES**. +# +# If there are multiple services specified as arguments the test performs a +# boolean OR or if any of the services specified on the command line +# return true. +# +# There is a special cases for some 'catch-all' services:: +# **nova** returns true if any service enabled start with **n-** +# **glance** returns true if any service enabled start with **g-** +# **quantum** returns true if any service enabled start with **q-** +function is_service_enabled() { + services=$@ + for service in ${services}; do + [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0 + [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0 + [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0 + [[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0 + done + return 1 +} + # Test if the named environment variable is set and not zero length # is_set env-var @@ -151,4 +173,4 @@ function trueorfalse() { } # Restore xtrace -$XTRACE \ No newline at end of file +$XTRACE diff --git a/stack.sh b/stack.sh index d77b1d5fba..3a7fc5dafe 100755 --- a/stack.sh +++ b/stack.sh @@ -268,30 +268,6 @@ function read_password { set -o xtrace } -# is_service_enabled() checks if the service(s) specified as arguments are -# enabled by the user in **ENABLED_SERVICES**. -# -# If there are multiple services specified as arguments the test performs a -# boolean OR or if any of the services specified on the command line -# return true. -# -# There is a special cases for some 'catch-all' services:: -# **nova** returns true if any service enabled start with **n-** -# **glance** returns true if any service enabled start with **g-** -# **quantum** returns true if any service enabled start with **q-** - -function is_service_enabled() { - services=$@ - for service in ${services}; do - [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0 - [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0 - [[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0 - [[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0 - done - return 1 -} - - # Nova Network Configuration # --------------------------