From 5becc2ac7ee6f7fe628a82d33841748fea8bcd21 Mon Sep 17 00:00:00 2001 From: Vaibhav Hemant Dixit Date: Tue, 5 Jan 2021 10:47:42 -0800 Subject: [PATCH] [determine-reboot-cause] Ignore non-hardware reboot cause (#6349) - Why I did it - Reboot cause prints "Non-Hardware (N/A)" instead of showing the software reboot cause. The issue is mishandling of hardware reboot cause in determine-reboot-cause script. - How I did it Fixed the handling for Non Hardware reboot cause. Ignore if Non-Hardware is present in the hardware_reboot_cause output. Added some code refactoring for simplicity. - How to verify it - With fix, the hardware reboot cause is ignored (if it is non hw): --- .../scripts/determine-reboot-cause | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/sonic-host-services/scripts/determine-reboot-cause b/src/sonic-host-services/scripts/determine-reboot-cause index 8439c78a70..8f1ee0a39b 100755 --- a/src/sonic-host-services/scripts/determine-reboot-cause +++ b/src/sonic-host-services/scripts/determine-reboot-cause @@ -164,35 +164,22 @@ def main(): if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE): os.remove(PREVIOUS_REBOOT_CAUSE_FILE) - hardware_reboot_cause = None # This variable is kept for future-use purpose. When proc_cmd_line/vendor/software provides # any additional_reboot_info it will be stored as a "comment" in REBOOT_CAUSE_HISTORY_FILE additional_reboot_info = "N/A" - # 1. Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline + # 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() - # 2. Check if the previous reboot was caused by hardware - # If yes, the hardware reboot cause will be treated as the reboot cause - hardware_reboot_cause = find_hardware_reboot_cause() - - # 3. If there is a REBOOT_CAUSE_FILE, it will contain any software-related - # reboot info. We will use it as the previous cause. - 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 - # 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 REBOOT_CAUSE_NON_HARDWARE: - previous_reboot_cause = hardware_reboot_cause + # If /proc/cmdline does not indicate reboot cause, check if the previous reboot was caused by hardware + if proc_cmdline_reboot_cause is None: + previous_reboot_cause = find_hardware_reboot_cause() + if previous_reboot_cause.startswith(REBOOT_CAUSE_NON_HARDWARE): + # If the reboot cause is non-hardware, get the reboot cause from REBOOT_CAUSE_FILE + previous_reboot_cause = find_software_reboot_cause() else: - previous_reboot_cause = software_reboot_cause + # Get the reboot cause from REBOOT_CAUSE_FILE + previous_reboot_cause = find_software_reboot_cause() # Current time reboot_cause_gen_time = str(datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S'))