From b171497466b95abf0f7f1243ee1eba14aba9c28b Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Mon, 19 Dec 2016 11:18:05 +0000 Subject: [PATCH] Ensure sanity checks exit early in case of a ping failure. --- test/sanity_check.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/sanity_check.sh b/test/sanity_check.sh index 217e4597..047d63f6 100755 --- a/test/sanity_check.sh +++ b/test/sanity_check.sh @@ -6,10 +6,20 @@ set -e whitely echo Ping each host from the other +# We wrap ping and echo in a function as we want the below parallel for loop +# to exit early in case of a failed ping, and it cannot be done concisely, +# e.g. using a one-liner, without losing the status code for ping. +function check_ping() { + local output=$(run_on $1 $PING $2) + local status=$? + echo $output + return $status +} + for host in $HOSTS; do for other in $HOSTS; do if [ "$host" != "$other" ]; then - echo $(run_on $host $PING $other) & + check_ping "$host" "$other" & pids="$pids $!" fi done