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

[process-reboot-cause] If software reboot cause is unknown add note if first boot into new image #4538

Merged
merged 3 commits into from
May 7, 2020
Merged
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: 10 additions & 4 deletions files/image_config/process-reboot-cause/process-reboot-cause
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ try:
import sys
import syslog
import re

import sonic_device_util
except ImportError as err:
raise ImportError("%s - required module not found" % str(err))

Expand All @@ -34,7 +36,7 @@ REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline"
REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*"
REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*"

UNKNOWN_REBOOT_CAUSE = "Unknown"
REBOOT_CAUSE_UNKNOWN = "Unknown"


# ========================== Syslog wrappers ==========================
Expand Down Expand Up @@ -72,7 +74,7 @@ def parse_warmfast_reboot_from_proc_cmdline():


def find_software_reboot_cause():
software_reboot_cause = UNKNOWN_REBOOT_CAUSE
software_reboot_cause = REBOOT_CAUSE_UNKNOWN

if os.path.isfile(REBOOT_CAUSE_FILE):
with open(REBOOT_CAUSE_FILE, "r") as cause_file:
Expand All @@ -82,6 +84,10 @@ def find_software_reboot_cause():
log_info("Reboot cause file {} not found".format(REBOOT_CAUSE_FILE))

if os.path.isfile(FIRST_BOOT_PLATFORM_FILE):
if software_reboot_cause == REBOOT_CAUSE_UNKNOWN:
version_info = sonic_device_util.get_sonic_version_info()
build_version = version_info['build_version'] if version_info else "unknown"
software_reboot_cause += " (First boot of SONiC version {})".format(build_version)
os.remove(FIRST_BOOT_PLATFORM_FILE)

return software_reboot_cause
Expand Down Expand Up @@ -148,7 +154,7 @@ def main():
os.remove(PREVIOUS_REBOOT_CAUSE_FILE)

# Set a default previous reboot cause
previous_reboot_cause = UNKNOWN_REBOOT_CAUSE
previous_reboot_cause = REBOOT_CAUSE_UNKNOWN

# 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()
Expand Down Expand Up @@ -188,7 +194,7 @@ def main():

# Write a new default reboot cause file for the next reboot
with open(REBOOT_CAUSE_FILE, "w") as cause_file:
cause_file.write(UNKNOWN_REBOOT_CAUSE)
cause_file.write(REBOOT_CAUSE_UNKNOWN)


if __name__ == "__main__":
Expand Down