From 796574f90e19f4e74ce802b5087c56dbd6f258b1 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 6 May 2020 00:36:05 +0000 Subject: [PATCH 1/3] [process-reboot-cause] Add 'SONiC image installation' reboot cause --- files/image_config/process-reboot-cause/process-reboot-cause | 2 ++ 1 file changed, 2 insertions(+) diff --git a/files/image_config/process-reboot-cause/process-reboot-cause b/files/image_config/process-reboot-cause/process-reboot-cause index 409deb7d6859..4a0dc17baa05 100755 --- a/files/image_config/process-reboot-cause/process-reboot-cause +++ b/files/image_config/process-reboot-cause/process-reboot-cause @@ -82,6 +82,8 @@ def find_software_reboot_cause(): log_info("Reboot cause file {} not found".format(REBOOT_CAUSE_FILE)) if os.path.isfile(FIRST_BOOT_PLATFORM_FILE): + if software_reboot_cause == UNKNOWN_REBOOT_CAUSE: + software_reboot_cause = "SONiC image installation" os.remove(FIRST_BOOT_PLATFORM_FILE) return software_reboot_cause From 570fc901c4410fa65837a1a8d2b5db68128e1956 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 6 May 2020 22:01:52 +0000 Subject: [PATCH 2/3] Create 'REBOOT_CAUSE_SONIC_IMAGE_INSTALL' constant --- .../process-reboot-cause/process-reboot-cause | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/files/image_config/process-reboot-cause/process-reboot-cause b/files/image_config/process-reboot-cause/process-reboot-cause index 4a0dc17baa05..040912d0da87 100755 --- a/files/image_config/process-reboot-cause/process-reboot-cause +++ b/files/image_config/process-reboot-cause/process-reboot-cause @@ -34,7 +34,8 @@ REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline" REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*" REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*" -UNKNOWN_REBOOT_CAUSE = "Unknown" +REBOOT_CAUSE_UNKNOWN = "Unknown" +REBOOT_CAUSE_SONIC_IMAGE_INSTALL = "SONiC image installation" # ========================== Syslog wrappers ========================== @@ -72,7 +73,7 @@ def parse_warmfast_reboot_from_proc_cmdline(): def find_software_reboot_cause(): - software_reboot_cause = UNKNOWN_REBOOT_CAUSE + software_reboot_cause = REBOOT_CAUSE_UNKNOWN if os.path.isfile(REBOOT_CAUSE_FILE): with open(REBOOT_CAUSE_FILE, "r") as cause_file: @@ -82,8 +83,8 @@ def find_software_reboot_cause(): log_info("Reboot cause file {} not found".format(REBOOT_CAUSE_FILE)) if os.path.isfile(FIRST_BOOT_PLATFORM_FILE): - if software_reboot_cause == UNKNOWN_REBOOT_CAUSE: - software_reboot_cause = "SONiC image installation" + if software_reboot_cause == REBOOT_CAUSE_UNKNOWN: + software_reboot_cause = REBOOT_CAUSE_SONIC_IMAGE_INSTALL os.remove(FIRST_BOOT_PLATFORM_FILE) return software_reboot_cause @@ -150,7 +151,7 @@ def main(): os.remove(PREVIOUS_REBOOT_CAUSE_FILE) # Set a default previous reboot cause - previous_reboot_cause = UNKNOWN_REBOOT_CAUSE + previous_reboot_cause = REBOOT_CAUSE_UNKNOWN # 1. Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline proc_cmdline_reboot_cause = find_proc_cmdline_reboot_cause() @@ -190,7 +191,7 @@ def main(): # Write a new default reboot cause file for the next reboot with open(REBOOT_CAUSE_FILE, "w") as cause_file: - cause_file.write(UNKNOWN_REBOOT_CAUSE) + cause_file.write(REBOOT_CAUSE_UNKNOWN) if __name__ == "__main__": From ba7851d0b4449b6fc00258cdaf337dabed98c807 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 6 May 2020 23:54:19 +0000 Subject: [PATCH 3/3] Change reboot cause message --- .../image_config/process-reboot-cause/process-reboot-cause | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/files/image_config/process-reboot-cause/process-reboot-cause b/files/image_config/process-reboot-cause/process-reboot-cause index 040912d0da87..c9d57fd77b0a 100755 --- a/files/image_config/process-reboot-cause/process-reboot-cause +++ b/files/image_config/process-reboot-cause/process-reboot-cause @@ -12,6 +12,8 @@ try: import sys import syslog import re + + import sonic_device_util except ImportError as err: raise ImportError("%s - required module not found" % str(err)) @@ -35,7 +37,6 @@ REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*" REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*" REBOOT_CAUSE_UNKNOWN = "Unknown" -REBOOT_CAUSE_SONIC_IMAGE_INSTALL = "SONiC image installation" # ========================== Syslog wrappers ========================== @@ -84,7 +85,9 @@ def find_software_reboot_cause(): if os.path.isfile(FIRST_BOOT_PLATFORM_FILE): if software_reboot_cause == REBOOT_CAUSE_UNKNOWN: - software_reboot_cause = REBOOT_CAUSE_SONIC_IMAGE_INSTALL + version_info = sonic_device_util.get_sonic_version_info() + build_version = version_info['build_version'] if version_info else "unknown" + software_reboot_cause += " (First boot of SONiC version {})".format(build_version) os.remove(FIRST_BOOT_PLATFORM_FILE) return software_reboot_cause