From f42363f623ee05c2e90c31842969a6211179c93a Mon Sep 17 00:00:00 2001 From: Gabriele Cerami Date: Mon, 30 Jul 2018 17:14:01 +0100 Subject: [PATCH] Collect logs: split and move the script creation Since we create the collect logs script only at the end of the playbooks run, when a job times out, there is no collect_logs.sh script created, and the post-run playbook doesn't actually run anything. This change split the function in two parts, the first part creates the script, and its call is moved to before the playbooks run. The second part is moved to toci_quickstart directly and runs after the playbooks. The second part should not be needed anymore with zuulv3 in rdo provider. Closes-Bug: #1784417 Change-Id: Iee897f780c93bdf847e188fc033e8be112e12a4f --- .../templates/oooq_common_functions.sh.j2 | 10 +--------- .../tripleo-ci/templates/toci_quickstart.sh.j2 | 12 ++++++++++-- scripts/oooq_common_functions.sh | 10 +--------- toci_quickstart.sh | 14 ++++++++++++-- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/playbooks/tripleo-ci/templates/oooq_common_functions.sh.j2 b/playbooks/tripleo-ci/templates/oooq_common_functions.sh.j2 index 3cc48cac7..a44497bac 100644 --- a/playbooks/tripleo-ci/templates/oooq_common_functions.sh.j2 +++ b/playbooks/tripleo-ci/templates/oooq_common_functions.sh.j2 @@ -88,7 +88,7 @@ function run_with_timeout { /usr/bin/timeout --preserve-status ${TIME_FOR_COMMAND}m ${COMMAND} } -function collect_logs { +function create_collect_logs_script { cat <<-EOF > $LOGS_DIR/collect_logs.sh #!/bin/bash set -x @@ -147,14 +147,6 @@ function collect_logs { du -L -ch $LOGS_DIR/* | tail -n +1 | sort -rh | head -n 200 &> $LOGS_DIR/log-size.txt || true EOF - if [[ "${NODEPOOL_PROVIDER:-''}" == "rdo-cloud-tripleo" ]] || [[ "${NODEPOOL_PROVIDER:-''}" == "tripleo-test-cloud-rh1" ]]; then - if [[ "$TOCI_JOBTYPE" =~ "ovb" ]]; then - bash $LOGS_DIR/collect_logs.sh - # rename script to not to run it in multinode jobs - mv $LOGS_DIR/collect_logs.sh $LOGS_DIR/ovb_collect_logs.sh - fi - fi - } get_extra_vars_from_release() diff --git a/playbooks/tripleo-ci/templates/toci_quickstart.sh.j2 b/playbooks/tripleo-ci/templates/toci_quickstart.sh.j2 index 4994dc7d2..c4fd6106b 100755 --- a/playbooks/tripleo-ci/templates/toci_quickstart.sh.j2 +++ b/playbooks/tripleo-ci/templates/toci_quickstart.sh.j2 @@ -140,6 +140,8 @@ done if [[ "$PLAYBOOK_DRY_RUN" == "1" ]]; then exit_value=0 else + ## LOGS COLLECTION PREPARE + create_collect_logs_script for playbook in $PLAYBOOKS; do echo "${RELEASE_ARGS[$playbook]:=$QUICKSTART_DEFAULT_RELEASE_ARG}" run_with_timeout $START_JOB_TIME $QUICKSTART_INSTALL_CMD \ @@ -160,8 +162,14 @@ for playbook in $PLAYBOOKS; do done [[ "$exit_value" == 0 ]] && echo "Playbook run passed successfully" || echo "Playbook run failed" - ## LOGS COLLECTION - collect_logs + ## LOGS COLLECTION RUN (if applicable) + if [[ "${NODEPOOL_PROVIDER:-''}" == "rdo-cloud-tripleo" ]] || [[ "${NODEPOOL_PROVIDER:-''}" == "tripleo-test-cloud-rh1" ]]; then + if [[ "$TOCI_JOBTYPE" =~ "ovb" ]]; then + bash $LOGS_DIR/collect_logs.sh + # rename script to not to run it in multinode jobs + mv $LOGS_DIR/collect_logs.sh $LOGS_DIR/ovb_collect_logs.sh + fi + fi fi diff --git a/scripts/oooq_common_functions.sh b/scripts/oooq_common_functions.sh index a90d05935..46e94decc 100644 --- a/scripts/oooq_common_functions.sh +++ b/scripts/oooq_common_functions.sh @@ -88,7 +88,7 @@ function run_with_timeout { /usr/bin/timeout --preserve-status ${TIME_FOR_COMMAND}m ${COMMAND} } -function collect_logs { +function create_collect_logs_script { cat <<-EOF > $LOGS_DIR/collect_logs.sh #!/bin/bash set -x @@ -147,14 +147,6 @@ function collect_logs { du -L -ch $LOGS_DIR/* | tail -n +1 | sort -rh | head -n 200 &> $LOGS_DIR/log-size.txt || true EOF - if [[ "${NODEPOOL_PROVIDER:-''}" == "rdo-cloud-tripleo" ]] || [[ "${NODEPOOL_PROVIDER:-''}" == "tripleo-test-cloud-rh1" ]]; then - if [[ "$TOCI_JOBTYPE" =~ "ovb" ]]; then - bash $LOGS_DIR/collect_logs.sh - # rename script to not to run it in multinode jobs - mv $LOGS_DIR/collect_logs.sh $LOGS_DIR/ovb_collect_logs.sh - fi - fi - } get_extra_vars_from_release() diff --git a/toci_quickstart.sh b/toci_quickstart.sh index 0949379ab..4a529da34 100755 --- a/toci_quickstart.sh +++ b/toci_quickstart.sh @@ -140,6 +140,9 @@ done if [[ "$PLAYBOOK_DRY_RUN" == "1" ]]; then exit_value=0 else + ## LOGS COLLECTION PREPARE + create_collect_logs_script + for playbook in $PLAYBOOKS; do echo "${RELEASE_ARGS[$playbook]:=$QUICKSTART_DEFAULT_RELEASE_ARG}" run_with_timeout $START_JOB_TIME $QUICKSTART_INSTALL_CMD \ @@ -161,8 +164,15 @@ else [[ "$exit_value" == 0 ]] && echo "Playbook run passed successfully" || echo "Playbook run failed" - ## LOGS COLLECTION - collect_logs + ## LOGS COLLECTION RUN (if applicable) + if [[ "${NODEPOOL_PROVIDER:-''}" == "rdo-cloud-tripleo" ]] || [[ "${NODEPOOL_PROVIDER:-''}" == "tripleo-test-cloud-rh1" ]]; then + if [[ "$TOCI_JOBTYPE" =~ "ovb" ]]; then + bash $LOGS_DIR/collect_logs.sh + # rename script to not to run it in multinode jobs + mv $LOGS_DIR/collect_logs.sh $LOGS_DIR/ovb_collect_logs.sh + fi + fi + fi