Skip to content

Commit 408b009

Browse files
committed
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
1 parent 17ff976 commit 408b009

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

HACKING.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ These scripts are executed serially by ``exercise.sh`` in testing situations.
136136
FLOATING_IP=`euca-allocate-address | cut -f2`
137137
die_if_not_set FLOATING_IP "Failure allocating floating IP"
138138

139+
* If you want an exercise to be skipped when for example a service wasn't
140+
enabled for the exercise to be run, you can exit your exercise with the
141+
special exitcode 55 and it will be detected as skipped.
142+
139143
* The exercise scripts should only use the various OpenStack client binaries to
140144
interact with OpenStack. This specifically excludes any ``*-manage`` tools
141145
as those assume direct access to configuration and databases, as well as direct

exercise.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ for script in $basenames; do
3232
echo Running $script
3333
echo "====================================================================="
3434
$EXERCISE_DIR/$script.sh
35-
if [[ $? -ne 0 ]] ; then
35+
exitcode=$?
36+
if [[ $exitcode == 55 ]]; then
37+
skips="$skips $script"
38+
elif [[ $exitcode -ne 0 ]] ; then
3639
failures="$failures $script"
3740
else
3841
passes="$passes $script"

exercises/swift.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ source $TOP_DIR/exerciserc
3636
# Container name
3737
CONTAINER=ex-swift
3838

39+
# If swift is not enabled we exit with exitcode 55 which mean
40+
# exercise is skipped.
41+
is_service_enabled swift || exit 55
3942

4043
# Testing Swift
4144
# =============

functions

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ function git_clone {
115115
}
116116

117117

118+
# is_service_enabled() checks if the service(s) specified as arguments are
119+
# enabled by the user in **ENABLED_SERVICES**.
120+
#
121+
# If there are multiple services specified as arguments the test performs a
122+
# boolean OR or if any of the services specified on the command line
123+
# return true.
124+
#
125+
# There is a special cases for some 'catch-all' services::
126+
# **nova** returns true if any service enabled start with **n-**
127+
# **glance** returns true if any service enabled start with **g-**
128+
# **quantum** returns true if any service enabled start with **q-**
129+
function is_service_enabled() {
130+
services=$@
131+
for service in ${services}; do
132+
[[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
133+
[[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
134+
[[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
135+
[[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
136+
done
137+
return 1
138+
}
139+
118140

119141
# Test if the named environment variable is set and not zero length
120142
# is_set env-var
@@ -151,4 +173,4 @@ function trueorfalse() {
151173
}
152174

153175
# Restore xtrace
154-
$XTRACE
176+
$XTRACE

stack.sh

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -268,30 +268,6 @@ function read_password {
268268
set -o xtrace
269269
}
270270

271-
# is_service_enabled() checks if the service(s) specified as arguments are
272-
# enabled by the user in **ENABLED_SERVICES**.
273-
#
274-
# If there are multiple services specified as arguments the test performs a
275-
# boolean OR or if any of the services specified on the command line
276-
# return true.
277-
#
278-
# There is a special cases for some 'catch-all' services::
279-
# **nova** returns true if any service enabled start with **n-**
280-
# **glance** returns true if any service enabled start with **g-**
281-
# **quantum** returns true if any service enabled start with **q-**
282-
283-
function is_service_enabled() {
284-
services=$@
285-
for service in ${services}; do
286-
[[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
287-
[[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
288-
[[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
289-
[[ ${service} == "quantum" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
290-
done
291-
return 1
292-
}
293-
294-
295271
# Nova Network Configuration
296272
# --------------------------
297273

0 commit comments

Comments
 (0)