diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-12-31 19:35:17 +0100 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-01-08 00:43:04 +0100 |
commit | 2b7c862e8c668d8fabc784680b05bec75baff2c6 (patch) | |
tree | 689c0b55659d49b2644672c3f71973b52c9371e4 /mcp/scripts | |
parent | f25c19f7a3f90f2cf11f1352772756dadbe95bcc (diff) |
lib.sh: Extend wait_for function to catch no resp
wait_for function should be able to also check for minions that did
not return or not respond, in addition to the return code.
To keep it backwards compatible, condition the new check on the max
attempt number being specified in decimal format (e.g. '10.0' unlike
old '10').
Change-Id: If2512cf9121cdd795638efe7362ef0485d4e8d91
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
(cherry picked from commit 3f559299c232bbb7639d02243c95d6256cdf94d4)
Diffstat (limited to 'mcp/scripts')
-rw-r--r-- | mcp/scripts/lib.sh | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh index e32f99511..210288022 100644 --- a/mcp/scripts/lib.sh +++ b/mcp/scripts/lib.sh @@ -436,13 +436,21 @@ function wait_for { local total_attempts=$1; shift local cmdstr=$* local sleep_time=10 - echo "[NOTE] Waiting for cmd to return success: ${cmdstr}" + echo "[wait_for] Waiting for cmd to return success: ${cmdstr}" # shellcheck disable=SC2034 for attempt in $(seq "${total_attempts}"); do - # shellcheck disable=SC2015 - eval "${cmdstr}" && return 0 || true + echo "[wait_for] Attempt ${attempt}/${total_attempts%.*} for: ${cmdstr}" + if [ "${total_attempts%.*}" = "${total_attempts}" ]; then + # shellcheck disable=SC2015 + eval "${cmdstr}" && echo "[wait_for] OK: ${cmdstr}" && return 0 || true + else + ( eval "${cmdstr}" || echo __fuel_wf_failure__ ) |& tee /dev/stderr | \ + grep -Eq '(Not connected|No response|__fuel_wf_failure__)' || \ + echo "[wait_for] OK: ${cmdstr}" && return 0 + fi echo -n '.'; sleep "${sleep_time}" done + echo "[wait_for] ERROR: Failed after max attempts: ${cmdstr}" return 1 ) } |