Skip to content

Commit

Permalink
[202012] [generate_dump] allow to extend dump with plugin scripts (#1945
Browse files Browse the repository at this point in the history
)

#### What I did
Added support for tech support extension scripts,
by cherry-picking of #1335 to branch 202012

The purpose is to have dumps of extensions in SONiC techsupport, even without App Extension infrastructure.
The new application will write a file that contains the dump command into /usr/bin/debug-dump folder, and it will appear in the output of `show techsupport` command.
#### 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/
  • Loading branch information
noaOrMlnx authored Dec 9, 2021
1 parent 8a3b41a commit 44ec4c8
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 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 @@ -153,6 +154,7 @@ save_bcmcmd_all_ns() {
# filename: the filename to save the output as in $BASE/dump
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# save_stderr: (OPTIONAL) true or false. Should the stderr output be saved
# Returns:
# None
###############################################################################
Expand All @@ -164,6 +166,7 @@ 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 cleanup_method=${4:-dummy_cleanup_method}
Expand All @@ -183,6 +186,11 @@ save_cmd() {
$MKDIR $V -p $LOGDIR
fi

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 Down Expand Up @@ -839,7 +847,7 @@ collect_mellanox() {
${CMD_PREFIX}/usr/bin/mstdump /dev/mst/mt*conf0 > "${mst_dump_filename}${i}"
save_file "${mst_dump_filename}${i}" mstdump true
done

# Save SDK error dumps
local sdk_dump_path=`${CMD_PREFIX}docker exec syncd cat /tmp/sai.profile|grep "SAI_DUMP_STORE_PATH"|cut -d = -f2`
if [[ -d $sdk_dump_path ]]; then
Expand Down Expand Up @@ -1056,7 +1064,7 @@ save_crash_files() {
get_asic_count() {
trap 'handle_error $? $LINENO' ERR
local redirect_eval="2>&1"
if ! $SAVE_STDERR
if ! $SAVE_STDERR
then
redirect_eval=""
fi
Expand Down Expand Up @@ -1216,6 +1224,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 Expand Up @@ -1298,7 +1312,7 @@ main() {
fi

echo ${TARFILE}

if ! $SAVE_STDERR
then
exit $RETURN_CODE
Expand Down Expand Up @@ -1350,7 +1364,7 @@ remove_secret_from_etc_files() {

# Remove snmp community string from snmp.yml
sed -i -E 's/(\s*snmp_\S*community\s*:\s*)(\S*)/\1****/g' $dumppath/etc/sonic/snmp.yml

# Remove secret from /etc/sonic/config_db.json
cat $dumppath/etc/sonic/config_db.json | remove_secret_from_config_db_dump > $dumppath/etc/sonic/config_db.json.temp
mv $dumppath/etc/sonic/config_db.json.temp $dumppath/etc/sonic/config_db.json
Expand Down Expand Up @@ -1409,7 +1423,7 @@ OPTIONS
"24 March", "yesterday", etc.
-t TIMEOUT_MINS
Command level timeout in minutes
-r
-r
Redirect any intermediate errors to STDERR
EOF
Expand Down

0 comments on commit 44ec4c8

Please sign in to comment.