From a56133bcac3f5d93ba7e5243acc75488bcdf3c17 Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 16 Aug 2022 15:48:11 -0700 Subject: [PATCH] Add hardware reboot cause as actual reboot cause for soft reboot failed --- scripts/determine-reboot-cause | 39 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/scripts/determine-reboot-cause b/scripts/determine-reboot-cause index 1408ad0e2952..1e28356491a3 100755 --- a/scripts/determine-reboot-cause +++ b/scripts/determine-reboot-cause @@ -181,18 +181,41 @@ def main(): # any additional_reboot_info it will be stored as a "comment" in REBOOT_CAUSE_HISTORY_FILE additional_reboot_info = "N/A" - # Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline + # 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() - # 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() + # 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: + if not hardware_reboot_cause.startswith(REBOOT_CAUSE_NON_HARDWARE): + # Add the hardware_reboot_cause as actual reboot cause + previous_reboot_cause = hardware_reboot_cause + additional_reboot_info = software_reboot_cause + else: + previous_reboot_cause = software_reboot_cause + elif hardware_reboot_cause is not None: + # Check if any software reboot was issued before this hardware reboot happened + if software_reboot_cause is not REBOOT_CAUSE_UNKNOWN: + previous_reboot_cause = hardware_reboot_cause + additional_reboot_info = software_reboot_cause + else: + previous_reboot_cause = hardware_reboot_cause else: # Get the reboot cause from REBOOT_CAUSE_FILE - previous_reboot_cause = find_software_reboot_cause() + previous_reboot_cause = software_reboot_cause # Current time reboot_cause_gen_time = str(datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S'))