Skip to content

Commit 7ba42c6

Browse files
ymd-aristaFengPan-Frank
authored andcommitted
Use more generic JSON reboot cause extra info file (sonic-net#22638)
Use a more structured file format to hold reboot cause information. Also match the cause and user to that used in the tests. Signed-off-by: Mohan Yelugoti <[email protected]> Signed-off-by: Feng Pan <[email protected]>
1 parent 1fc2756 commit 7ba42c6

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#!/usr/bin/env python3
22

3+
import json
34
import os
45
from datetime import datetime, timezone
56

67
REBOOT_CAUSE_DIR = "/host/reboot-cause/"
7-
REBOOT_LC_BY_SUPERVISOR_FILE = os.path.join(REBOOT_CAUSE_DIR, "reboot-lc-by-supervisor.txt")
8+
REBOOT_CAUSE_PLATFORM_DIR = "/host/reboot-cause/platform"
9+
REBOOT_EXTRA_INFO_FILE = os.path.join(REBOOT_CAUSE_PLATFORM_DIR, "reboot-extra-info.json")
810

911
def main():
10-
reboot_time = datetime.now(timezone.utc).strftime("%a %b %d %I:%M:%S %p %Z %Y")
11-
12-
if os.path.exists(REBOOT_LC_BY_SUPERVISOR_FILE):
13-
os.remove(REBOOT_LC_BY_SUPERVISOR_FILE)
14-
with open(os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt"), 'w') as reboot_cause_file:
15-
reboot_msg = "User issued 'Reboot from Supervisor' command [User: Supervisor, Time: {}]".format(reboot_time)
16-
reboot_cause_file.write(reboot_msg)
12+
if os.path.exists(REBOOT_EXTRA_INFO_FILE):
13+
with open(REBOOT_EXTRA_INFO_FILE, 'r', encoding='utf-8') as f:
14+
data = json.load(f)
15+
os.remove(REBOOT_EXTRA_INFO_FILE)
16+
who = data.get('from', None)
17+
when = data.get('when', None)
18+
if who is not None:
19+
who = who.capitalize()
20+
with open(os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt"), 'w') as reboot_cause_file:
21+
reboot_msg = f"User issued 'Reboot from {who}' command [User: {who}, Time: {when}]"
22+
reboot_cause_file.write(reboot_msg)
1723

1824
if __name__ == "__main__":
1925
main()

0 commit comments

Comments
 (0)