diff --git a/src/sonic-host-services/scripts/determine-reboot-cause b/src/sonic-host-services/scripts/determine-reboot-cause index 501b279ec1..8439c78a70 100755 --- a/src/sonic-host-services/scripts/determine-reboot-cause +++ b/src/sonic-host-services/scripts/determine-reboot-cause @@ -100,7 +100,7 @@ def find_proc_cmdline_reboot_cause(): return proc_cmdline_reboot_cause -def find_hardware_reboot_cause(): +def get_reboot_cause_from_platform(): # Find hardware reboot cause using sonic_platform library try: import sonic_platform @@ -112,6 +112,11 @@ def find_hardware_reboot_cause(): sonic_logger.log_warning("sonic_platform package not installed. Unable to detect hardware reboot causes.") hardware_reboot_cause_major, hardware_reboot_cause_minor = REBOOT_CAUSE_NON_HARDWARE, "N/A" + return hardware_reboot_cause_major, hardware_reboot_cause_minor + + +def find_hardware_reboot_cause(): + hardware_reboot_cause_major, hardware_reboot_cause_minor = get_reboot_cause_from_platform() if hardware_reboot_cause_major: sonic_logger.log_info("Platform api indicates reboot cause {}".format(hardware_reboot_cause_major)) else: diff --git a/src/sonic-host-services/tests/determine-reboot-cause_test.py b/src/sonic-host-services/tests/determine-reboot-cause_test.py index 31f36dd130..afd74957b6 100644 --- a/src/sonic-host-services/tests/determine-reboot-cause_test.py +++ b/src/sonic-host-services/tests/determine-reboot-cause_test.py @@ -99,8 +99,9 @@ class TestDetermineRebootCause(object): assert result == "fast-reboot" def test_find_hardware_reboot_cause(self): - result = find_hardware_reboot_cause() - assert result == "Non-Hardware (N/A)" + with mock.patch("determine_reboot_cause.get_reboot_cause_from_platform", return_value=("Powerloss", None)): + result = find_hardware_reboot_cause() + assert result == "Powerloss (None)" def test_get_reboot_cause_dict_watchdog(self): reboot_cause_dict = get_reboot_cause_dict(REBOOT_CAUSE_WATCHDOG, "", GEN_TIME_WATCHDOG)