Skip to content

Commit

Permalink
[CLI][techsupport] Add NOOP option for commands that did not have tha…
Browse files Browse the repository at this point in the history
…t option (#1445)
  • Loading branch information
smaheshm authored Feb 25, 2021
1 parent 1fa4b94 commit 2f6e36e
Showing 1 changed file with 101 additions and 72 deletions.
173 changes: 101 additions & 72 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ save_cmd() {
# This is required if $cmd has quoted strings that should be bunched
# as one argument, e.g. vtysh -c "COMMAND HERE" needs to have
# "COMMAND HERE" bunched together as 1 arg to vtysh -c
if $do_gzip
then
if $do_gzip; then
tarpath="${tarpath}.gz"
filepath="${filepath}.gz"
local cmds="$cmd 2>&1 | gzip -c > '${filepath}'"
Expand Down Expand Up @@ -223,6 +222,71 @@ save_cmd_all_ns() {
fi
}

###############################################################################
# Copies a given file from a specified docker to the given target location
# default (host) namespace in single ASIC platform
# Globals:
# None
# Arguments:
# docker: docker name
# filename: the filename to copy
# destination: destination filename
# Returns:
# None
###############################################################################
copy_from_docker() {
local start_t=$(date +%s%3N)
local end_t=0
local docker=$1
local filename=$2
local dstpath=$3
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"

if $NOOP; then
echo "${timeout_cmd} sudo docker exec -i ${docker} touch ${filename}"
echo "${timeout_cmd} sudo docker cp ${docker}:${filename} ${dstpath}"
else
eval "${timeout_cmd} sudo docker exec -i ${docker} touch ${filename}"
if [ $? -ne 0 ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
fi
eval "${timeout_cmd} sudo docker cp ${docker}:${filename} ${dstpath}"
if [ $? -ne 0 ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
fi
fi
end_t=$(date +%s%3N)
echo "[ copy_from_docker:${docker}:${filename} ] : $(($end_t-$start_t)) msec" \
>> $TECHSUPPORT_TIME_INFO
}

###############################################################################
# Copies a given file from a specified docker to the given target location
# default (host) namespace in single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# docker: docker name
# filename: the filename to copy
# destination: destination filename
# Returns:
# None
###############################################################################
copy_from_masic_docker() {
local docker=$1
local filename=$2
local dstpath=$3

if [[ ("$NUM_ASICS" > 1) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
copy_from_docker "$docker$i" "$filename" "$dstpath.$i"
done
else
copy_from_docker "$docker" "$filename" "$dstpath"
fi
}

###############################################################################
# Returns namespace option to be used with vtysh commmand, based on the ASIC ID.
# Returns empty string if no ASIC ID is provided
Expand All @@ -241,6 +305,7 @@ get_vtysh_namespace() {
else
ns=" -n ${asic_id}"
fi
echo "$ns"
}

###############################################################################
Expand Down Expand Up @@ -502,17 +567,27 @@ save_redis_info() {
# RM
# BASE
# TARFILE
# NOOP
# Arguments:
# *procfiles: variable-length list of proc file paths to save
# Returns:
# None
###############################################################################
save_proc() {
local procfiles="$@"
$MKDIR $V -p $TARDIR/proc \
&& (for f in $procfiles; do ( [ -e $f ] && $CP $V -r $f $TARDIR/proc ) || echo "$f not found" > $TARDIR/$f; done) \
&& $TAR $V -rhf $TARFILE -C $DUMPDIR --mode=+rw $BASE/proc \
&& $RM $V -rf $TARDIR/proc
$MKDIR $V -p $TARDIR/proc
for f in $procfiles
do
if $NOOP; then
if [ -e $f ]; then
echo "$CP $V -r $f $TARDIR/proc"
fi
else
( [ -e $f ] && $CP $V -r $f $TARDIR/proc ) || echo "$f not found" > $TARDIR/$f
fi
done
$TAR $V -rhf $TARFILE -C $DUMPDIR --mode=+rw $BASE/proc
$RM $V -rf $TARDIR/proc
}

###############################################################################
Expand Down Expand Up @@ -553,41 +628,6 @@ save_saidump() {
fi
}

###############################################################################
# Runs a 'show platform' command, append the output to 'filename' and add to the incrementally built tar.
# Globals:
# LOGDIR
# BASE
# MKDIR
# TAR
# TARFILE
# DUMPDIR
# V
# RM
# Arguments:
# type: the type of platform information
# filename: the filename to save the output as in $BASE/dump
# Returns:
# None
###############################################################################
save_platform() {
local start_t=$(date +%s%3N)
local end_t=0
local type="$1"
local filename=$2
local filepath="${LOGDIR}/$filename"
local tarpath="${BASE}/dump/$filename"
[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR

eval "show platform $type" &>> "$filepath"
echo $'\r' >> "$filepath"

($TAR $V -uhf $TARFILE -C $DUMPDIR "$tarpath" \
|| abort "${ERROR_TAR_FAILED}" "tar append operation failed. Aborting to prevent data loss.")
end_t=$(date +%s%3N)
echo "[ save_platform:$type ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}

###############################################################################
# Save platform related info
# Globals:
Expand All @@ -598,11 +638,11 @@ save_platform() {
# None
###############################################################################
save_platform_info() {
save_platform "syseeprom" "platform"
save_platform "psustatus" "platform"
save_platform "ssdhealth" "platform"
save_platform "temperature" "platform"
save_platform "fan" "platform"
save_cmd "show platform syseeprom" "syseeprom"
save_cmd "show platform psustatus" "psustatus"
save_cmd "show platform ssdhealth" "ssdhealth"
save_cmd "show platform temperature" "temperature"
save_cmd "show platform fan" "fan"
}

###############################################################################
Expand Down Expand Up @@ -809,6 +849,9 @@ collect_broadcom() {
save_bcmcmd_all_ns "\"mirror dest show\"" "mirror.dest.summary"
save_bcmcmd_all_ns "\"port *\"" "port.summary"
save_bcmcmd_all_ns "\"d chg my_station_tcam\"" "mystation.tcam.summary"

copy_from_masic_docker "syncd" "/var/log/diagrun.log" "/var/log/diagrun.log"
copy_from_masic_docker "syncd" "/var/log/bcm_diag_post" "/var/log/bcm_diag_post"
}

###############################################################################
Expand Down Expand Up @@ -868,22 +911,26 @@ save_log_files() {
###############################################################################
# Save warmboot files
# Globals:
# TARDIR, TARFILE, TAR, DUMPDIR, TECHSUPPORT_TIME_INFO
# TARDIR, TARFILE, TAR, DUMPDIR, TECHSUPPORT_TIME_INFO, NOOP
# Arguments:
# None
# Returns:
# None
###############################################################################
save_warmboot_files() {
# Copy the warmboot files
mkdir -p $TARDIR
$CP $V -rf /host/warmboot $TARDIR

start_t=$(date +%s%3N)
($TAR $V --warning=no-file-removed -rhf $TARFILE -C $DUMPDIR --mode=+rw \
$BASE/warmboot \
|| abort "${ERROR_TAR_FAILED}" "Tar append operation failed. Aborting for safety.") \
&& $RM $V -rf $TARDIR
if $NOOP; then
echo "$CP $V -rf /host/warmboot $TARDIR"
else
mkdir -p $TARDIR
$CP $V -rf /host/warmboot $TARDIR

($TAR $V --warning=no-file-removed -rhf $TARFILE -C $DUMPDIR --mode=+rw \
$BASE/warmboot \
|| abort "${ERROR_TAR_FAILED}" "Tar append operation failed. Aborting for safety.") \
&& $RM $V -rf $TARDIR
fi
end_t=$(date +%s%3N)
echo "[ Warm-boot Files ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
Expand Down Expand Up @@ -1137,24 +1184,6 @@ main() {
end_t=$(date +%s%3N)
echo "[ TAR /etc Files ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO

if [ "$asic" = "broadcom" ]; then
if [[ ("$NUM_ASICS" > 1) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
sudo docker exec -i syncd$i touch /var/log/diagrun.log
sudo docker exec -i syncd$i touch /var/log/bcm_diag_post

sudo docker cp syncd$i:/var/log/diagrun.log /var/log/diagrun.log.$i
sudo docker cp syncd$i:/var/log/bcm_diag_post /var/log/bcm_diag_post.$i
done
else
sudo docker exec -i syncd touch /var/log/diagrun.log
sudo docker exec -i syncd touch /var/log/bcm_diag_post

sudo docker cp syncd:/var/log/diagrun.log /var/log/diagrun.log
sudo docker cp syncd:/var/log/bcm_diag_post /var/log/bcm_diag_post
fi
fi
save_log_files
save_warmboot_files
save_crash_files
Expand Down

0 comments on commit 2f6e36e

Please sign in to comment.