fix error: interface counters is mismatch after warm-reboot (#5346)

- 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.
This commit is contained in:
JiangboHe 2020-11-21 02:37:45 +08:00 committed by GitHub
parent 7bf05f7f4f
commit 461e43649b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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