Skip to content

Commit

Permalink
[generate_dump] allow to extend dump with plugin scripts. (sonic-net#…
Browse files Browse the repository at this point in the history
…1335)

- What I did
Added support for tech support extension scripts.

- How I did it
It looks at /usr/bin/debug-dump for scripts, if it finds one it will execute them and save the output to dump/ folder.

- How to verify it
Write a simple scripts that outputs something and place it under /usr/bin/debug-dump/

Signed-off-by: Stepan Blyshchak <[email protected]>
  • Loading branch information
stepanblyschak authored and anand-kumar-subramanian committed Mar 2, 2021
1 parent ed5c3b9 commit 402e8a3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DUMPDIR=/var/dump
TARDIR=$DUMPDIR/$BASE
TARFILE=$DUMPDIR/$BASE.tar
LOGDIR=$DUMPDIR/$BASE/dump
PLUGINS_DIR=/usr/local/bin/debug-dump
NUM_ASICS=1
HOME=${HOME:-/root}
USER=${USER:-root}
Expand Down Expand Up @@ -138,6 +139,7 @@ save_bcmcmd_all_ns() {
# cmd: The command to run. Make sure that arguments with spaces have quotes
# filename: the filename to save the output as in $BASE/dump
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# save_stderr: (OPTIONAL) true or false. Should the stderr output be saved
# Returns:
# None
###############################################################################
Expand All @@ -148,10 +150,17 @@ save_cmd() {
local filename=$2
local filepath="${LOGDIR}/$filename"
local do_gzip=${3:-false}
local save_stderr=${4:-true}
local tarpath="${BASE}/dump/$filename"
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local redirect="&>"
[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR

if ! $save_stderr
then
redirect=">"
fi

# 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
Expand All @@ -171,9 +180,9 @@ save_cmd() {
fi
else
if $NOOP; then
echo "${timeout_cmd} $cmd &> '$filepath'"
echo "${timeout_cmd} $cmd $redirect '$filepath'"
else
eval "${timeout_cmd} $cmd" &> "$filepath"
eval "${timeout_cmd} $cmd" "$redirect" "$filepath"
if [ $? -ne 0 ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
fi
Expand Down Expand Up @@ -1076,6 +1085,12 @@ main() {
save_cmd "docker ps -a" "docker.ps"
save_cmd "docker top pmon" "docker.pmon"

local -r dump_plugins="$(find ${PLUGINS_DIR} -type f -executable)"
for plugin in $dump_plugins; do
# save stdout output of plugin and gzip it
save_cmd "$plugin" "$(basename $plugin)" true false
done

save_saidump

if [[ "$asic" = "mellanox" ]]; then
Expand Down

0 comments on commit 402e8a3

Please sign in to comment.