12
12
import sys
13
13
import syslog
14
14
import re
15
+
16
+ import sonic_device_util
15
17
except ImportError as err :
16
18
raise ImportError ("%s - required module not found" % str (err ))
17
19
@@ -34,7 +36,7 @@ REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline"
34
36
REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*"
35
37
REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*"
36
38
37
- UNKNOWN_REBOOT_CAUSE = "Unknown"
39
+ REBOOT_CAUSE_UNKNOWN = "Unknown"
38
40
39
41
40
42
# ========================== Syslog wrappers ==========================
@@ -72,7 +74,7 @@ def parse_warmfast_reboot_from_proc_cmdline():
72
74
73
75
74
76
def find_software_reboot_cause ():
75
- software_reboot_cause = UNKNOWN_REBOOT_CAUSE
77
+ software_reboot_cause = REBOOT_CAUSE_UNKNOWN
76
78
77
79
if os .path .isfile (REBOOT_CAUSE_FILE ):
78
80
with open (REBOOT_CAUSE_FILE , "r" ) as cause_file :
@@ -82,6 +84,10 @@ def find_software_reboot_cause():
82
84
log_info ("Reboot cause file {} not found" .format (REBOOT_CAUSE_FILE ))
83
85
84
86
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 )
85
91
os .remove (FIRST_BOOT_PLATFORM_FILE )
86
92
87
93
return software_reboot_cause
@@ -148,7 +154,7 @@ def main():
148
154
os .remove (PREVIOUS_REBOOT_CAUSE_FILE )
149
155
150
156
# Set a default previous reboot cause
151
- previous_reboot_cause = UNKNOWN_REBOOT_CAUSE
157
+ previous_reboot_cause = REBOOT_CAUSE_UNKNOWN
152
158
153
159
# 1. Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline
154
160
proc_cmdline_reboot_cause = find_proc_cmdline_reboot_cause ()
@@ -188,7 +194,7 @@ def main():
188
194
189
195
# Write a new default reboot cause file for the next reboot
190
196
with open (REBOOT_CAUSE_FILE , "w" ) as cause_file :
191
- cause_file .write (UNKNOWN_REBOOT_CAUSE )
197
+ cause_file .write (REBOOT_CAUSE_UNKNOWN )
192
198
193
199
194
200
if __name__ == "__main__" :
0 commit comments