From 6eb3c34a17cf2ad0ceae8cdff55569b999369f13 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Wed, 30 Mar 2016 13:22:10 -0500 Subject: [PATCH] Ensure the OpenStack gate has access to the logs When the gate fails, for any reason, its possible the logs generated by the services are not accessible by the jenkins worker which does cause problems when the logs are uploaded for analysis. To ensure the gate always has access to the logs a trap was added to the gate script which is used to guarantee the gate has access to the logs by recursively setting the mode to 0777 on all files within the "/openstack/logs" directory. The function "gate_job_exit_tasks" has been added to the script-libraries.sh file Change-Id: I3eece015060dd99aceb7a39ca62c5cb1a0162421 Signed-off-by: Kevin Carter --- scripts/gate-check-commit.sh | 9 ++++++++- scripts/scripts-library.sh | 15 ++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scripts/gate-check-commit.sh b/scripts/gate-check-commit.sh index e812a30329..7a98e9fffd 100755 --- a/scripts/gate-check-commit.sh +++ b/scripts/gate-check-commit.sh @@ -24,11 +24,16 @@ export TESTR_OPTS=${TESTR_OPTS:-''} export PYTHONUNBUFFERED=1 # Extra options to pass to the AIO bootstrap process export BOOTSTRAP_OPTS=${BOOTSTRAP_OPTS:-''} +# This variable is being added to ensure the gate job executes an exit +# function at the end of the run. +export OSA_GATE_JOB=true ## Functions ----------------------------------------------------------------- info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh ## Main ---------------------------------------------------------------------- +# Set gate job exit traps, this is run regardless of exit state when the job finishes. +trap gate_job_exit_tasks EXIT # Log some data about the instance and the rest of the system log_instance_info @@ -80,8 +85,10 @@ pushd $(dirname ${0})/../tests bootstrap-aio.yml popd -# Implement the log directory link for openstack-infra log publishing +# Implement the log directory mkdir -p /openstack/log + +# Implement the log directory link for openstack-infra log publishing ln -sf /openstack/log $(dirname ${0})/../logs pushd $(dirname ${0})/../playbooks diff --git a/scripts/scripts-library.sh b/scripts/scripts-library.sh index ba93b80840..a9403ae70e 100755 --- a/scripts/scripts-library.sh +++ b/scripts/scripts-library.sh @@ -97,14 +97,6 @@ function ssh_key_create { function exit_state { set +x - # Check if the logs link is in place. This will only be true when the - # environment was built by the gate-check-commit script. - if [ -h $(dirname ${0})/../logs ]; then - # Ensure that all directories may be traversed by all users, and that - # all files are readable by all users. - chmod --recursive o+rX $(dirname ${0})/../logs - fi - TOTALSECONDS="$(( $(date +%s) - STARTTIME ))" info_block "Run Time = ${TOTALSECONDS} seconds || $((TOTALSECONDS / 60)) minutes" if [ "${1}" == 0 ];then @@ -117,6 +109,7 @@ function exit_state { function exit_success { set +x + [[ "${OSA_GATE_JOB:-false}" = true ]] && gate_job_exit_tasks exit_state 0 } @@ -125,9 +118,14 @@ function exit_fail { log_instance_info cat ${INFO_FILENAME} info_block "Error Info - $@" + [[ "${OSA_GATE_JOB:-false}" = true ]] && gate_job_exit_tasks exit_state 1 } +function gate_job_exit_tasks { + [[ -d "/openstack/log" ]] && chmod -R 0777 /openstack/log +} + function print_info { PROC_NAME="- [ $@ ] -" printf "\n%s%s\n" "$PROC_NAME" "${LINE:${#PROC_NAME}}" @@ -258,7 +256,6 @@ function get_pip { fi } - ## Signal traps -------------------------------------------------------------- # Trap all Death Signals and Errors trap "exit_fail ${LINENO} $? 'Received STOP Signal'" SIGHUP SIGINT SIGTERM