|
13 | 13 | try:
|
14 | 14 | from sonic_platform_base.chassis_base import ChassisBase
|
15 | 15 | from os.path import join
|
| 16 | + from glob import glob |
| 17 | + import os |
16 | 18 | import io
|
17 | 19 | import re
|
18 | 20 | import subprocess
|
19 | 21 | import syslog
|
20 | 22 | except ImportError as e:
|
21 | 23 | raise ImportError (str(e) + "- required module not found")
|
22 | 24 |
|
| 25 | +# The default dir for reboot cause files |
23 | 26 | HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/'
|
| 27 | +# The hwmon root dir used in case of the hw-mgmt v1.x.x is used. |
| 28 | +HWMON_ROOT_PATTERN = '/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*' |
24 | 29 |
|
25 | 30 | #reboot cause related definitions
|
26 |
| -REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT |
| 31 | +REBOOT_CAUSE_ROOT = None |
27 | 32 |
|
28 | 33 | REBOOT_CAUSE_POWER_LOSS_FILE = 'reset_main_pwr_fail'
|
29 | 34 | REBOOT_CAUSE_AUX_POWER_LOSS_FILE = 'reset_aux_pwr_or_ref'
|
|
37 | 42 |
|
38 | 43 | # ========================== Syslog wrappers ==========================
|
39 | 44 | SYSLOG_IDENTIFIER = "mlnx-chassis"
|
40 |
| -def log_warning(msg, also_print_to_console=False): |
| 45 | +def log_warning(msg): |
41 | 46 | syslog.openlog(SYSLOG_IDENTIFIER)
|
42 | 47 | syslog.syslog(syslog.LOG_WARNING, msg)
|
43 | 48 | syslog.closelog()
|
44 | 49 |
|
| 50 | +def log_info(msg): |
| 51 | + syslog.openlog(SYSLOG_IDENTIFIER) |
| 52 | + syslog.syslog(syslog.LOG_INFO, msg) |
| 53 | + syslog.closelog() |
45 | 54 |
|
46 | 55 | class Chassis(ChassisBase):
|
47 | 56 | """Platform-specific Chassis class"""
|
48 | 57 |
|
49 | 58 | def __init__(self):
|
| 59 | + global REBOOT_CAUSE_ROOT |
50 | 60 | super(Chassis, self).__init__()
|
51 | 61 |
|
| 62 | + # adaptively reboot cause root dir initialization |
| 63 | + REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT |
| 64 | + if not os.path.exists(REBOOT_CAUSE_ROOT): |
| 65 | + log_warning("reboot cause dir {} doesn't exist, trying other alternatives".format(REBOOT_CAUSE_ROOT)) |
| 66 | + possible_reboot_cause_dir_list = glob(HWMON_ROOT_PATTERN) |
| 67 | + if possible_reboot_cause_dir_list is None or len(possible_reboot_cause_dir_list) == 0: |
| 68 | + log_warning("can't find reboot cause files in {}".format(HWMON_ROOT_PATTERN)) |
| 69 | + else: |
| 70 | + REBOOT_CAUSE_ROOT = possible_reboot_cause_dir_list[0] |
| 71 | + if len(possible_reboot_cause_dir_list) > 1: |
| 72 | + log_warning("found multiple reboot cause dir {}, pick the first one".format(possible_reboot_cause_dir_list)) |
| 73 | + else: |
| 74 | + log_info("pick {} as reboot cause file".format(REBOOT_CAUSE_ROOT)) |
| 75 | + |
52 | 76 | def _read_generic_file(self, filename, len):
|
53 | 77 | """
|
54 | 78 | Read a generic file, returns the contents of the file
|
|
0 commit comments