From 0bd40857d19952a0d39021606aea481a4341d388 Mon Sep 17 00:00:00 2001 From: Sujin Kang Date: Wed, 24 Aug 2022 08:36:09 -0700 Subject: [PATCH] [201811] Add the hw reboot cause if it happened during software reboot (#11752) Why I did it Add the hardware reboot cause when the previous software reboot failed How I did it Check both hardware reboot cause and software reboot cause. Add the hardware reboot as actual reboot cause if any hardware reboot cause is available for any software reboot. How to verify it Perform reboots and verify the reboot-cause --- .../process-reboot-cause/process-reboot-cause | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/files/image_config/process-reboot-cause/process-reboot-cause b/files/image_config/process-reboot-cause/process-reboot-cause index c9d57fd77b..0989db1cd2 100755 --- a/files/image_config/process-reboot-cause/process-reboot-cause +++ b/files/image_config/process-reboot-cause/process-reboot-cause @@ -37,6 +37,7 @@ 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_NON_HARDWARE = "Non-Hardware" # ========================== Syslog wrappers ========================== @@ -119,7 +120,7 @@ def find_hardware_reboot_cause(): hardware_reboot_cause_major, hardware_reboot_cause_minor = chassis.get_reboot_cause() - if hardware_reboot_cause_major == chassis.REBOOT_CAUSE_NON_HARDWARE: + if hardware_reboot_cause_major == REBOOT_CAUSE_NON_HARDWARE: # The reboot was not caused by hardware. If there is a REBOOT_CAUSE_FILE, it will # contain any software-related reboot info. We will use it as the previous cause. pass @@ -168,16 +169,30 @@ def main(): software_reboot_cause = find_software_reboot_cause() # The main decision logic of the reboot cause: - # If there is a reboot cause indicated by /proc/cmdline, it should be warmreboot/fastreboot - # the software_reboot_cause which is the content of /hosts/reboot-cause/reboot-cause.txt - # will be treated as the reboot cause - # Elif there is a reboot cause indicated by platform API, - # the hardware_reboot_cause will be treated as the reboot cause + # If there is a valid hardware reboot cause indicated by platform API, + # check the software reboot cause to add additional rebot cause. + # If there is a reboot cause indicated by /proc/cmdline, and/or warmreboot/fastreboot/softreboot + # the software_reboot_cause which is the content of /hosts/reboot-cause/reboot-cause.txt + # will be treated as the additional reboot cause + # Elif there is a cmdline reboot cause, + # the software_reboot_cause will be treated as the reboot cause if it's not unknown + # otherwise, the cmdline_reboot_cause will be treated as the reboot cause if it's not none # Else the software_reboot_cause will be treated as the reboot cause - if proc_cmdline_reboot_cause is not None: - previous_reboot_cause = software_reboot_cause - elif hardware_reboot_cause is not None: - previous_reboot_cause = hardware_reboot_cause + if hardware_reboot_cause is not None: + # Check if any software reboot was issued before this hardware reboot happened + if REBOOT_CAUSE_UNKNOWN not in software_reboot_cause: + # Add the hardware_reboot_cause as actual reboot cause + previous_reboot_cause = software_reboot_cause + " Actual reboot cause : " + hardware_reboot_cause + elif proc_cmdline_reboot_cause is not None: + previous_reboot_cause = proc_cmdline_reboot_cause + " Actual reboot cause : " + hardware_reboot_cause + else: + previous_reboot_cause = hardware_reboot_cause + elif proc_cmdline_reboot_cause is not None: + if REBOOT_CAUSE_UNKNOWN not in software_reboot_cause: + # Get the reboot cause from REBOOT_CAUSE_FILE + previous_reboot_cause = software_reboot_cause + else: + previous_reboot_cause = proc_cmdline_reboot_cause else: previous_reboot_cause = software_reboot_cause