Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[determine-reboot-cause] Skip invoking platform code for unit tests for hardware_reboot_cause #6325

Merged
merged 2 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sonic-host-services/scripts/determine-reboot-cause
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def test_find_proc_cmdline_reboot_cause(self):
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)
Expand Down