[reboot-cause] Use UTC to ensure consistent sorting#293
[reboot-cause] Use UTC to ensure consistent sorting#293judyjoseph merged 5 commits intosonic-net:masterfrom
Conversation
Previously reboot cause uses local timezone. This could result in the timestamp being in UTC, IDT, or any other timezone depending on the system configuration. When reboot cause history files are sorted, mixing different timezones can lead to incorrect chronological order and cause reboot cause test failure. Now change the code to use datetime.datetime.utcnow() for reboot_cause_gen_time, ensuring that all timestamps are consistently in UTC. Signed-off-by: Jianyue Wu <[email protected]>
Signed-off-by: Jianyue Wu <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
hi @vvolam , do you mind to help reviewing this PR? |
vvolam
left a comment
There was a problem hiding this comment.
LGTM, same change might be needed in scripts/procdockerstatsd as we are still using systemtime.
sonic-host-services/scripts/procdockerstatsd
Line 248 in 0028383
Could you also update the PR description with the reboot history command after the fix?
OK, will also update this timestamp, and also put new reboot history. |
Update 2nd timestamp in reboot cause, also use UTC. Mon Jul 28 10:15:33 AM UTC 2025 Signed-off-by: Jianyue Wu <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Jianyue Wu <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Code updated, new reboot history put in description. |
|
/azpw run |
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Jianyue Wu <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
I tried to run in local via pdb, seems that updated line is covered. Not sure why that line is still not in coverage report.
|
|
@judyjoseph Could you help review this change? Thanks😊 |
|
@vvolam @judyjoseph , Could you help also review PR for those branches? Thank you~ |
|
@jianyuewu could you provide 202411 PR as this has CP conflict |
|
Hi @judyjoseph , could you help to suggest whether this PR should go to 202505 branch, thanks in advance |
|
hi @jianyuewu , do you mind helping pick this change to 202411? |
|
|
offline synced with Judy, good to backport to 202505 |
hi @jianyuewu , looks like the PR is created to master, might need some update. |
|
|
Removing 202412 tag since the PR is already merged in 202411. |
Previously reboot cause uses local timezone. This could result in the timestamp being in UTC, IDT, or any other timezone depending on the system configuration. When reboot cause history files are sorted, mixing different timezones can lead to incorrect chronological order and cause reboot cause test failure.
Now change the code to use datetime.datetime.utcnow() for reboot_cause_gen_time, ensuring that all timestamps are consistently in UTC.
Details:
Previously reboot-cause history will sort by name, name is using system time, could be UTC or IDT.
2025_07_28_10_48_14 reboot Mon Jul 28 01:45:45 PM IDT 2025 admin N/A
Here left side 10_48_14 is UTC time, while right side 01:45:45 is IDT time.
2025_07_28_13_41_44 reboot Mon Jul 28 01:39:13 PM IDT 2025 admin N/A
Left and right are both IDT time.
We need to make left side time aligned, so sort index will be always correct.
show reboot-cause history cmd:
Reboot cause history in test:
After fix, now both timestamps use UTC.
$ show reboot-cause history Name Cause Time User Comment ------------------- ----------- ------------------------------- ------ --------- 2025_08_06_05_45_15 reboot Wed Aug 6 05:44:00 AM UTC 2025 admin N/A 2025_08_06_05_43_13 reboot Wed Aug 6 05:41:59 AM UTC 2025 admin N/A 2025_08_06_05_40_56 reboot Wed Aug 6 05:39:41 AM UTC 2025 admin N/A 2025_08_06_05_38_42 reboot Wed Aug 6 05:35:43 AM UTC 2025 admin N/A 2025_08_06_03_20_24 reboot Wed Aug 6 03:17:30 AM UTC 2025 admin N/A 2025_08_01_14_18_34 fast-reboot Fri Aug 1 02:17:17 PM UTC 2025 admin N/A 2025_08_01_13_54_35 fast-reboot Fri Aug 1 01:53:17 PM UTC 2025 admin N/A 2025_08_01_13_28_36 fast-reboot Fri Aug 1 01:27:18 PM UTC 2025 admin N/A 2025_08_01_13_23_31 fast-reboot Fri Aug 1 01:22:14 PM UTC 2025 admin N/A 2025_08_01_10_29_28 fast-reboot Fri Aug 1 10:28:12 AM UTC 2025 admin N/A