forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_dump
executable file
·1509 lines (1387 loc) · 48.2 KB
/
generate_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Generate Sysdump
# creates a snapshot of system state for debugging later.
#
set -u
ERROR_TAR_FAILED=5
ERROR_PROCFS_SAVE_FAILED=6
ERROR_INVALID_ARGUMENT=10
TAR=tar
MKDIR=mkdir
RM=rm
LN=ln
GZIP=gzip
CP=cp
MV=mv
GREP=grep
TOUCH=touch
V=
ALLOW_PROCESS_STOP=
NOOP=false
DO_COMPRESS=true
CMD_PREFIX=
SINCE_DATE="@0" # default is set to January 1, 1970 at 00:00:00 GMT
REFERENCE_FILE=/tmp/reference
TECHSUPPORT_TIME_INFO=`mktemp "/tmp/techsupport_time_info.XXXXXXXXXX"`
BASE=sonic_dump_`hostname`_`date +%Y%m%d_%H%M%S`
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}
TIMEOUT_MIN="5"
SKIP_BCMCMD=0
SAVE_STDERR=true
RETURN_CODE=0
handle_signal()
{
echo "Generate Dump received interrupt" >&2
$RM $V -rf $TARDIR
exit 1
}
trap 'handle_signal' SIGINT
handle_error() {
if [ "$1" != "0" ]; then
echo "ERR: RC:-$1 observed on line $2" >&2
RETURN_CODE=1
fi
}
save_bcmcmd() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local cmd="$1"
local filename=$2
local filepath="${LOGDIR}/$filename"
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
if [ $SKIP_BCMCMD -eq 1 ]; then
echo "Skip $cmd"
return 0
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
# "COMMAND HERE" bunched together as 1 arg to vtysh -c
if $NOOP; then
echo "${timeout_cmd} $cmd &> '${filepath}'"
else
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."
else
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
fi
fi
fi
if $do_gzip; then
gzip ${filepath} 2>/dev/null
tarpath="${tarpath}.gz"
filepath="${filepath}.gz"
fi
($TAR $V -rhf $TARFILE -C $DUMPDIR "$tarpath" \
|| abort "${ERROR_TAR_FAILED}" "tar append operation failed. Aborting to prevent data loss.") \
&& $RM $V -rf "$filepath"
end_t=$(date +%s%3N)
echo "[ save_bcmcmd:$cmd ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Runs a given bcmcmd command in all namesapces in case of multi ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# 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
# Returns:
# None
###############################################################################
save_bcmcmd_all_ns() {
trap 'handle_error $? $LINENO' ERR
local do_gzip=${3:-false}
if [[ ( "$NUM_ASICS" > 1 ) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
local cmd="bcmcmd -n $i $1"
local file="$2.$i"
save_bcmcmd "$cmd" "$file" "$do_gzip"
done
else
local cmd="bcmcmd $1"
save_bcmcmd "$cmd" "$2" "$do_gzip"
fi
}
###############################################################################
# Runs a comamnd and saves its output to the incrementally built tar.
# Command gets timedout if it runs for more than TIMEOUT_MIN minutes.
# Globals:
# LOGDIR
# BASE
# MKDIR
# TAR
# TARFILE
# DUMPDIR
# V
# RM
# NOOP
# Arguments:
# 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
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# Returns:
# None
###############################################################################
save_cmd() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local cmd="$1"
local filename=$2
local filepath="${LOGDIR}/$filename"
local do_gzip=${3:-false}
local tarpath="${BASE}/dump/$filename"
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local cleanup_method=${4:-dummy_cleanup_method}
local redirect='&>'
local redirect_eval='2>&1'
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
fi
if ! $SAVE_STDERR
then
redirect=">"
redirect_eval=""
fi
if [ ! -d $LOGDIR ]; then
$MKDIR $V -p $LOGDIR
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
# "COMMAND HERE" bunched together as 1 arg to vtysh -c
if $do_gzip; then
tarpath="${tarpath}.gz"
filepath="${filepath}.gz"
# cleanup_method will run in a sub-shell, need declare it first
local cleanup_method_declration=$(declare -f $cleanup_method)
local cmds="$cleanup_method_declration; $cmd $redirect_eval | $cleanup_method | gzip -c > '${filepath}'"
if $NOOP; then
echo "${timeout_cmd} bash -c \"${cmds}\""
else
RC=0
eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
fi
fi
else
if $NOOP; then
echo "${timeout_cmd} $cmd | $cleanup_method $redirect '$filepath'"
else
RC=0
eval "${timeout_cmd} $cmd | $cleanup_method" "$redirect" "$filepath" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
fi
fi
fi
($TAR $V -rhf $TARFILE -C $DUMPDIR "$tarpath" \
|| abort "${ERROR_TAR_FAILED}" "tar append operation failed. Aborting to prevent data loss.") \
&& $RM $V -rf "$filepath"
end_t=$(date +%s%3N)
echo "[ save_cmd:$cmd ] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# Dummy cleanup method.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
dummy_cleanup_method() {
cat
}
###############################################################################
# Runs a given command in all namesapces in case of multi ASIC platform, in
# default (host) namespace in single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# 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
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# Returns:
# None
###############################################################################
save_cmd_all_ns() {
trap 'handle_error $? $LINENO' ERR
local do_zip=${3:-false}
local cleanup_method=${4:-dummy_cleanup_method}
# host or default namespace
save_cmd "$1" "$2" "$do_zip" $cleanup_method
if [[ ( "$NUM_ASICS" > 1 ) ]] ; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
local cmd="sonic-netns-exec asic$i $1"
local file="$2.$i"
save_cmd "$cmd" "$file" "$do_zip" $cleanup_method
done
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() {
trap 'handle_error $? $LINENO' ERR
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"
local touch_cmd="sudo docker exec ${docker} touch ${filename}"
local cp_cmd="sudo docker cp ${docker}:${filename} ${dstpath}"
if $NOOP; then
echo "${timeout_cmd} ${touch_cmd}"
echo "${timeout_cmd} ${cp_cmd}"
else
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}" || RC=$?
if [ $RC -ne 0 ]; then
echo "Command: $cp_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() {
trap 'handle_error $? $LINENO' ERR
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
# Globals:
# None
# Arguments:
# asic_id: (OPTIONAL) ASIC ID
# Returns:
# vtysh namespace option
###############################################################################
get_vtysh_namespace() {
trap 'handle_error $? $LINENO' ERR
local asic_id=${1:-""}
local ns=""
if [[ ( $asic_id = "" ) ]] ; then
ns=""
else
ns=" -n ${asic_id}"
fi
echo "$ns"
}
###############################################################################
# Runs a vtysh command in all namesapces for a multi ASIC platform, and in
# default (host) namespace in single ASIC platforms. Saves its output to the
# incrementally built tar.
# Globals:
# None
# Arguments:
# cmd: the vtysh command to run. This should NOT include vtysh -c
# filename: The filename to save the output as.
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_vtysh() {
trap 'handle_error $? $LINENO' ERR
local vtysh_cmd=$1
local filename=$2
local do_gzip=${3:-false}
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "vtysh -c '${vtysh_cmd}'" "$filename" $do_gzip
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
ns_cmd=$(get_vtysh_namespace $i)
local cmd="vtysh $ns_cmd -c '${vtysh_cmd}'"
local file=$filename.$i
save_cmd "$cmd" "$file" "$do_gzip"
done
fi
}
###############################################################################
# Runs an ip command and saves its output to the incrementally built tar.
# Globals:
# None
# Arguments:
# cmd: the ip command to run sans 'ip'
# filename: Files will be named 'ip.<filename>'
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_ip() {
trap 'handle_error $? $LINENO' ERR
local ip_args=$1
local filename="ip.$2"
local do_gzip=${3:-false}
save_cmd_all_ns "ip $ip_args" "$filename" "$do_gzip"
}
###############################################################################
# Runs a bridge command and saves its output to the incrementally built tar.
# Globals:
# None
# Arguments:
# cmd: the bridge command to run sans 'bridge'
# filename: Files will be named 'bridge.<filename>'
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_bridge() {
trap 'handle_error $? $LINENO' ERR
local br_args=$1
local filename="bridge.$2"
local do_gzip=${3:-false}
save_cmd_all_ns "bridge $br_args" "$filename" $do_gzip
}
###############################################################################
# Dump the bridge L2 information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bridge_info() {
trap 'handle_error $? $LINENO' ERR
save_bridge "fdb show" "fdb"
save_bridge "vlan show" "vlan"
}
###############################################################################
# Iterates all neighbors and runs save_vtysh to save each neighbor's
# advertised-routes and received-routes
# On multi ASIC platform, collects information from all namespaces
# Globals:
# None
# Arguments:
# Optional arg namespace
# Returns:
# None
###############################################################################
save_bgp_neighbor() {
trap 'handle_error $? $LINENO' ERR
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
local asic_id=${1:-""}
local ns=$(get_vtysh_namespace $asic_id)
neighbor_list_v4=$(${timeout_cmd} vtysh $ns -c "show ip bgp neighbors" | grep "BGP neighbor is" | awk -F '[, ]' '{print $4}')
for word in $neighbor_list_v4; do
save_cmd "vtysh $ns -c \"show ip bgp neighbors $word advertised-routes\"" "ip.bgp.neighbor.$word.adv$asic_id"
save_cmd "vtysh $ns -c \"show ip bgp neighbors $word routes\"" "ip.bgp.neighbor.$word.rcv$asic_id"
done
neighbor_list_v6=$(vtysh $ns -c "show bgp ipv6 neighbors" | grep "BGP neighbor is" | awk -F '[, ]' '{print $4}' | fgrep ':')
for word in $neighbor_list_v6; do
save_cmd "vtysh $ns -c \"show bgp ipv6 neighbors $word advertised-routes\"" "ipv6.bgp.neighbor.$word.adv$asic_id"
save_cmd "vtysh $ns -c \"show bgp ipv6 neighbors $word routes\"" "ipv6.bgp.neighbor.$word.rcv$asic_id"
done
vrf_list=`${timeout_cmd} vtysh $ns -c "show vrf" | awk -F" " '{print $2}'`
for vrf in $vrf_list; do
neighbor_list=`${timeout_cmd} vtysh $ns -c "show ip bgp vrf $vrf neighbors" | grep "BGP neighbor is" | awk -F '[, ]' '{print $4}'`
for word in $neighbor_list; do
save_cmd "vtysh $ns -c \"show ip bgp vrf $vrf neighbors $word advertised-routes\"" "ip.bgp.neighbor.$vrf.$word.adv$asic_id"
save_cmd "vtysh $ns -c \"show ip bgp vrf $vrf neighbors $word routes\"" "ip.bgp.neighbor.$vrf.$word.rcv$asic_id"
done
done
}
###############################################################################
# Iterates all ASIC namespaces on multi ASIC platform and on default (host)
# namespace on single ASIC platform
# Globals:
# NUM_ASICS
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bgp_neighbor_all_ns() {
trap 'handle_error $? $LINENO' ERR
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_bgp_neighbor
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
save_bgp_neighbor $i
done
fi
}
###############################################################################
# Dump the nat config, iptables rules and conntrack nat entries
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_nat_info() {
trap 'handle_error $? $LINENO' ERR
save_cmd_all_ns "iptables -t nat -nv -L" "nat.iptables"
save_cmd_all_ns "conntrack -j -L" "nat.conntrack"
save_cmd_all_ns "conntrack -j -L | wc" "nat.conntrackcount"
save_cmd_all_ns "conntrack -L" "nat.conntrackall"
save_cmd_all_ns "conntrack -L | wc" "nat.conntrackallcount"
save_cmd_all_ns "show nat config" "nat.config"
}
###############################################################################
# Dump the BFD information from vtysh
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bfd_info() {
trap 'handle_error $? $LINENO' ERR
save_vtysh "show bfd peers" "frr.bfd.peers"
save_vtysh "show bfd peers counters" "frr.bfd.peers.counters"
save_vtysh "show bfd peers json" "frr.bfd.peers.json"
save_vtysh "show bfd peers counters json" "frr.bfd.peers.counters.json"
}
###############################################################################
# Save IP related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_ip_info() {
trap 'handle_error $? $LINENO' ERR
save_ip "link" "link"
save_ip "addr" "addr"
save_ip "rule" "rule"
save_ip "route show table all" "route"
save_ip "neigh" "neigh"
save_ip "-s neigh show nud noarp" "neigh.noarp"
}
###############################################################################
# Save BGP related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_bgp_info() {
trap 'handle_error $? $LINENO' ERR
save_vtysh "show ip bgp summary" "bgp.summary"
save_vtysh "show ip bgp neighbors" "bgp.neighbors"
save_vtysh "show ip bgp" "bgp.table"
save_vtysh "show bgp ipv6 summary" "bgp.ipv6.summary"
save_vtysh "show bgp ipv6 neighbors" "bgp.ipv6.neighbors"
save_vtysh "show bgp ipv6" "bgp.ipv6.table"
save_bgp_neighbor_all_ns
}
###############################################################################
# Save FRR related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_frr_info() {
trap 'handle_error $? $LINENO' ERR
save_vtysh "show running-config" "frr.running_config"
save_vtysh "show ip route vrf all" "frr.ip_route"
save_vtysh "show ipv6 route vrf all" "frr.ip6_route"
save_vtysh "show zebra fpm stats" "frr.fpm.stats"
save_vtysh "show zebra dplane detailed" "frr.dplane"
save_vtysh "show interface vrf all" "frr.interfaces"
save_vtysh "show zebra client summary" "frr.client"
}
###############################################################################
# Save Redis DB contents
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_redis_info() {
trap 'handle_error $? $LINENO' ERR
save_redis "APPL_DB"
save_redis "ASIC_DB"
save_redis "COUNTERS_DB"
# There are secrets in CONFIG_DB need to be cleanup.
save_redis "CONFIG_DB" "CONFIG_DB" remove_secret_from_config_db_dump
save_redis "FLEX_COUNTER_DB"
save_redis "STATE_DB"
}
###############################################################################
# Given list of proc files, saves proc files to tar.
# Globals:
# V
# TARDIR
# MKDIR
# CP
# DUMPDIR
# TAR
# RM
# BASE
# TARFILE
# NOOP
# Arguments:
# *procfiles: variable-length list of proc file paths to save
# Returns:
# None
###############################################################################
save_proc() {
trap 'handle_error $? $LINENO' ERR
local procfiles="$@"
$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
}
###############################################################################
# Dumps all fields and values from given Redis DB.
# Arguments:
# DB name: DB name
# Filename: Destination filename, if not given then filename would be DB name
# cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
# Returns:
# None
###############################################################################
save_redis() {
local cleanup_method=${3:-dummy_cleanup_method}
trap 'handle_error $? $LINENO' ERR
local db_name=$1
if [ $# -ge 2 ] && [ -n "$2" ]; then
local dest_file_name=$2
else
local dest_file_name="$db_name"
fi
save_cmd_all_ns "sonic-db-dump -n '$db_name' -y" "$dest_file_name.json" false $cleanup_method
}
###############################################################################
# SAI DUMP from syncd
# Globals:
# NUM_ASICS
# Arguments:
# None
# Returns:
# None
###############################################################################
save_saidump() {
trap 'handle_error $? $LINENO' ERR
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
save_cmd "docker exec syncd saidump" "saidump"
else
for (( i=0; i<$NUM_ASICS; i++ ))
do
save_cmd "docker exec syncd$i saidump" "saidump$i"
done
fi
}
###############################################################################
# Save platform related info
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
save_platform_info() {
trap 'handle_error $? $LINENO' ERR
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"
}
###############################################################################
# Runs a comamnd and saves its output to the incrementally built tar.
# Globals:
# LOGDIR
# BASE
# MKDIR
# TAR
# TARFILE
# DUMPDIR
# V
# RM
# NOOP
# Arguments:
# filename: the full path of the file to save
# base_dir: the directory in $TARDIR/ to stage the file
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
# Returns:
# None
###############################################################################
save_file() {
trap 'handle_error $? $LINENO' ERR
local start_t=$(date +%s%3N)
local end_t=0
local orig_path=$1
local supp_dir=$2
local gz_path="$TARDIR/$supp_dir/$(basename $orig_path)"
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
if $do_gzip; then
gz_path="${gz_path}.gz"
tar_path="${tar_path}.gz"
if $NOOP; then
echo "gzip -c $orig_path > $gz_path"
else
gzip -c $orig_path > $gz_path
fi
else
if $NOOP; then
echo "cp $orig_path $gz_path"
else
cp $orig_path $gz_path
fi
fi
if $do_tar_append; then
($TAR $V -rhf $TARFILE -C $DUMPDIR "$tar_path" \
|| abort "${ERROR_PROCFS_SAVE_FAILED}" "tar append operation failed. Aborting to prevent data loss.") \
&& $RM $V -f "$gz_path"
fi
end_t=$(date +%s%3N)
echo "[ save_file:$orig_path] : $(($end_t-$start_t)) msec" >> $TECHSUPPORT_TIME_INFO
}
###############################################################################
# find_files routine
# Globals:
# SINCE_DATE: list files only newer than given date
# REFERENCE_FILE: the file to be created as a reference to compare modification time
# Arguments:
# directory: directory to search files in
# Returns:
# None
###############################################################################
find_files() {
trap 'handle_error $? $LINENO' ERR
local -r directory=$1
$TOUCH --date="${SINCE_DATE}" "${REFERENCE_FILE}"
local -r find_command="find -L $directory -type f -newer ${REFERENCE_FILE}"
echo $($find_command)
}
###############################################################################
# disable_logrotate routine
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
disable_logrotate() {
sed -i '/\/usr\/sbin\/logrotate/s/^/#/g' /etc/cron.d/logrotate
}
###############################################################################
# enable_logrotate routine
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
enable_logrotate() {
sed -i '/\/usr\/sbin\/logrotate/s/^#*//g' /etc/cron.d/logrotate
}
###############################################################################
# Collect Mellanox specific information
# Globals:
# CMD_PREFIX
# Arguments:
# None
# Returns:
# None
###############################################################################
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 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
local mst_dump_filename="/tmp/mstdump"
local max_dump_count="3"
for i in $(seq 1 $max_dump_count); do
${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
copy_from_docker syncd $sdk_dump_path /tmp/sdk-dumps
for file in $(find /tmp/sdk-dumps -type f); do
save_file ${file} sai_sdk_dump false
done
rm -rf /tmp/sdk-dumps
fi
}
###############################################################################
# Collect Broadcom specific information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
collect_broadcom() {
trap 'handle_error $? $LINENO' ERR
local platform=$(show platform summary --json | python -c 'import sys, json; \
print(json.load(sys.stdin)["platform"])')
local hwsku=$(show platform summary --json | python -c 'import sys, json; \
print(json.load(sys.stdin)["hwsku"])')
# save SAI configuration files (config.bcm, port_config.ini, sai.profile)
if [ -d /usr/share/sonic/device/${platform}/${hwsku} ]; then
# copy all the files in the HWSKU directory
pushd /usr/share/sonic/device/${platform}/${hwsku} > /dev/null
for file in $(find . -maxdepth 2 -type f); do
save_file ${file} sai false
done
popd > /dev/null
if [[ ("$NUM_ASICS" > 1) ]]; then
for (( i=0; i<$NUM_ASICS; i++ ))
do
# config.bcm - copy the one with chip common properties merged
for file in $(find /var/run/docker-syncd$i -type f -name "*.bcm"); do
save_file ${file} sai$i false
done
# sai.profile - copy the final sai.profile generated in docker-syncd
if [ -f /var/run/docker-syncd$i/sai.profile ]; then
save_file /var/run/docker-syncd$i/sai.profile sai$i false
fi
done
else
# config.bcm - copy the one with chip common properties merged
for file in $(find /var/run/docker-syncd -type f -name "*.bcm"); do
save_file ${file} sai false
done
# sai.profile - copy the final sai.profile generated in docker-syncd
if [ -f /var/run/docker-syncd/sai.profile ]; then
save_file /var/run/docker-syncd/sai.profile sai false
fi
fi
else
echo "'/usr/share/sonic/device/${platform}/${hwsku}' does not exist" > /tmp/error
save_file /tmp/error sai false
fi
save_cmd "cat /proc/bcm/knet/debug" "broadcom.knet.debug"
save_cmd "cat /proc/bcm/knet/dma" "broadcom.knet.dma"
save_cmd "cat /proc/bcm/knet/link" "broadcom.knet.link"
save_cmd "cat /proc/bcm/knet/rate" "broadcom.knet.rate"
save_bcmcmd_all_ns "-t5 version" "broadcom.version"
save_bcmcmd_all_ns "-t5 soc" "broadcom.soc"
save_bcmcmd_all_ns "-t5 ps" "broadcom.ps"
save_bcmcmd_all_ns "\"l3 nat_ingress show\"" "broadcom.nat.ingress"
save_bcmcmd_all_ns "\"l3 nat_egress show\"" "broadcom.nat.egress"
save_bcmcmd_all_ns "\"ipmc table show\"" "broadcom.ipmc"
save_bcmcmd_all_ns "\"multicast show\"" "broadcom.multicast"
save_bcmcmd_all_ns "\"conf show\"" "conf.summary"
save_bcmcmd_all_ns "\"fp show\"" "fp.summary"
save_bcmcmd_all_ns "\"pvlan show\"" "pvlan.summary"
save_bcmcmd_all_ns "\"l2 show\"" "l2.summary"
save_bcmcmd_all_ns "\"l3 intf show\"" "l3.intf.summary"
save_bcmcmd_all_ns "\"l3 defip show\"" "l3.defip.summary"
save_bcmcmd_all_ns "\"l3 l3table show\"" "l3.l3table.summary"
save_bcmcmd_all_ns "\"l3 egress show\"" "l3.egress.summary"
save_bcmcmd_all_ns "\"l3 ecmp egress show\"" "l3.ecmp.egress.summary"
save_bcmcmd_all_ns "\"l3 multipath show\"" "l3.multipath.summary"
save_bcmcmd_all_ns "\"l3 ip6host show\"" "l3.ip6host.summary"
save_bcmcmd_all_ns "\"l3 ip6route show\"" "l3.ip6route.summary"
save_bcmcmd_all_ns "\"mc show\"" "multicast.summary"
save_bcmcmd_all_ns "\"cstat *\"" "cstat.summary"
save_bcmcmd_all_ns "\"mirror show\"" "mirror.summary"
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"
}
###############################################################################
# Collect Cisco-8000 specific information
# Globals:
# None
# Arguments:
# None
# Returns:
# None
###############################################################################
collect_cisco_8000() {
trap 'handle_error $? $LINENO' ERR
local platform=$(show platform summary --json | python -c 'import sys, json; \
print(json.load(sys.stdin)["platform"])')
if [ -d /usr/share/sonic/device/${platform} ]; then
pushd /usr/share/sonic/device/${platform} > /dev/null
for file in $(find . -path "./*plugin*" -prune -o -path "./*.xml" -prune -o -path "./*.yaml" -prune -o -print); do
save_file ${file} sai false
done
popd > /dev/null
else
echo "'/usr/share/sonic/device/${platform}' does not exist" > /tmp/error
save_file /tmp/error sai false
fi
}
###############################################################################
# Save log file
# Globals:
# TAR, TARFILE, DUMPDIR, BASE, TARDIR, TECHSUPPORT_TIME_INFO
# Arguments:
# None
# Returns:
# None
###############################################################################
save_log_files() {
trap 'handle_error $? $LINENO' ERR
disable_logrotate
trap enable_logrotate HUP INT QUIT TERM KILL ABRT ALRM
start_t=$(date +%s%3N)
# gzip up all log files individually before placing them in the incremental tarball
for file in $(find_files "/var/log/"); do
# ignore the sparse file lastlog
if [ "$file" = "/var/log/lastlog" ]; then
continue
fi
# don't gzip already-gzipped log files :)
# do not append the individual files to the main tarball
if [ -z "${file##*.gz}" ]; then
save_file $file log false false
else
save_file $file log true false
fi
done
# Append the log folder to the main tarball
($TAR $V -rhf $TARFILE -C $DUMPDIR ${BASE}/log \
|| abort "${ERROR_TAR_FAILED}" "tar append operation failed. Aborting for safety") \