Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Handle NotImplementedError in determine-reboot-cause that will be thrown on VS Chassis platform #211

Merged
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
14 changes: 7 additions & 7 deletions scripts/determine-reboot-cause
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def get_reboot_cause_from_platform():
chassis = platform.get_chassis()
hardware_reboot_cause_major, hardware_reboot_cause_minor = chassis.get_reboot_cause()
sonic_logger.log_info("Platform api returns reboot cause {}, {}".format(hardware_reboot_cause_major, hardware_reboot_cause_minor))
except (ImportError, FileNotFoundError):
sonic_logger.log_warning("sonic_platform package not installed. Unable to detect hardware reboot causes.")
except (ImportError, FileNotFoundError, NotImplementedError):
sonic_logger.log_warning("sonic_platform package not installed or not implemented. 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
Expand Down Expand Up @@ -143,7 +143,7 @@ def get_reboot_cause_dict(previous_reboot_cause, comment, gen_time):
If user issued a command to reboot device, then user, command and time will be
stored into a dictionary.

If device was rebooted due to the kernel panic, then the string `Kernel Panic`
If device was rebooted due to the kernel panic, then the string `Kernel Panic`
and time will be stored into a dictionary.
"""
reboot_cause_dict = {}
Expand All @@ -165,7 +165,7 @@ def get_reboot_cause_dict(previous_reboot_cause, comment, gen_time):
if match is not None:
reboot_cause_dict['cause'] = "Kernel Panic"
reboot_cause_dict['time'] = match.group(1)

return reboot_cause_dict

def determine_reboot_cause():
Expand All @@ -185,12 +185,12 @@ def determine_reboot_cause():
software_reboot_cause = find_software_reboot_cause()

# The main decision logic of the reboot cause:
# If there is a valid hardware reboot cause indicated by platform API,
# If there is a valid hardware reboot cause indicated by platform API,
# check the software reboot cause to add additional reboot cause.
# If there is a reboot cause indicated by /proc/cmdline, and/or warmreboot/fastreboot/softreboot
# the software_reboot_cause which is the content of /hosts/reboot-cause/reboot-cause.txt
# will be treated as the additional reboot cause
# Elif there is a cmdline reboot cause,
# Elif there is a cmdline reboot cause,
# the software_reboot_cause will be treated as the reboot cause if it's not unknown
# otherwise, the cmdline_reboot_cause will be treated as the reboot cause if it's not none
# Else the software_reboot_cause will be treated as the reboot cause
Expand Down Expand Up @@ -266,7 +266,7 @@ def main():
# Write the previous reboot cause to REBOOT_CAUSE_HISTORY_FILE as a JSON format
with open(REBOOT_CAUSE_HISTORY_FILE, "w") as reboot_cause_history_file:
json.dump(reboot_cause_dict, reboot_cause_history_file)

# Remove stale PREVIOUS_REBOOT_CAUSE_FILE if it exists
if os.path.exists(PREVIOUS_REBOOT_CAUSE_FILE) or os.path.islink(PREVIOUS_REBOOT_CAUSE_FILE):
os.remove(PREVIOUS_REBOOT_CAUSE_FILE)
Expand Down
6 changes: 5 additions & 1 deletion tests/determine-reboot-cause_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def test_find_hardware_reboot_cause_with_minor(self):
result = determine_reboot_cause.find_hardware_reboot_cause()
assert result == "Powerloss (under-voltage)"

def test_find_hardware_reboot_cause_not_installed_or_not_implemented(self):
result = determine_reboot_cause.find_hardware_reboot_cause()
assert result == REBOOT_CAUSE_NON_HARDWARE + " (N/A)"

def test_get_reboot_cause_dict_watchdog(self):
reboot_cause_dict = determine_reboot_cause.get_reboot_cause_dict(REBOOT_CAUSE_WATCHDOG, "", GEN_TIME_WATCHDOG)
assert reboot_cause_dict == EXPECTED_WATCHDOG_REBOOT_CAUSE_DICT
Expand Down Expand Up @@ -210,7 +214,7 @@ def test_determine_reboot_cause_main_with_reboot_cause_dir(self):
with mock.patch("os.geteuid", return_value=0):
determine_reboot_cause.main()
assert os.path.exists("host/reboot-cause/reboot-cause.txt") == True
assert os.path.exists("host/reboot-cause/previous-reboot-cause.json") == True
assert os.path.exists("host/reboot-cause/previous-reboot-cause.json") == True

def create_mock_platform_json(self, dpus):
"""Helper function to create a mock platform.json file."""
Expand Down
Loading