From 80d5fe160651d363fc476d8e93fe190bcce79586 Mon Sep 17 00:00:00 2001 From: JiangboHe <57433992+JiangboHe@users.noreply.github.com> Date: Sat, 21 Nov 2020 02:37:45 +0800 Subject: [PATCH] fix error: interface counters is mismatch after warm-reboot (#5346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Why I did it There is a issue for counters after warm-reboot: If I clear counters by command "sonic-clear counters", then execute 'warm-reboot' and whenSONiC is restart, the counters showed with command "show interface counters" is still old counters before "sonic-clear". It is not the right counters because the counters file in '/tmp' is lost in warm-reboot process. - How I did it I fixed it by saving '/tmp/portstat-0' folders in '/host/' before executing 'warm-reboot' (in pull request Azure/sonic-utilities#1099 ), and restore the counters folders back to '/tmp/' after warm-reboot process is finished. - How to verify it Clear counters by command 'sonic-clear' sonic-clear counters sonic-clear dropcounters sonic-clear pfccounters sonic-clear queuecounters sonic-clear rifcounters Execute 'warm-reboot' Use command ‘show interface counters’ to see if the counters is right. --- .../warmboot-finalizer/finalize-warmboot.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 2cde4028396b..094fff2133f7 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -76,6 +76,20 @@ function stop_control_plane_assistant() fi } +function restore_counters_folder() +{ + debug "Restoring counters folder after warmboot..." + + modules=("portstat-0" "dropstat" "pfcstat-0" "queuestat-0" "intfstat-0") + for module in ${modules[@]} + do + statfile="/host/counters/$module" + if [[ -d $statfile ]]; then + mv $statfile /tmp/ + fi + done +} + wait_for_database_service @@ -86,6 +100,8 @@ if [[ x"${WARM_BOOT}" != x"true" ]]; then exit 0 fi +restore_counters_folder + list=${COMP_LIST} # Wait up to 5 minutes