exercise.sh
2599b316
 #!/usr/bin/env bash
 
27e32699
 # **exercise.sh**
 
dc97cb71
 # Keep track of the current DevStack directory.
27e32699
 TOP_DIR=$(cd $(dirname "$0") && pwd)
 
05530caf
 # Import common functions
 source $TOP_DIR/functions
 
27e32699
 # Load local configuration
 source $TOP_DIR/stackrc
 
2599b316
 # Run everything in the exercises/ directory that isn't explicitly disabled
 
 # comma separated list of script basenames to skip
dc97cb71
 # to refrain from exercising euca.sh use ``SKIP_EXERCISES=euca``
2599b316
 SKIP_EXERCISES=${SKIP_EXERCISES:-""}
 
a845dded
 # comma separated list of script basenames to run
dc97cb71
 # to run only euca.sh use ``RUN_EXERCISES=euca``
a845dded
 basenames=${RUN_EXERCISES:-""}
 
 EXERCISE_DIR=$TOP_DIR/exercises
 
cc6b4435
 if [[ -z "${basenames}" ]]; then
a845dded
     # Locate the scripts we should run
     basenames=$(for b in `ls $EXERCISE_DIR/*.sh`; do basename $b .sh; done)
 else
dc97cb71
     # If ``RUN_EXERCISES`` was specified, ignore ``SKIP_EXERCISES``.
a845dded
     SKIP_EXERCISES=
 fi
2599b316
 
9e9132dd
 # Track the state of each script
 passes=""
 failures=""
 skips=""
 
 # Loop over each possible script (by basename)
0367cf15
 for script in $basenames; do
cc6b4435
     if [[ ,$SKIP_EXERCISES, =~ ,$script, ]]; then
9e9132dd
         skips="$skips $script"
2599b316
     else
27e32699
         echo "====================================================================="
2599b316
         echo Running $script
27e32699
         echo "====================================================================="
9e9132dd
         $EXERCISE_DIR/$script.sh
408b009c
         exitcode=$?
         if [[ $exitcode == 55 ]]; then
             skips="$skips $script"
cc6b4435
         elif [[ $exitcode -ne 0 ]]; then
9e9132dd
             failures="$failures $script"
2599b316
         else
9e9132dd
             passes="$passes $script"
2599b316
         fi
     fi
 done
9e9132dd
 
dc97cb71
 # Output status of exercise run
27e32699
 echo "====================================================================="
0367cf15
 for script in $skips; do
9e9132dd
     echo SKIP $script
 done
0367cf15
 for script in $passes; do
9e9132dd
     echo PASS $script
 done
0367cf15
 for script in $failures; do
9e9132dd
     echo FAILED $script
 done
27e32699
 echo "====================================================================="
c639ef01
 
cc6b4435
 if [[ -n "$failures" ]]; then
c639ef01
     exit 1
 fi