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 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 5 | # Keep track of the current DevStack directory. |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 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 |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 17 | # to refrain from exercising euca.sh use ``SKIP_EXERCISES=euca`` |
Todd Willey | 2599b31 | 2011-11-04 10:31:37 -0400 | [diff] [blame] | 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 |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 21 | # to run only euca.sh use ``RUN_EXERCISES=euca`` |
Russell Bryant | a845dde | 2013-03-07 15:16:01 -0500 | [diff] [blame] | 22 | basenames=${RUN_EXERCISES:-""} |
| 23 | |
| 24 | EXERCISE_DIR=$TOP_DIR/exercises |
| 25 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 26 | if [[ -z "${basenames}" ]]; then |
Russell Bryant | a845dde | 2013-03-07 15:16:01 -0500 | [diff] [blame] | 27 | # Locate the scripts we should run |
| 28 | basenames=$(for b in `ls $EXERCISE_DIR/*.sh`; do basename $b .sh; done) |
| 29 | else |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 30 | # If ``RUN_EXERCISES`` was specified, ignore ``SKIP_EXERCISES``. |
Russell Bryant | a845dde | 2013-03-07 15:16:01 -0500 | [diff] [blame] | 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 | cc6b443 | 2013-04-08 15:38:03 -0500 | [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" |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 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 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 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 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 72 | if [[ -n "$failures" ]]; then |
James E. Blair | c639ef0 | 2011-11-10 15:11:28 -0800 | [diff] [blame] | 73 | exit 1 |
| 74 | fi |