From b76d43e8c60bcb3060ee4ee99b6fac8acf0650fb Mon Sep 17 00:00:00 2001 From: Hugh Saunders Date: Mon, 16 Mar 2015 15:26:32 +0000 Subject: [PATCH] Ensure return code passes through output trimming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the output of run-playbooks is filtered through an awk statement to reduce the verbosity of the output. The problem is that bash uses the return code from the right most command to determine the return code for the whole pipe. Awk successfully processes the run-playbooks output, even if run-playbooks fails, so awk returns 0, and the pipeline is assumed to have completed successfully. From the bash manual: "Each command in a pipeline is executed in its own subshell (see Command Execution Environment). The exit status of a pipeline is the exit status of the last command in the pipeline, unless the pipefail option is enabled (see The Set Builtin). If pipefail is enabled, the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. If the reserved word ‘!’ precedes the pipeline, the exit status is the logical negation of the exit status as described above. The shell waits for all commands in the pipeline to terminate before returning a value." By enabling pipefail, we can ensure that the pipeline exits non-zero if the run-playbooks script fails. Closes-bug: #1432295 Change-Id: I019141a7bfbcfa817b90e39f4ae1a68eb3f269a5 --- scripts/gate-check-commit.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/gate-check-commit.sh b/scripts/gate-check-commit.sh index 15fb5608c6..56ec18ce12 100755 --- a/scripts/gate-check-commit.sh +++ b/scripts/gate-check-commit.sh @@ -82,7 +82,9 @@ if [ "${RUN_PLAYBOOKS}" == "yes" ]; then print } " + set -o pipefail bash $(dirname ${0})/run-playbooks.sh | awk "${strip_debug}" + set +o pipefail fi # Run the tempest tests if required