|
13 | 13 | from sonic_py_common.logger import Logger
|
14 | 14 | from os import listdir
|
15 | 15 | from os.path import isfile, join
|
| 16 | + from . import utils |
16 | 17 | import sys
|
17 | 18 | import io
|
18 | 19 | import re
|
|
38 | 39 |
|
39 | 40 | REBOOT_CAUSE_FILE_LENGTH = 1
|
40 | 41 |
|
| 42 | +REBOOT_TYPE_KEXEC_FILE = "/proc/cmdline" |
| 43 | +REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*" |
| 44 | +REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*" |
| 45 | + |
41 | 46 | # Global logger class instance
|
42 | 47 | logger = Logger()
|
43 | 48 |
|
@@ -350,6 +355,17 @@ def _verify_reboot_cause(self, filename):
|
350 | 355 | '''
|
351 | 356 | return bool(int(self._read_generic_file(join(REBOOT_CAUSE_ROOT, filename), REBOOT_CAUSE_FILE_LENGTH).rstrip('\n')))
|
352 | 357 |
|
| 358 | + def _parse_warmfast_reboot_from_proc_cmdline(self): |
| 359 | + if isfile(REBOOT_TYPE_KEXEC_FILE): |
| 360 | + with open(REBOOT_TYPE_KEXEC_FILE) as cause_file: |
| 361 | + cause_file_kexec = cause_file.readline() |
| 362 | + m = re.search(REBOOT_TYPE_KEXEC_PATTERN_WARM, cause_file_kexec) |
| 363 | + if m and m.group(1): |
| 364 | + return 'warm-reboot' |
| 365 | + m = re.search(REBOOT_TYPE_KEXEC_PATTERN_FAST, cause_file_kexec) |
| 366 | + if m and m.group(1): |
| 367 | + return 'fast-reboot' |
| 368 | + return None |
353 | 369 |
|
354 | 370 | def initialize_reboot_cause(self):
|
355 | 371 | self.reboot_major_cause_dict = {
|
@@ -388,6 +404,13 @@ def get_reboot_cause(self):
|
388 | 404 | is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
|
389 | 405 | to pass a description of the reboot cause.
|
390 | 406 | """
|
| 407 | + # To avoid the leftover hardware reboot cause confusing the reboot cause determine service |
| 408 | + # Skip the hardware reboot cause check if warm/fast reboot cause found from cmdline |
| 409 | + if utils.is_host(): |
| 410 | + reboot_cause = self._parse_warmfast_reboot_from_proc_cmdline() |
| 411 | + if reboot_cause: |
| 412 | + return self.REBOOT_CAUSE_NON_HARDWARE, '' |
| 413 | + |
391 | 414 | #read reboot causes files in the following order
|
392 | 415 | if not self.reboot_cause_initialized:
|
393 | 416 | self.initialize_reboot_cause()
|
|
0 commit comments