Skip to content

Commit a569bfc

Browse files
authored
skip hw reboot cause if warm/fast reboot found from the proc cmdline (#13378)
#### Why I did it Backport #13246 to 202012 branch. In case of warm/fast reboot, the hardware reboot cause will NOT be cleared because CPLD will not be touched in this flow. To not confuse the reboot cause determine logic, the leftover hardware reboot cause shall be skipped by the platform API, platform API will return the 'REBOOT_CAUSE_NON_HARDWARE' instead of the "hardware" reboot cause. #### How I did it Check the proc cmdline to see whether the last reboot is a warm or fast reboot, if yes skip checking the leftover hardware reboot cause. #### How to verify it a. Manual test: > 1. Perform a power loss > 2. Perform a warm/fast reboot > 3. check the reboot cause should be "warm-reboot" or "fast-reboot" instead of "power loss" b. Run reboot cause related regression test.
1 parent 5193a96 commit a569bfc

File tree

1 file changed

+23
-0
lines changed
  • platform/mellanox/mlnx-platform-api/sonic_platform

1 file changed

+23
-0
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from sonic_py_common.logger import Logger
1414
from os import listdir
1515
from os.path import isfile, join
16+
from . import utils
1617
import sys
1718
import io
1819
import re
@@ -38,6 +39,10 @@
3839

3940
REBOOT_CAUSE_FILE_LENGTH = 1
4041

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+
4146
# Global logger class instance
4247
logger = Logger()
4348

@@ -350,6 +355,17 @@ def _verify_reboot_cause(self, filename):
350355
'''
351356
return bool(int(self._read_generic_file(join(REBOOT_CAUSE_ROOT, filename), REBOOT_CAUSE_FILE_LENGTH).rstrip('\n')))
352357

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
353369

354370
def initialize_reboot_cause(self):
355371
self.reboot_major_cause_dict = {
@@ -388,6 +404,13 @@ def get_reboot_cause(self):
388404
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
389405
to pass a description of the reboot cause.
390406
"""
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+
391414
#read reboot causes files in the following order
392415
if not self.reboot_cause_initialized:
393416
self.initialize_reboot_cause()

0 commit comments

Comments
 (0)