From 86919fae83e5d2edd194a790d0c0d72cc827f931 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Wed, 29 Sep 2021 21:51:38 +0000 Subject: [PATCH 1/7] bash error changes ported to 202012 Signed-off-by: Vivek Reddy Karri --- scripts/generate_dump | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 6e2ab6728c..4c9077eef2 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -65,7 +65,9 @@ save_bcmcmd() { local do_gzip=${3:-false} local tarpath="${BASE}/dump/$filename" local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" - [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR + if [ ! -d $LOGDIR ]; then + $MKDIR $V -p $LOGDIR + fi if [ $SKIP_BCMCMD -eq 1 ]; then echo "Skip $cmd" @@ -78,8 +80,8 @@ save_bcmcmd() { if $NOOP; then echo "${timeout_cmd} $cmd &> '${filepath}'" else - eval "${timeout_cmd} $cmd" &> "${filepath}" - ret=$? + ret=0 + eval "${timeout_cmd} $cmd" &> "${filepath}" || ret=$? if [ $ret -ne 0 ]; then if [ $ret -eq 124 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." @@ -164,6 +166,9 @@ save_cmd() { local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" local redirect='&>' local redirect_eval='2>&1' + if [ ! -d $LOGDIR ]; then + $MKDIR $V -p $LOGDIR + fi if ! $SAVE_STDERR then @@ -171,8 +176,6 @@ save_cmd() { redirect_eval="" fi - [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR - # eval required here to re-evaluate the $cmd properly at runtime # This is required if $cmd has quoted strings that should be bunched # as one argument, e.g. vtysh -c "COMMAND HERE" needs to have @@ -264,12 +267,13 @@ copy_from_docker() { echo "${timeout_cmd} ${touch_cmd}" echo "${timeout_cmd} ${cp_cmd}" else - eval "${timeout_cmd} ${touch_cmd}" - if [ $? -ne 0 ]; then + RC=0 + eval "${timeout_cmd} ${touch_cmd}" || RC=$? + if [ $RC -ne 0 ]; then echo "Command: $touch_cmd timedout after ${TIMEOUT_MIN} minutes." fi - eval "${timeout_cmd} ${cp_cmd}" - if [ $? -ne 0 ]; then + eval "${timeout_cmd} ${cp_cmd}" || RC=$? + if [ $RC -ne 0 ]; then echo "Command: $cp_cmd timedout after ${TIMEOUT_MIN} minutes." fi fi @@ -710,7 +714,9 @@ save_file() { local tar_path="${BASE}/$supp_dir/$(basename $orig_path)" local do_gzip=${3:-true} local do_tar_append=${4:-true} - [ ! -d "$TARDIR/$supp_dir" ] && $MKDIR $V -p "$TARDIR/$supp_dir" + if [ ! -d "$TARDIR/$supp_dir" ]; then + $MKDIR $V -p "$TARDIR/$supp_dir" + fi if $do_gzip; then gz_path="${gz_path}.gz" @@ -1244,8 +1250,9 @@ main() { $RM $V -rf $TARDIR if $DO_COMPRESS; then - $GZIP $V $TARFILE - if [ $? -eq 0 ]; then + RC=0 + $GZIP $V $TARFILE || RC=$? + if [ $RC -eq 0 ]; then TARFILE="${TARFILE}.gz" else echo "WARNING: gzip operation appears to have failed." >&2 From c8b913e6a4f589ce334bf8053bf82e7dd49b8f86 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Wed, 29 Sep 2021 22:07:12 +0000 Subject: [PATCH 2/7] Missing fixes added Signed-off-by: Vivek Reddy Karri --- scripts/generate_dump | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 4c9077eef2..80ca9d3226 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -86,8 +86,9 @@ save_bcmcmd() { if [ $ret -eq 124 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." else - grep "polling socket timeout: Success" ${filepath} &>/dev/null - if [ $? -eq 0 ]; then + RC=0 + grep "polling socket timeout: Success" ${filepath} &>/dev/null || RC=$? + if [ $RC -eq 0 ]; then echo "bcmcmd command timeout. Setting SKIP_BCMCMD to true ..." SKIP_BCMCMD=1 fi @@ -187,8 +188,9 @@ save_cmd() { if $NOOP; then echo "${timeout_cmd} bash -c \"${cmds}\"" else - eval "${timeout_cmd} bash -c \"${cmds}\"" - if [ $? -ne 0 ]; then + RC=0 + eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$? + if [ $RC -ne 0 ]; then echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes." fi fi From d6ea78d50623a59d2a6f76760d1abd3bb168ecad Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Thu, 30 Sep 2021 04:02:23 +0000 Subject: [PATCH 3/7] Removed the -it option Signed-off-by: Vivek Reddy Karri --- scripts/generate_dump | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 80ca9d3226..d39d4ec52c 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -660,11 +660,11 @@ save_redis() { save_saidump() { trap 'handle_error $? $LINENO' ERR if [[ ( "$NUM_ASICS" == 1 ) ]] ; then - save_cmd "docker exec -it syncd saidump" "saidump" + save_cmd "docker exec syncd saidump" "saidump" else for (( i=0; i<$NUM_ASICS; i++ )) do - save_cmd "docker exec -it syncd$i saidump" "saidump$i" + save_cmd "docker exec syncd$i saidump" "saidump$i" done fi } @@ -803,7 +803,7 @@ enable_logrotate() { collect_mellanox() { trap 'handle_error $? $LINENO' ERR local sai_dump_filename="/tmp/sai_sdk_dump_$(date +"%m_%d_%Y_%I_%M_%p")" - ${CMD_PREFIX}docker exec -it syncd saisdkdump -f $sai_dump_filename + ${CMD_PREFIX}docker exec syncd saisdkdump -f $sai_dump_filename ${CMD_PREFIX}docker exec syncd tar Ccf $(dirname $sai_dump_filename) - $(basename $sai_dump_filename) | tar Cxf /tmp/ - save_file $sai_dump_filename sai_sdk_dump true From 628bb2c8d72cd7c8c6fbfd6297349fed6b6df4a0 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Sun, 3 Oct 2021 07:50:19 +0000 Subject: [PATCH 4/7] removed -d option from show ip interfaces Signed-off-by: Vivek Reddy Karri --- scripts/generate_dump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index d39d4ec52c..cdba6dd269 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -1157,7 +1157,7 @@ main() { save_cmd "show interface status -d all" "interface.status" save_cmd "show interface transceiver presence" "interface.xcvrs.presence" save_cmd "show interface transceiver eeprom --dom" "interface.xcvrs.eeprom" - save_cmd "show ip interface -d all" "ip.interface" + save_cmd "show ip interface" "ip.interface" save_cmd "lldpctl" "lldpctl" if [[ ( "$NUM_ASICS" > 1 ) ]]; then From ee8e4a29b756c8b26c898fb7f41217e500176ea1 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Sun, 3 Oct 2021 07:54:43 +0000 Subject: [PATCH 5/7] Revert "bash error changes ported to 202012" This reverts commit 86919fae83e5d2edd194a790d0c0d72cc827f931. --- scripts/generate_dump | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index cdba6dd269..d3ba40d8fc 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -65,9 +65,7 @@ save_bcmcmd() { local do_gzip=${3:-false} local tarpath="${BASE}/dump/$filename" local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" - if [ ! -d $LOGDIR ]; then - $MKDIR $V -p $LOGDIR - fi + [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR if [ $SKIP_BCMCMD -eq 1 ]; then echo "Skip $cmd" @@ -80,8 +78,8 @@ save_bcmcmd() { if $NOOP; then echo "${timeout_cmd} $cmd &> '${filepath}'" else - ret=0 - eval "${timeout_cmd} $cmd" &> "${filepath}" || ret=$? + eval "${timeout_cmd} $cmd" &> "${filepath}" + ret=$? if [ $ret -ne 0 ]; then if [ $ret -eq 124 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." @@ -167,9 +165,6 @@ save_cmd() { local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" local redirect='&>' local redirect_eval='2>&1' - if [ ! -d $LOGDIR ]; then - $MKDIR $V -p $LOGDIR - fi if ! $SAVE_STDERR then @@ -177,6 +172,8 @@ save_cmd() { redirect_eval="" fi + [ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR + # eval required here to re-evaluate the $cmd properly at runtime # This is required if $cmd has quoted strings that should be bunched # as one argument, e.g. vtysh -c "COMMAND HERE" needs to have @@ -269,13 +266,12 @@ copy_from_docker() { echo "${timeout_cmd} ${touch_cmd}" echo "${timeout_cmd} ${cp_cmd}" else - RC=0 - eval "${timeout_cmd} ${touch_cmd}" || RC=$? - if [ $RC -ne 0 ]; then + eval "${timeout_cmd} ${touch_cmd}" + if [ $? -ne 0 ]; then echo "Command: $touch_cmd timedout after ${TIMEOUT_MIN} minutes." fi - eval "${timeout_cmd} ${cp_cmd}" || RC=$? - if [ $RC -ne 0 ]; then + eval "${timeout_cmd} ${cp_cmd}" + if [ $? -ne 0 ]; then echo "Command: $cp_cmd timedout after ${TIMEOUT_MIN} minutes." fi fi @@ -716,9 +712,7 @@ save_file() { local tar_path="${BASE}/$supp_dir/$(basename $orig_path)" local do_gzip=${3:-true} local do_tar_append=${4:-true} - if [ ! -d "$TARDIR/$supp_dir" ]; then - $MKDIR $V -p "$TARDIR/$supp_dir" - fi + [ ! -d "$TARDIR/$supp_dir" ] && $MKDIR $V -p "$TARDIR/$supp_dir" if $do_gzip; then gz_path="${gz_path}.gz" @@ -1252,9 +1246,8 @@ main() { $RM $V -rf $TARDIR if $DO_COMPRESS; then - RC=0 - $GZIP $V $TARFILE || RC=$? - if [ $RC -eq 0 ]; then + $GZIP $V $TARFILE + if [ $? -eq 0 ]; then TARFILE="${TARFILE}.gz" else echo "WARNING: gzip operation appears to have failed." >&2 From c85a36baa61857745b8cde536d99627b3e98093c Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Sun, 3 Oct 2021 07:56:59 +0000 Subject: [PATCH 6/7] Revert "Missing fixes added" This reverts commit c8b913e6a4f589ce334bf8053bf82e7dd49b8f86. --- scripts/generate_dump | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index d3ba40d8fc..76922afb6f 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -84,9 +84,8 @@ save_bcmcmd() { if [ $ret -eq 124 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." else - RC=0 - grep "polling socket timeout: Success" ${filepath} &>/dev/null || RC=$? - if [ $RC -eq 0 ]; then + grep "polling socket timeout: Success" ${filepath} &>/dev/null + if [ $? -eq 0 ]; then echo "bcmcmd command timeout. Setting SKIP_BCMCMD to true ..." SKIP_BCMCMD=1 fi @@ -185,9 +184,8 @@ save_cmd() { if $NOOP; then echo "${timeout_cmd} bash -c \"${cmds}\"" else - RC=0 - eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$? - if [ $RC -ne 0 ]; then + eval "${timeout_cmd} bash -c \"${cmds}\"" + if [ $? -ne 0 ]; then echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes." fi fi From 8251d7fe500634a36811f52c68e048a5fde9524f Mon Sep 17 00:00:00 2001 From: Vivek Reddy Karri Date: Sat, 16 Oct 2021 22:42:18 +0000 Subject: [PATCH 7/7] exit with trap Return code only when -r option is set Signed-off-by: Vivek Reddy Karri --- scripts/generate_dump | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 8f1fa066ab..4b796c1348 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -1266,7 +1266,11 @@ main() { fi echo ${TARFILE} - exit $RETURN_CODE + + if ! $SAVE_STDERR + then + exit $RETURN_CODE + fi } ###############################################################################