Skip to content

Commit ceb8784

Browse files
jlevequeyxieca
authored andcommitted
[process-reboot-cause] If software reboot cause is unknown add note if first boot into new image (#4538)
1 parent 708d901 commit ceb8784

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

files/image_config/process-reboot-cause/process-reboot-cause

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ try:
1212
import sys
1313
import syslog
1414
import re
15+
16+
import sonic_device_util
1517
except ImportError as err:
1618
raise ImportError("%s - required module not found" % str(err))
1719

@@ -34,7 +36,7 @@ REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline"
3436
REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*"
3537
REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*"
3638

37-
UNKNOWN_REBOOT_CAUSE = "Unknown"
39+
REBOOT_CAUSE_UNKNOWN = "Unknown"
3840

3941

4042
# ========================== Syslog wrappers ==========================
@@ -72,7 +74,7 @@ def parse_warmfast_reboot_from_proc_cmdline():
7274

7375

7476
def find_software_reboot_cause():
75-
software_reboot_cause = UNKNOWN_REBOOT_CAUSE
77+
software_reboot_cause = REBOOT_CAUSE_UNKNOWN
7678

7779
if os.path.isfile(REBOOT_CAUSE_FILE):
7880
with open(REBOOT_CAUSE_FILE, "r") as cause_file:
@@ -82,6 +84,10 @@ def find_software_reboot_cause():
8284
log_info("Reboot cause file {} not found".format(REBOOT_CAUSE_FILE))
8385

8486
if os.path.isfile(FIRST_BOOT_PLATFORM_FILE):
87+
if software_reboot_cause == REBOOT_CAUSE_UNKNOWN:
88+
version_info = sonic_device_util.get_sonic_version_info()
89+
build_version = version_info['build_version'] if version_info else "unknown"
90+
software_reboot_cause += " (First boot of SONiC version {})".format(build_version)
8591
os.remove(FIRST_BOOT_PLATFORM_FILE)
8692

8793
return software_reboot_cause
@@ -148,7 +154,7 @@ def main():
148154
os.remove(PREVIOUS_REBOOT_CAUSE_FILE)
149155

150156
# Set a default previous reboot cause
151-
previous_reboot_cause = UNKNOWN_REBOOT_CAUSE
157+
previous_reboot_cause = REBOOT_CAUSE_UNKNOWN
152158

153159
# 1. Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline
154160
proc_cmdline_reboot_cause = find_proc_cmdline_reboot_cause()
@@ -188,7 +194,7 @@ def main():
188194

189195
# Write a new default reboot cause file for the next reboot
190196
with open(REBOOT_CAUSE_FILE, "w") as cause_file:
191-
cause_file.write(UNKNOWN_REBOOT_CAUSE)
197+
cause_file.write(REBOOT_CAUSE_UNKNOWN)
192198

193199

194200
if __name__ == "__main__":

0 commit comments

Comments
 (0)