[determine-reboot-cause] Skip invoking platform code for unit tests for hardware_reboot_cause (#6325)
What: Modify unit test to not call any platform dependent api in test_find_hardware_reboot_cause. - Why I did it MELLANOX build is failing for the recent PRs. The errors are due to platform library being invoked in a unit test for determine-reboot-cause script. Verified by running unit tests and a successful Mellanox build. Co-authored-by: Vaibhav Hemant Dixit <vadixit@microsoft.com>
This commit is contained in:
parent
ba92a081ce
commit
40f69f0aac
@ -100,7 +100,7 @@ def find_proc_cmdline_reboot_cause():
|
|||||||
return 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
|
# Find hardware reboot cause using sonic_platform library
|
||||||
try:
|
try:
|
||||||
import sonic_platform
|
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.")
|
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"
|
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:
|
if hardware_reboot_cause_major:
|
||||||
sonic_logger.log_info("Platform api indicates reboot cause {}".format(hardware_reboot_cause_major))
|
sonic_logger.log_info("Platform api indicates reboot cause {}".format(hardware_reboot_cause_major))
|
||||||
else:
|
else:
|
||||||
|
@ -99,8 +99,9 @@ class TestDetermineRebootCause(object):
|
|||||||
assert result == "fast-reboot"
|
assert result == "fast-reboot"
|
||||||
|
|
||||||
def test_find_hardware_reboot_cause(self):
|
def test_find_hardware_reboot_cause(self):
|
||||||
result = find_hardware_reboot_cause()
|
with mock.patch("determine_reboot_cause.get_reboot_cause_from_platform", return_value=("Powerloss", None)):
|
||||||
assert result == "Non-Hardware (N/A)"
|
result = find_hardware_reboot_cause()
|
||||||
|
assert result == "Powerloss (None)"
|
||||||
|
|
||||||
def test_get_reboot_cause_dict_watchdog(self):
|
def test_get_reboot_cause_dict_watchdog(self):
|
||||||
reboot_cause_dict = get_reboot_cause_dict(REBOOT_CAUSE_WATCHDOG, "", GEN_TIME_WATCHDOG)
|
reboot_cause_dict = get_reboot_cause_dict(REBOOT_CAUSE_WATCHDOG, "", GEN_TIME_WATCHDOG)
|
||||||
|
Reference in New Issue
Block a user