| ... | ... |
@@ -9,7 +9,7 @@ set -o pipefail |
| 9 | 9 |
STARTTIME=$(date +%s) |
| 10 | 10 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 11 | 11 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 12 |
-os::log::install_errexit |
|
| 12 |
+os::log::stacktrace::install |
|
| 13 | 13 |
|
| 14 | 14 |
platforms=( "${OS_CROSS_COMPILE_PLATFORMS[@]}" )
|
| 15 | 15 |
if [[ -n "${OS_ONLY_BUILD_PLATFORMS-}" ]]; then
|
| ... | ... |
@@ -9,7 +9,7 @@ set -o pipefail |
| 9 | 9 |
STARTTIME=$(date +%s) |
| 10 | 10 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 11 | 11 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 12 |
-os::log::install_errexit |
|
| 12 |
+os::log::stacktrace::install |
|
| 13 | 13 |
|
| 14 | 14 |
# only works on Linux for now, all other platforms must build binaries themselves |
| 15 | 15 |
if [[ -z "$@" ]]; then |
| ... | ... |
@@ -15,7 +15,7 @@ STARTTIME=$(date +%s) |
| 15 | 15 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 16 | 16 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 17 | 17 |
source "${OS_ROOT}/contrib/node/install-sdn.sh"
|
| 18 |
-os::log::install_errexit |
|
| 18 |
+os::log::stacktrace::install |
|
| 19 | 19 |
|
| 20 | 20 |
# Go to the top of the tree. |
| 21 | 21 |
cd "${OS_ROOT}"
|
| ... | ... |
@@ -252,7 +252,7 @@ function os::build::build_static_binaries() {
|
| 252 | 252 |
} |
| 253 | 253 |
readonly -f os::build::build_static_binaries |
| 254 | 254 |
|
| 255 |
-# Build binaries targets specified |
|
| 255 |
+# Build binary targets specified |
|
| 256 | 256 |
# |
| 257 | 257 |
# Input: |
| 258 | 258 |
# $@ - targets and go flags. If no targets are set then all binaries targets |
| ... | ... |
@@ -260,8 +260,19 @@ readonly -f os::build::build_static_binaries |
| 260 | 260 |
# OS_BUILD_PLATFORMS - Incoming variable of targets to build for. If unset |
| 261 | 261 |
# then just the host architecture is built. |
| 262 | 262 |
function os::build::build_binaries() {
|
| 263 |
+ local -a binaries=( "$@" ) |
|
| 263 | 264 |
# Create a sub-shell so that we don't pollute the outer environment |
| 264 |
- ( |
|
| 265 |
+ ( os::build::internal::build_binaries "${binaries[@]+"${binaries[@]}"}" )
|
|
| 266 |
+} |
|
| 267 |
+ |
|
| 268 |
+# Build binary targets specified. Should always be run in a sub-shell so we don't leak GOBIN |
|
| 269 |
+# |
|
| 270 |
+# Input: |
|
| 271 |
+# $@ - targets and go flags. If no targets are set then all binaries targets |
|
| 272 |
+# are built. |
|
| 273 |
+# OS_BUILD_PLATFORMS - Incoming variable of targets to build for. If unset |
|
| 274 |
+# then just the host architecture is built. |
|
| 275 |
+os::build::internal::build_binaries() {
|
|
| 265 | 276 |
# Check for `go` binary and set ${GOPATH}.
|
| 266 | 277 |
os::build::setup_env |
| 267 | 278 |
|
| ... | ... |
@@ -328,7 +339,6 @@ function os::build::build_binaries() {
|
| 328 | 328 |
"$(dirname ${test})"
|
| 329 | 329 |
done |
| 330 | 330 |
done |
| 331 |
- ) |
|
| 332 | 331 |
} |
| 333 | 332 |
readonly -f os::build::build_binaries |
| 334 | 333 |
|
| ... | ... |
@@ -8,7 +8,7 @@ set -o pipefail |
| 8 | 8 |
|
| 9 | 9 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 10 | 10 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 11 |
-os::log::install_errexit |
|
| 11 |
+os::log::stacktrace::install |
|
| 12 | 12 |
|
| 13 | 13 |
etcd_version=$(go run ${OS_ROOT}/tools/godepversion/godepversion.go ${OS_ROOT}/Godeps/Godeps.json github.com/coreos/etcd/etcdserver)
|
| 14 | 14 |
|
| 15 | 15 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,100 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+# |
|
| 2 |
+# This library contains an implementation of a stack trace for Bash scripts. |
|
| 3 |
+ |
|
| 4 |
+# os::log::stacktrace::install installs the stacktrace as a handler for the ERR signal if one |
|
| 5 |
+# has not already been installed and sets `set -o errtrace` in order to propagate the handler |
|
| 6 |
+# If the ERR trap is not initialized, installing this plugin will initialize it. |
|
| 7 |
+# |
|
| 8 |
+# Globals: |
|
| 9 |
+# None |
|
| 10 |
+# Arguments: |
|
| 11 |
+# None |
|
| 12 |
+# Returns: |
|
| 13 |
+# - export OS_USE_STACKTRACE |
|
| 14 |
+function os::log::stacktrace::install() {
|
|
| 15 |
+ # setting 'errtrace' propagates our ERR handler to functions, expansions and subshells |
|
| 16 |
+ set -o errtrace |
|
| 17 |
+ |
|
| 18 |
+ # OS_USE_STACKTRACE is read by os::util::trap at runtime to request a stacktrace |
|
| 19 |
+ export OS_USE_STACKTRACE=true |
|
| 20 |
+ |
|
| 21 |
+ os::util::trap::init_err |
|
| 22 |
+} |
|
| 23 |
+readonly -f os::log::stacktrace::install |
|
| 24 |
+ |
|
| 25 |
+# os::log::stacktrace::print prints the stacktrace and exits with the return code from the script that |
|
| 26 |
+# called for a stack trace. This function will always return 0 if it is not handling the signal, and if it |
|
| 27 |
+# is handling the signal, this function will always `exit`, not return, the return code it receives as |
|
| 28 |
+# its first argument. |
|
| 29 |
+# |
|
| 30 |
+# Globals: |
|
| 31 |
+# - BASH_SOURCE |
|
| 32 |
+# - BASH_LINENO |
|
| 33 |
+# - FUNCNAME |
|
| 34 |
+# Arguments: |
|
| 35 |
+# - 1: the return code of the command in the script that generated the ERR signal |
|
| 36 |
+# - 2: the last command that ran before handlers were invoked |
|
| 37 |
+# - 3: whether or not `set -o errexit` was set in the script that generated the ERR signal |
|
| 38 |
+# Returns: |
|
| 39 |
+# None |
|
| 40 |
+function os::log::stacktrace::print() {
|
|
| 41 |
+ local return_code=$1 |
|
| 42 |
+ local last_command=$2 |
|
| 43 |
+ local errexit_set=${3:-}
|
|
| 44 |
+ set -- |
|
| 45 |
+ |
|
| 46 |
+ # evaulate all of the variables in the last command literal so we have a useful stacktrace |
|
| 47 |
+ # this will *not* be able to capture positional variables ($1, $@, $*) or variables declared |
|
| 48 |
+ # in this scope or in the trap handler ($return_code, $last_command, $errexit_set) |
|
| 49 |
+ # Furthermore, since it is possible that the failure in the last command itself was an unset |
|
| 50 |
+ # variable, we need to turn off that check to ensure we're not re-triggering it here. |
|
| 51 |
+ set +o nounset |
|
| 52 |
+ local -r last_command_with_vars="$( eval "echo \"${last_command}\"" )"
|
|
| 53 |
+ set -o nounset |
|
| 54 |
+ |
|
| 55 |
+ if [[ "${return_code}" = "0" ]]; then
|
|
| 56 |
+ # we're not supposed to respond when no error has occurred |
|
| 57 |
+ return 0 |
|
| 58 |
+ fi |
|
| 59 |
+ |
|
| 60 |
+ if [[ -z "${errexit_set}" ]]; then
|
|
| 61 |
+ # if errexit wasn't set in the shell when the ERR signal was issued, then we can ignore the signal |
|
| 62 |
+ # as this is not cause for failure |
|
| 63 |
+ return 0 |
|
| 64 |
+ fi |
|
| 65 |
+ |
|
| 66 |
+ # iterate backwards through the stack until we leave library files, so we can be sure we start logging |
|
| 67 |
+ # actual script code and not this handler's call |
|
| 68 |
+ local stack_begin_index |
|
| 69 |
+ for (( stack_begin_index = 0; stack_begin_index < ${#BASH_SOURCE[@]}; stack_begin_index++ )); do
|
|
| 70 |
+ if [[ ! "${BASH_SOURCE[${stack_begin_index}]}" =~ hack/lib/(log/stacktrace|util/trap)\.sh ]]; then
|
|
| 71 |
+ break |
|
| 72 |
+ fi |
|
| 73 |
+ done |
|
| 74 |
+ |
|
| 75 |
+ local preamble_finished |
|
| 76 |
+ local stack_index=1 |
|
| 77 |
+ local i |
|
| 78 |
+ for (( i = stack_begin_index; i < ${#BASH_SOURCE[@]}; i++ )); do
|
|
| 79 |
+ local bash_source |
|
| 80 |
+ bash_source="$( os::util::repository_relative_path "${BASH_SOURCE[$i]}" )"
|
|
| 81 |
+ if [[ -z "${preamble_finished:-}" ]]; then
|
|
| 82 |
+ preamble_finished=true |
|
| 83 |
+ os::log::error "PID ${BASHPID:-$$}: ${bash_source}:${BASH_LINENO[$i-1]}: \`${last_command}\` exited with status ${return_code}." >&2
|
|
| 84 |
+ os::log::error "Command with variables substituted is: " |
|
| 85 |
+ os::log::error $'\t'"${last_command_with_vars}"
|
|
| 86 |
+ os::log::info $'\t\t'"Stack Trace: " >&2 |
|
| 87 |
+ os::log::info $'\t\t'" ${stack_index}: ${bash_source}:${BASH_LINENO[$i-1]}: \`${last_command}\`" >&2
|
|
| 88 |
+ else |
|
| 89 |
+ os::log::info $'\t\t'" ${stack_index}: ${bash_source}:${BASH_LINENO[$i-1]}: ${FUNCNAME[$i-1]}" >&2
|
|
| 90 |
+ fi |
|
| 91 |
+ stack_index=$(( stack_index + 1 )) |
|
| 92 |
+ done |
|
| 93 |
+ |
|
| 94 |
+ # we know we're the privileged handler in this chain, so we can safely exit the shell without |
|
| 95 |
+ # starving another handler of the privilege of reacting to this signal |
|
| 96 |
+ os::log::info " Exiting with code ${return_code}." >&2
|
|
| 97 |
+ exit "${return_code}"
|
|
| 98 |
+} |
|
| 99 |
+readonly -f os::log::stacktrace::print |
|
| 0 | 100 |
\ No newline at end of file |
| 1 | 101 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,96 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+# |
|
| 2 |
+# This library holds miscellaneous utility functions. If there begin to be groups of functions in this |
|
| 3 |
+# file that share intent or are thematically similar, they should be split into their own files. |
|
| 4 |
+ |
|
| 5 |
+# os::util::describe_return_code describes an exit code |
|
| 6 |
+# |
|
| 7 |
+# Globals: |
|
| 8 |
+# - OS_SCRIPT_START_TIME |
|
| 9 |
+# Arguments: |
|
| 10 |
+# - 1: exit code to describe |
|
| 11 |
+# Returns: |
|
| 12 |
+# None |
|
| 13 |
+function os::util::describe_return_code() {
|
|
| 14 |
+ local return_code=$1 |
|
| 15 |
+ |
|
| 16 |
+ if [[ "${return_code}" = "0" ]]; then
|
|
| 17 |
+ echo -n "[INFO] $0 succeeded " |
|
| 18 |
+ else |
|
| 19 |
+ echo -n "[ERROR] $0 failed " |
|
| 20 |
+ fi |
|
| 21 |
+ |
|
| 22 |
+ if [[ -n "${OS_SCRIPT_START_TIME:-}" ]]; then
|
|
| 23 |
+ local end_time |
|
| 24 |
+ end_time="$(date +%s)" |
|
| 25 |
+ local elapsed_time |
|
| 26 |
+ elapsed_time="$(( end_time - OS_SCRIPT_START_TIME ))" |
|
| 27 |
+ local formatted_time |
|
| 28 |
+ formatted_time="$( os::util::format_seconds "${elapsed_time}" )"
|
|
| 29 |
+ echo "after ${formatted_time}"
|
|
| 30 |
+ else |
|
| 31 |
+ echo |
|
| 32 |
+ fi |
|
| 33 |
+} |
|
| 34 |
+readonly -f os::util::describe_return_code |
|
| 35 |
+ |
|
| 36 |
+# os::util::install_describe_return_code installs the return code describer for the EXIT trap |
|
| 37 |
+# If the EXIT trap is not initialized, installing this plugin will initialize it. |
|
| 38 |
+# |
|
| 39 |
+# Globals: |
|
| 40 |
+# None |
|
| 41 |
+# Arguments: |
|
| 42 |
+# None |
|
| 43 |
+# Returns: |
|
| 44 |
+# - export OS_DESCRIBE_RETURN_CODE |
|
| 45 |
+# - export OS_SCRIPT_START_TIME |
|
| 46 |
+function os::util::install_describe_return_code() {
|
|
| 47 |
+ export OS_DESCRIBE_RETURN_CODE="true" |
|
| 48 |
+ OS_SCRIPT_START_TIME="$( date +%s )"; export OS_SCRIPT_START_TIME |
|
| 49 |
+ os::util::trap::init_exit |
|
| 50 |
+} |
|
| 51 |
+readonly -f os::util::install_describe_return_code |
|
| 52 |
+ |
|
| 53 |
+# os::util::repository_relative_path returns the relative path from the $OS_ROOT directory to the |
|
| 54 |
+# given file, if the file is inside of the $OS_ROOT directory. If the file is outside of $OS_ROOT, |
|
| 55 |
+# this function will return the absolute path to the file |
|
| 56 |
+# |
|
| 57 |
+# Globals: |
|
| 58 |
+# - OS_ROOT |
|
| 59 |
+# Arguments: |
|
| 60 |
+# - 1: the path to relativize |
|
| 61 |
+# Returns: |
|
| 62 |
+# None |
|
| 63 |
+function os::util::repository_relative_path() {
|
|
| 64 |
+ local filename=$1 |
|
| 65 |
+ |
|
| 66 |
+ if which realpath >/dev/null 2>&1; then |
|
| 67 |
+ local trim_path |
|
| 68 |
+ trim_path="$( realpath "${OS_ROOT}" )/"
|
|
| 69 |
+ filename="$( realpath "${filename}" )"
|
|
| 70 |
+ filename="${filename##*${trim_path}}"
|
|
| 71 |
+ fi |
|
| 72 |
+ |
|
| 73 |
+ echo "${filename}"
|
|
| 74 |
+} |
|
| 75 |
+readonly -f os::util::repository_relative_path |
|
| 76 |
+ |
|
| 77 |
+# os::util::format_seconds formats a duration of time in seconds to print in HHh MMm SSs |
|
| 78 |
+# |
|
| 79 |
+# Globals: |
|
| 80 |
+# None |
|
| 81 |
+# Arguments: |
|
| 82 |
+# - 1: time in seconds to format |
|
| 83 |
+# Return: |
|
| 84 |
+# None |
|
| 85 |
+function os::util::format_seconds() {
|
|
| 86 |
+ local raw_seconds=$1 |
|
| 87 |
+ |
|
| 88 |
+ local hours minutes seconds |
|
| 89 |
+ (( hours=raw_seconds/3600 )) |
|
| 90 |
+ (( minutes=(raw_seconds%3600)/60 )) |
|
| 91 |
+ (( seconds=raw_seconds%60 )) |
|
| 92 |
+ |
|
| 93 |
+ printf '%02dh %02dm %02ds' "${hours}" "${minutes}" "${seconds}"
|
|
| 94 |
+} |
|
| 95 |
+readonly -f os::util::format_seconds |
|
| 0 | 96 |
\ No newline at end of file |
| 1 | 97 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,99 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+# |
|
| 2 |
+# This library defines the trap handlers for the ERR and EXIT signals. Any new handler for these signals |
|
| 3 |
+# must be added to these handlers and activated by the environment variable mechanism that the rest use. |
|
| 4 |
+# These functions ensure that no handler can ever alter the exit code that was emitted by a command |
|
| 5 |
+# in a test script. |
|
| 6 |
+ |
|
| 7 |
+# os::util::trap::init_err initializes the privileged handler for the ERR signal if it hasn't |
|
| 8 |
+# been registered already. This will overwrite any other handlers registered on the signal. |
|
| 9 |
+# |
|
| 10 |
+# Globals: |
|
| 11 |
+# None |
|
| 12 |
+# Arguments: |
|
| 13 |
+# None |
|
| 14 |
+# Returns: |
|
| 15 |
+# None |
|
| 16 |
+function os::util::trap::init_err() {
|
|
| 17 |
+ if ! trap -p ERR | grep -q 'os::util::trap::err_handler'; then |
|
| 18 |
+ trap 'os::util::trap::err_handler;' ERR |
|
| 19 |
+ fi |
|
| 20 |
+} |
|
| 21 |
+readonly -f os::util::trap::init_err |
|
| 22 |
+ |
|
| 23 |
+# os::util::trap::init_exit initializes the privileged handler for the EXIT signal if it hasn't |
|
| 24 |
+# been registered already. This will overwrite any other handlers registered on the signal. |
|
| 25 |
+# |
|
| 26 |
+# Globals: |
|
| 27 |
+# None |
|
| 28 |
+# Arguments: |
|
| 29 |
+# None |
|
| 30 |
+# Returns: |
|
| 31 |
+# None |
|
| 32 |
+function os::util::trap::init_exit() {
|
|
| 33 |
+ if ! trap -p EXIT | grep -q 'os::util::trap::exit_handler'; then |
|
| 34 |
+ trap 'os::util::trap::exit_handler;' EXIT |
|
| 35 |
+ fi |
|
| 36 |
+} |
|
| 37 |
+readonly -f os::util::trap::init_exit |
|
| 38 |
+ |
|
| 39 |
+# os::util::trap::err_handler is the handler for the ERR signal. |
|
| 40 |
+# |
|
| 41 |
+# Globals: |
|
| 42 |
+# - OS_TRAP_DEBUG |
|
| 43 |
+# - OS_USE_STACKTRACE |
|
| 44 |
+# Arguments: |
|
| 45 |
+# None |
|
| 46 |
+# Returns: |
|
| 47 |
+# - returns original return code, allows privileged handler to exit if necessary |
|
| 48 |
+function os::util::trap::err_handler() {
|
|
| 49 |
+ local -r return_code=$? |
|
| 50 |
+ local -r last_command="${BASH_COMMAND}"
|
|
| 51 |
+ |
|
| 52 |
+ if set +o | grep -q '\-o errexit'; then |
|
| 53 |
+ local -r errexit_set=true |
|
| 54 |
+ fi |
|
| 55 |
+ |
|
| 56 |
+ if [[ "${OS_TRAP_DEBUG:-}" = "true" ]]; then
|
|
| 57 |
+ echo "[DEBUG] Error handler executing with return code \`${return_code}\`, last command \`${last_command}\`, and errexit set \`${errexit_set:-}\`"
|
|
| 58 |
+ fi |
|
| 59 |
+ |
|
| 60 |
+ if [[ "${OS_USE_STACKTRACE:-}" = "true" ]]; then
|
|
| 61 |
+ # the OpenShift stacktrace function is treated as a privileged handler for this signal |
|
| 62 |
+ # and is therefore allowed to run outside of a subshell in order to allow it to `exit` |
|
| 63 |
+ # if necessary |
|
| 64 |
+ os::log::stacktrace::print "${return_code}" "${last_command}" "${errexit_set:-}"
|
|
| 65 |
+ fi |
|
| 66 |
+ |
|
| 67 |
+ return "${return_code}"
|
|
| 68 |
+} |
|
| 69 |
+readonly -f os::util::trap::err_handler |
|
| 70 |
+ |
|
| 71 |
+# os::util::trap::exit_handler is the handler for the EXIT signal. |
|
| 72 |
+# |
|
| 73 |
+# Globals: |
|
| 74 |
+# - OS_TRAP_DEBUG |
|
| 75 |
+# - OS_DESCRIBE_RETURN_CODE |
|
| 76 |
+# Arguments: |
|
| 77 |
+# None |
|
| 78 |
+# Returns: |
|
| 79 |
+# - original exit code of the script that exited |
|
| 80 |
+function os::util::trap::exit_handler() {
|
|
| 81 |
+ local -r return_code=$? |
|
| 82 |
+ |
|
| 83 |
+ # we do not want these traps to be able to trigger more errors, we can let them fail silently |
|
| 84 |
+ set +o errexit |
|
| 85 |
+ |
|
| 86 |
+ if [[ "${OS_TRAP_DEBUG:-}" = "true" ]]; then
|
|
| 87 |
+ echo "[DEBUG] Exit handler executing with return code \`${return_code}\`"
|
|
| 88 |
+ fi |
|
| 89 |
+ |
|
| 90 |
+ # the following envars selectively enable optional exit traps, all of which are run inside of |
|
| 91 |
+ # a subshell in order to sandbox them and not allow them to influence how this script will exit |
|
| 92 |
+ if [[ "${OS_DESCRIBE_RETURN_CODE:-}" = "true" ]]; then
|
|
| 93 |
+ ( os::util::describe_return_code "${return_code}" )
|
|
| 94 |
+ fi |
|
| 95 |
+ |
|
| 96 |
+ exit "${return_code}"
|
|
| 97 |
+} |
|
| 98 |
+readonly -f os::util::trap::exit_handler |
|
| 0 | 99 |
\ No newline at end of file |
| ... | ... |
@@ -44,7 +44,7 @@ start_time=$(date +%s) |
| 44 | 44 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 45 | 45 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 46 | 46 |
cd "${OS_ROOT}"
|
| 47 |
-os::log::install_errexit |
|
| 47 |
+os::log::stacktrace::install |
|
| 48 | 48 |
os::build::setup_env |
| 49 | 49 |
os::util::environment::setup_tmpdir_vars "test-go" |
| 50 | 50 |
|
| ... | ... |
@@ -26,7 +26,7 @@ trap exit_trap EXIT |
| 26 | 26 |
start_time=$(date +%s) |
| 27 | 27 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 28 | 28 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 29 |
-os::log::install_errexit |
|
| 29 |
+os::log::stacktrace::install |
|
| 30 | 30 |
os::util::environment::setup_tmpdir_vars "test-lib" |
| 31 | 31 |
|
| 32 | 32 |
cd "${OS_ROOT}"
|
| ... | ... |
@@ -26,7 +26,7 @@ trap exit_trap EXIT |
| 26 | 26 |
start_time=$(date +%s) |
| 27 | 27 |
OS_ROOT="$( dirname "${BASH_SOURCE}" )"/../../..
|
| 28 | 28 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 29 |
-os::log::install_errexit |
|
| 29 |
+os::log::stacktrace::install |
|
| 30 | 30 |
|
| 31 | 31 |
# envars used to track these interactions are not propagated out of the subshells used to run these commands |
| 32 | 32 |
# therefore each os::cmd call is its own sandbox and complicated scenarios need to play out inside one call |
| ... | ... |
@@ -8,7 +8,7 @@ set -o pipefail |
| 8 | 8 |
|
| 9 | 9 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 10 | 10 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 11 |
-os::log::install_errexit |
|
| 11 |
+os::log::stacktrace::install |
|
| 12 | 12 |
trap os::test::junit::reconcile_output EXIT |
| 13 | 13 |
|
| 14 | 14 |
BASETMPDIR="${TMPDIR:-/tmp}/openshift/test-tools"
|
| ... | ... |
@@ -722,79 +722,6 @@ readonly -f disable-selinux |
| 722 | 722 |
# end of common functions for extended test group's run.sh scripts |
| 723 | 723 |
###### |
| 724 | 724 |
|
| 725 |
-# Handler for when we exit automatically on an error. |
|
| 726 |
-# Borrowed from https://gist.github.com/ahendrix/7030300 |
|
| 727 |
-function os::log::errexit() {
|
|
| 728 |
- local err="${PIPESTATUS[@]}"
|
|
| 729 |
- |
|
| 730 |
- # If the shell we are in doesn't have errexit set (common in subshells) then |
|
| 731 |
- # don't dump stacks. |
|
| 732 |
- set +o | grep -qe "-o errexit" || return |
|
| 733 |
- |
|
| 734 |
- set +o xtrace |
|
| 735 |
- local code="${1:-1}"
|
|
| 736 |
- os::log::error_exit "'${BASH_COMMAND}' exited with status $err" "${1:-1}" 1
|
|
| 737 |
-} |
|
| 738 |
-readonly -f os::log::errexit |
|
| 739 |
- |
|
| 740 |
-function os::log::install_errexit() {
|
|
| 741 |
- # trap ERR to provide an error handler whenever a command exits nonzero this |
|
| 742 |
- # is a more verbose version of set -o errexit |
|
| 743 |
- trap 'os::log::errexit' ERR |
|
| 744 |
- |
|
| 745 |
- # setting errtrace allows our ERR trap handler to be propagated to functions, |
|
| 746 |
- # expansions and subshells |
|
| 747 |
- set -o errtrace |
|
| 748 |
-} |
|
| 749 |
-readonly -f os::log::install_errexit |
|
| 750 |
- |
|
| 751 |
-# Print out the stack trace |
|
| 752 |
-# |
|
| 753 |
-# Args: |
|
| 754 |
-# $1 The number of stack frames to skip when printing. |
|
| 755 |
-function os::log::stack() {
|
|
| 756 |
- local stack_skip=${1:-0}
|
|
| 757 |
- stack_skip=$((stack_skip + 1)) |
|
| 758 |
- if [[ ${#FUNCNAME[@]} -gt $stack_skip ]]; then
|
|
| 759 |
- echo "Call stack:" >&2 |
|
| 760 |
- local i |
|
| 761 |
- for ((i=1 ; i <= ${#FUNCNAME[@]} - $stack_skip ; i++))
|
|
| 762 |
- do |
|
| 763 |
- local frame_no=$((i - 1 + stack_skip)) |
|
| 764 |
- local source_file=${BASH_SOURCE[$frame_no]}
|
|
| 765 |
- local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
|
|
| 766 |
- local funcname=${FUNCNAME[$frame_no]}
|
|
| 767 |
- echo " $i: ${source_file}:${source_lineno} ${funcname}(...)" >&2
|
|
| 768 |
- done |
|
| 769 |
- fi |
|
| 770 |
-} |
|
| 771 |
-readonly -f os::log::stack |
|
| 772 |
- |
|
| 773 |
-# Log an error and exit. |
|
| 774 |
-# Args: |
|
| 775 |
-# $1 Message to log with the error |
|
| 776 |
-# $2 The error code to return |
|
| 777 |
-# $3 The number of stack frames to skip when printing. |
|
| 778 |
-function os::log::error_exit() {
|
|
| 779 |
- local message="${1:-}"
|
|
| 780 |
- local code="${2:-1}"
|
|
| 781 |
- local stack_skip="${3:-0}"
|
|
| 782 |
- stack_skip=$((stack_skip + 1)) |
|
| 783 |
- |
|
| 784 |
- local source_file=${BASH_SOURCE[$stack_skip]}
|
|
| 785 |
- local source_line=${BASH_LINENO[$((stack_skip - 1))]}
|
|
| 786 |
- echo "!!! Error in ${source_file}:${source_line}" >&2
|
|
| 787 |
- [[ -z ${1-} ]] || {
|
|
| 788 |
- echo " ${1}" >&2
|
|
| 789 |
- } |
|
| 790 |
- |
|
| 791 |
- os::log::stack $stack_skip |
|
| 792 |
- |
|
| 793 |
- echo "Exiting with status ${code}" >&2
|
|
| 794 |
- exit "${code}"
|
|
| 795 |
-} |
|
| 796 |
-readonly -f os::log::error_exit |
|
| 797 |
- |
|
| 798 | 725 |
function os::log::with-severity() {
|
| 799 | 726 |
local msg=$1 |
| 800 | 727 |
local severity=$2 |
| ... | ... |
@@ -9,7 +9,7 @@ set -o pipefail |
| 9 | 9 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
|
| 10 | 10 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 11 | 11 |
|
| 12 |
-os::log::install_errexit |
|
| 12 |
+os::log::stacktrace::install |
|
| 13 | 13 |
|
| 14 | 14 |
# Open port scanning |
| 15 | 15 |
echo "[INFO] Checking open ports ('sudo openshift start' should already be running)"
|
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
os::test::junit::declare_suite_start "cmd/authentication" |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
os::test::junit::declare_suite_start "cmd/help" |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
os::test::junit::declare_suite_start "cmd/policy" |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -6,7 +6,7 @@ set -o pipefail |
| 6 | 6 |
|
| 7 | 7 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 8 | 8 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 9 |
-os::log::install_errexit |
|
| 9 |
+os::log::stacktrace::install |
|
| 10 | 10 |
trap os::test::junit::reconcile_output EXIT |
| 11 | 11 |
|
| 12 | 12 |
# Cleanup cluster resources created by this test |
| ... | ... |
@@ -9,7 +9,7 @@ set -o pipefail |
| 9 | 9 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 10 | 10 |
cd "${OS_ROOT}"
|
| 11 | 11 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 12 |
-os::log::install_errexit |
|
| 12 |
+os::log::stacktrace::install |
|
| 13 | 13 |
|
| 14 | 14 |
os::util::environment::setup_all_server_vars "test-extended-alternate-certs/" |
| 15 | 15 |
reset_tmp_dir |
| ... | ... |
@@ -11,7 +11,7 @@ set -o pipefail |
| 11 | 11 |
OS_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
| 12 | 12 |
cd "${OS_ROOT}"
|
| 13 | 13 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 14 |
-os::log::install_errexit |
|
| 14 |
+os::log::stacktrace::install |
|
| 15 | 15 |
|
| 16 | 16 |
os::util::environment::setup_all_server_vars "test-extended-alternate-launches/" |
| 17 | 17 |
reset_tmp_dir |
| ... | ... |
@@ -22,7 +22,7 @@ function os::test::extended::focus {
|
| 22 | 22 |
# be done in other contexts. |
| 23 | 23 |
function os::test::extended::setup {
|
| 24 | 24 |
source "${OS_ROOT}/hack/lib/init.sh"
|
| 25 |
- os::log::install_errexit |
|
| 25 |
+ os::log::stacktrace::install |
|
| 26 | 26 |
|
| 27 | 27 |
# build binaries |
| 28 | 28 |
if [[ -z $(os::build::find-binary ginkgo) ]]; then |