Ensure return code passes through output trimming

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
This commit is contained in:
Hugh Saunders 2015-03-16 15:26:32 +00:00
parent af64fa9f1f
commit b76d43e8c6

View File

@ -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