| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
 | 2 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 3 | # **exercise.sh** | 
 | 4 |  | 
 | 5 | # Keep track of the current devstack directory. | 
 | 6 | TOP_DIR=$(cd $(dirname "$0") && pwd) | 
 | 7 |  | 
| Dean Troyer | 05530ca | 2012-07-06 15:09:10 -0500 | [diff] [blame] | 8 | # Import common functions | 
 | 9 | source $TOP_DIR/functions | 
 | 10 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 11 | # Load local configuration | 
 | 12 | source $TOP_DIR/stackrc | 
 | 13 |  | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 14 | # Run everything in the exercises/ directory that isn't explicitly disabled | 
 | 15 |  | 
 | 16 | # comma separated list of script basenames to skip | 
 | 17 | # to refrain from exercising euca.sh use SKIP_EXERCISES=euca | 
 | 18 | SKIP_EXERCISES=${SKIP_EXERCISES:-""} | 
 | 19 |  | 
| Russell Bryant | a845dde | 2013-03-07 15:16:01 -0500 | [diff] [blame] | 20 | # comma separated list of script basenames to run | 
 | 21 | # to run only euca.sh use RUN_EXERCISES=euca | 
 | 22 | basenames=${RUN_EXERCISES:-""} | 
 | 23 |  | 
 | 24 | EXERCISE_DIR=$TOP_DIR/exercises | 
 | 25 |  | 
 | 26 | if [ -z "${basenames}" ] ; then | 
 | 27 |     # Locate the scripts we should run | 
 | 28 |     basenames=$(for b in `ls $EXERCISE_DIR/*.sh`; do basename $b .sh; done) | 
 | 29 | else | 
 | 30 |     # If RUN_EXERCISES was specified, ignore SKIP_EXERCISES. | 
 | 31 |     SKIP_EXERCISES= | 
 | 32 | fi | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 33 |  | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 34 | # Track the state of each script | 
 | 35 | passes="" | 
 | 36 | failures="" | 
 | 37 | skips="" | 
 | 38 |  | 
 | 39 | # Loop over each possible script (by basename) | 
| Todd Willey | 0367cf1 | 2011-11-05 10:46:56 -0400 | [diff] [blame] | 40 | for script in $basenames; do | 
| Dean Troyer | a3b0255 | 2012-12-19 16:27:12 -0600 | [diff] [blame] | 41 |     if [[ ,$SKIP_EXERCISES, =~ ,$script, ]] ; then | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 42 |         skips="$skips $script" | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 43 |     else | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 44 |         echo "=====================================================================" | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 45 |         echo Running $script | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 46 |         echo "=====================================================================" | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 47 |         $EXERCISE_DIR/$script.sh | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 48 |         exitcode=$? | 
 | 49 |         if [[ $exitcode == 55 ]]; then | 
 | 50 |             skips="$skips $script" | 
 | 51 |         elif [[ $exitcode -ne 0 ]] ; then | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 52 |             failures="$failures $script" | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 53 |         else | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 54 |             passes="$passes $script" | 
| Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 55 |         fi | 
 | 56 |     fi | 
 | 57 | done | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 58 |  | 
 | 59 | # output status of exercise run | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 60 | echo "=====================================================================" | 
| Todd Willey | 0367cf1 | 2011-11-05 10:46:56 -0400 | [diff] [blame] | 61 | for script in $skips; do | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 62 |     echo SKIP $script | 
 | 63 | done | 
| Todd Willey | 0367cf1 | 2011-11-05 10:46:56 -0400 | [diff] [blame] | 64 | for script in $passes; do | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 65 |     echo PASS $script | 
 | 66 | done | 
| Todd Willey | 0367cf1 | 2011-11-05 10:46:56 -0400 | [diff] [blame] | 67 | for script in $failures; do | 
| Todd Willey | 9e9132d | 2011-11-04 12:09:54 -0400 | [diff] [blame] | 68 |     echo FAILED $script | 
 | 69 | done | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 70 | echo "=====================================================================" | 
| James E. Blair | c639ef0 | 2011-11-10 15:11:28 -0800 | [diff] [blame] | 71 |  | 
 | 72 | if [ -n "$failures" ] ; then | 
 | 73 |     exit 1 | 
 | 74 | fi |