2021-10-17 11:03:02 -05:00
|
|
|
#
|
2023-09-23 02:19:27 -05:00
|
|
|
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
|
2021-10-17 11:03:02 -05:00
|
|
|
# Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2019-04-21 16:34:28 -05:00
|
|
|
#############################################################################
|
|
|
|
# Mellanox
|
|
|
|
#
|
|
|
|
# Module contains an implementation of SONiC Platform Base API and
|
|
|
|
# provides the Chassis information which are available in the platform
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
try:
|
|
|
|
from sonic_platform_base.chassis_base import ChassisBase
|
2020-08-03 13:43:12 -05:00
|
|
|
from sonic_py_common.logger import Logger
|
2021-10-24 23:59:06 -05:00
|
|
|
import os
|
|
|
|
from functools import reduce
|
2022-06-20 21:12:20 -05:00
|
|
|
from .utils import extract_RJ45_ports_index
|
2021-10-24 23:59:06 -05:00
|
|
|
from . import utils
|
|
|
|
from .device_data import DeviceDataManager
|
2023-01-11 08:50:46 -06:00
|
|
|
import re
|
2023-12-07 06:54:56 -06:00
|
|
|
import queue
|
|
|
|
import threading
|
2023-02-14 00:26:25 -06:00
|
|
|
import time
|
2023-12-07 06:54:56 -06:00
|
|
|
from sonic_platform import modules_mgmt
|
2019-04-21 16:34:28 -05:00
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError (str(e) + "- required module not found")
|
|
|
|
|
2019-07-28 07:18:39 -05:00
|
|
|
|
2022-06-20 21:12:20 -05:00
|
|
|
RJ45_TYPE = "RJ45"
|
|
|
|
|
2021-05-24 11:37:59 -05:00
|
|
|
DMI_FILE = '/sys/firmware/dmi/entries/2-0/raw'
|
|
|
|
DMI_HEADER_LEN = 15
|
|
|
|
DMI_PRODUCT_NAME = "Product Name"
|
|
|
|
DMI_MANUFACTURER = "Manufacturer"
|
|
|
|
DMI_VERSION = "Version"
|
|
|
|
DMI_SERIAL = "Serial Number"
|
|
|
|
DMI_ASSET_TAG = "Asset Tag"
|
|
|
|
DMI_LOC = "Location In Chassis"
|
|
|
|
DMI_TABLE_MAP = {
|
|
|
|
DMI_PRODUCT_NAME: 0,
|
|
|
|
DMI_MANUFACTURER: 1,
|
|
|
|
DMI_VERSION: 2,
|
|
|
|
DMI_SERIAL: 3,
|
|
|
|
DMI_ASSET_TAG: 4,
|
|
|
|
DMI_LOC: 5
|
|
|
|
}
|
|
|
|
|
2019-07-04 06:29:58 -05:00
|
|
|
HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/'
|
|
|
|
|
|
|
|
#reboot cause related definitions
|
|
|
|
REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT
|
2023-10-03 20:58:31 -05:00
|
|
|
REBOOT_CAUSE_MAX_WAIT_TIME = 45
|
|
|
|
REBOOT_CAUSE_CHECK_INTERVAL = 5
|
|
|
|
REBOOT_CAUSE_READY_FILE = '/run/hw-management/config/reset_attr_ready'
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2023-01-11 08:50:46 -06:00
|
|
|
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).*"
|
|
|
|
|
2019-07-04 06:29:58 -05:00
|
|
|
# Global logger class instance
|
2019-10-15 13:29:45 -05:00
|
|
|
logger = Logger()
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2019-04-21 16:34:28 -05:00
|
|
|
class Chassis(ChassisBase):
|
|
|
|
"""Platform-specific Chassis class"""
|
|
|
|
|
2020-07-13 12:22:39 -05:00
|
|
|
# System status LED
|
|
|
|
_led = None
|
|
|
|
|
2023-05-16 00:24:39 -05:00
|
|
|
# System UID LED
|
|
|
|
_led_uid = None
|
|
|
|
|
2023-12-13 06:19:44 -06:00
|
|
|
chassis_instance = None
|
|
|
|
|
2019-04-21 16:34:28 -05:00
|
|
|
def __init__(self):
|
2019-07-04 06:29:58 -05:00
|
|
|
super(Chassis, self).__init__()
|
2019-04-21 16:34:28 -05:00
|
|
|
|
2021-05-24 11:37:59 -05:00
|
|
|
# Initialize DMI data
|
|
|
|
self.dmi_data = None
|
2022-03-23 02:16:03 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
# move the initialization of each components to their dedicated initializer
|
|
|
|
# which will be called from platform
|
[Mellanox] Optimize SFP modules initialization (#7537)
Originally, SFP modules were always accessed from platform daemons, and arbitrary SFP modules can be accessed in the daemon. So all SFP modules were initialized in one shot once one of the following chassis APIs called
- get_all_sfps
- get_sfp_numbers
- get_sfp
Recently, we noticed that SFP modules can also be accessed from CLI, eg. the latest refactor of `sfputil`.
In this case, only one SFP module is accessed in the chassis object's life cycle.
To initialize all SFP modules in one shot is waste of time and causes the CLI to take much more time to finish.
So we would like to optimize the initialization flow by introducing a two-phase initialization approach:
- Partial initialization, which means the `chassis._sfp_list` has been initialized with proper length and all elements being `None`
- Full initialization, which means all elements in `chassis._sfp_list` are created
If the relevant function is called,
- `get_sfp`, only partial initialization will be done, and then the specific SFP module is initialized.
- `get_all_sfps` or `get_num_sfps`, full initialization will be done, which means all SFP modules are initialized.
Signed-off-by: Stephen Sun <stephens@nvidia.com>
2021-05-06 12:14:48 -05:00
|
|
|
#
|
|
|
|
# Multiple scenarios need to be taken into consideration regarding the SFP modules initialization.
|
|
|
|
# - Platform daemons
|
|
|
|
# - Can access multiple or all SFP modules
|
|
|
|
# - sfputil
|
|
|
|
# - Sometimes can access only one SFP module
|
|
|
|
# - Call get_sfp to get one SFP module object
|
|
|
|
#
|
|
|
|
# We should initialize all SFP modules only if it is necessary because initializing SFP module is time-consuming.
|
|
|
|
# This means,
|
|
|
|
# - If get_sfp is called,
|
|
|
|
# - If the _sfp_list isn't initialized, initialize it first.
|
|
|
|
# - Only the SFP module being required should be initialized.
|
|
|
|
# - If get_all_sfps is called,
|
|
|
|
# - If the _sfp_list isn't initialized, initialize it first.
|
|
|
|
# - All SFP modules need to be initialized.
|
|
|
|
# But the SFP modules that have already been initialized should not be initialized for the second time.
|
|
|
|
# This can caused by get_sfp being called before.
|
|
|
|
#
|
|
|
|
# Due to the complexity of SFP modules initialization, we have to introduce two initialized flags for SFP modules
|
|
|
|
# - sfp_module_partial_initialized:
|
|
|
|
# - False: The _sfp_list is [] (SFP stuff has never been accessed)
|
|
|
|
# - True: The _sfp_list is a list whose length is number of SFP modules supported by the platform
|
|
|
|
# - sfp_module_full_initialized:
|
|
|
|
# - False: All SFP modules have not been created
|
|
|
|
# - True: All SFP modules have been created
|
|
|
|
#
|
2021-10-24 23:59:06 -05:00
|
|
|
self.sfp_initialized_count = 0
|
|
|
|
self.sfp_event = None
|
2019-08-28 13:59:37 -05:00
|
|
|
self.reboot_cause_initialized = False
|
2022-06-20 21:12:20 -05:00
|
|
|
|
2022-07-14 04:20:16 -05:00
|
|
|
self.sfp_module = None
|
2023-12-14 04:01:11 -06:00
|
|
|
self.sfp_lock = threading.Lock()
|
2022-07-14 04:20:16 -05:00
|
|
|
|
2022-06-20 21:12:20 -05:00
|
|
|
# Build the RJ45 port list from platform.json and hwsku.json
|
2022-07-14 01:24:39 -05:00
|
|
|
self._RJ45_port_inited = False
|
|
|
|
self._RJ45_port_list = None
|
2022-06-20 21:12:20 -05:00
|
|
|
|
2023-12-13 06:19:44 -06:00
|
|
|
Chassis.chassis_instance = self
|
|
|
|
|
2023-12-07 06:54:56 -06:00
|
|
|
self.modules_mgmt_thread = threading.Thread()
|
|
|
|
self.modules_changes_queue = queue.Queue()
|
|
|
|
self.modules_mgmt_task_stopping_event = threading.Event()
|
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
logger.log_info("Chassis loaded successfully")
|
|
|
|
|
|
|
|
def __del__(self):
|
2021-10-24 23:59:06 -05:00
|
|
|
if self.sfp_event:
|
2019-08-28 13:59:37 -05:00
|
|
|
self.sfp_event.deinitialize()
|
|
|
|
|
2023-11-27 05:23:04 -06:00
|
|
|
if self._sfp_list:
|
|
|
|
if self.sfp_module.SFP.shared_sdk_handle:
|
|
|
|
self.sfp_module.deinitialize_sdk_handle(self.sfp_module.SFP.shared_sdk_handle)
|
|
|
|
|
2022-07-14 01:24:39 -05:00
|
|
|
@property
|
|
|
|
def RJ45_port_list(self):
|
|
|
|
if not self._RJ45_port_inited:
|
|
|
|
self._RJ45_port_list = extract_RJ45_ports_index()
|
|
|
|
self._RJ45_port_inited = True
|
|
|
|
return self._RJ45_port_list
|
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
##############################################
|
|
|
|
# PSU methods
|
|
|
|
##############################################
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
def initialize_psu(self):
|
2021-10-24 23:59:06 -05:00
|
|
|
if not self._psu_list:
|
|
|
|
from .psu import Psu, FixedPsu
|
|
|
|
psu_count = DeviceDataManager.get_psu_count()
|
|
|
|
hot_swapable = DeviceDataManager.is_psu_hotswapable()
|
|
|
|
|
|
|
|
# Initialize PSU list
|
|
|
|
for index in range(psu_count):
|
|
|
|
if hot_swapable:
|
|
|
|
psu = Psu(index)
|
[Mellanox] Optimize SFP modules initialization (#7537)
Originally, SFP modules were always accessed from platform daemons, and arbitrary SFP modules can be accessed in the daemon. So all SFP modules were initialized in one shot once one of the following chassis APIs called
- get_all_sfps
- get_sfp_numbers
- get_sfp
Recently, we noticed that SFP modules can also be accessed from CLI, eg. the latest refactor of `sfputil`.
In this case, only one SFP module is accessed in the chassis object's life cycle.
To initialize all SFP modules in one shot is waste of time and causes the CLI to take much more time to finish.
So we would like to optimize the initialization flow by introducing a two-phase initialization approach:
- Partial initialization, which means the `chassis._sfp_list` has been initialized with proper length and all elements being `None`
- Full initialization, which means all elements in `chassis._sfp_list` are created
If the relevant function is called,
- `get_sfp`, only partial initialization will be done, and then the specific SFP module is initialized.
- `get_all_sfps` or `get_num_sfps`, full initialization will be done, which means all SFP modules are initialized.
Signed-off-by: Stephen Sun <stephens@nvidia.com>
2021-05-06 12:14:48 -05:00
|
|
|
else:
|
2021-10-24 23:59:06 -05:00
|
|
|
psu = FixedPsu(index)
|
|
|
|
self._psu_list.append(psu)
|
2020-12-11 12:51:31 -06:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_num_psus(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of power supply units available on this chassis
|
2020-12-11 12:51:31 -06:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
An integer, the number of power supply units available on this
|
|
|
|
chassis
|
|
|
|
"""
|
|
|
|
self.initialize_psu()
|
|
|
|
return len(self._psu_list)
|
[Mellanox] support new platform api, thermal and psu part (#3175)
* support new platform api, thermal and psu part
for psu, all APIs are supported.
for thermal, we support
get_temperature,
get_high_threshold
for the thermal sensors of cpu core, cpu pack, psu and sfp module
and get_temperature for the ambient thermal sensors around the asic, port, fan, comex and board.
* 1. address review comments
2. improve the handling of PSU inserting/removal
3. tolerance diverse psu thermal sensor file name conventions
* 1. adjust thermal code according to the latest version of hw-management
2. check power_good_status rather than whether file existing ahead of reading voltage, current and power of PSU
2019-07-22 09:59:49 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_all_psus(self):
|
|
|
|
"""
|
|
|
|
Retrieves all power supply units available on this chassis
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
A list of objects derived from PsuBase representing all power
|
|
|
|
supply units available on this chassis
|
|
|
|
"""
|
|
|
|
self.initialize_psu()
|
|
|
|
return self._psu_list
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_psu(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves power supply unit represented by (0-based) index <index>
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Args:
|
|
|
|
index: An integer, the index (0-based) of the power supply unit to
|
|
|
|
retrieve
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
An object dervied from PsuBase representing the specified power
|
|
|
|
supply unit
|
|
|
|
"""
|
|
|
|
self.initialize_psu()
|
|
|
|
return super(Chassis, self).get_psu(index)
|
2020-07-13 12:22:39 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
##############################################
|
|
|
|
# Fan methods
|
|
|
|
##############################################
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def initialize_fan(self):
|
|
|
|
if not self._fan_drawer_list:
|
|
|
|
from .fan import Fan
|
|
|
|
from .fan_drawer import RealDrawer, VirtualDrawer
|
|
|
|
|
|
|
|
hot_swapable = DeviceDataManager.is_fan_hotswapable()
|
|
|
|
drawer_num = DeviceDataManager.get_fan_drawer_count()
|
|
|
|
fan_num = DeviceDataManager.get_fan_count()
|
|
|
|
fan_num_per_drawer = fan_num // drawer_num
|
|
|
|
drawer_ctor = RealDrawer if hot_swapable else VirtualDrawer
|
|
|
|
fan_index = 0
|
|
|
|
for drawer_index in range(drawer_num):
|
|
|
|
drawer = drawer_ctor(drawer_index)
|
|
|
|
self._fan_drawer_list.append(drawer)
|
|
|
|
for index in range(fan_num_per_drawer):
|
|
|
|
fan = Fan(fan_index, drawer, index + 1)
|
|
|
|
fan_index += 1
|
|
|
|
drawer._fan_list.append(fan)
|
|
|
|
|
|
|
|
def get_num_fan_drawers(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of fan drawers available on this chassis
|
2020-01-28 23:55:50 -06:00
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
An integer, the number of fan drawers available on this chassis
|
2020-01-28 23:55:50 -06:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return DeviceDataManager.get_fan_drawer_count()
|
2020-01-28 23:55:50 -06:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_all_fan_drawers(self):
|
2020-09-26 13:20:43 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves all fan drawers available on this chassis
|
2020-09-26 13:20:43 -05:00
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
A list of objects derived from FanDrawerBase representing all fan
|
|
|
|
drawers available on this chassis
|
2020-09-26 13:20:43 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_fan()
|
|
|
|
return self._fan_drawer_list
|
2021-05-24 11:37:59 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_fan_drawer(self, index):
|
2021-05-24 11:37:59 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves fan drawers represented by (0-based) index <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer, the index (0-based) of the fan drawer to
|
|
|
|
retrieve
|
|
|
|
|
2021-05-24 11:37:59 -05:00
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
An object dervied from FanDrawerBase representing the specified fan
|
|
|
|
drawer
|
2021-05-24 11:37:59 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_fan()
|
|
|
|
return super(Chassis, self).get_fan_drawer(index)
|
2021-05-24 11:37:59 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
##############################################
|
|
|
|
# SFP methods
|
|
|
|
##############################################
|
2021-10-24 23:59:06 -05:00
|
|
|
|
2022-07-14 04:20:16 -05:00
|
|
|
def _import_sfp_module(self):
|
|
|
|
if not self.sfp_module:
|
|
|
|
from . import sfp as sfp_module
|
|
|
|
self.sfp_module = sfp_module
|
|
|
|
return self.sfp_module
|
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def initialize_single_sfp(self, index):
|
|
|
|
sfp_count = self.get_num_sfps()
|
2023-12-14 04:01:11 -06:00
|
|
|
# Use double checked locking mechanism for:
|
|
|
|
# 1. protect shared resource self._sfp_list
|
|
|
|
# 2. performance (avoid locking every time)
|
2021-10-24 23:59:06 -05:00
|
|
|
if index < sfp_count:
|
2023-12-14 04:01:11 -06:00
|
|
|
if not self._sfp_list or not self._sfp_list[index]:
|
|
|
|
with self.sfp_lock:
|
|
|
|
if not self._sfp_list:
|
|
|
|
self._sfp_list = [None] * sfp_count
|
|
|
|
|
|
|
|
if not self._sfp_list[index]:
|
|
|
|
sfp_module = self._import_sfp_module()
|
|
|
|
if self.RJ45_port_list and index in self.RJ45_port_list:
|
|
|
|
self._sfp_list[index] = sfp_module.RJ45Port(index)
|
|
|
|
else:
|
|
|
|
self._sfp_list[index] = sfp_module.SFP(index)
|
|
|
|
self.sfp_initialized_count += 1
|
2021-10-24 23:59:06 -05:00
|
|
|
|
|
|
|
def initialize_sfp(self):
|
2023-12-14 04:01:11 -06:00
|
|
|
sfp_count = self.get_num_sfps()
|
|
|
|
# Use double checked locking mechanism for:
|
|
|
|
# 1. protect shared resource self._sfp_list
|
|
|
|
# 2. performance (avoid locking every time)
|
|
|
|
if sfp_count != self.sfp_initialized_count:
|
|
|
|
with self.sfp_lock:
|
|
|
|
if sfp_count != self.sfp_initialized_count:
|
|
|
|
if not self._sfp_list:
|
|
|
|
sfp_module = self._import_sfp_module()
|
|
|
|
for index in range(sfp_count):
|
|
|
|
if self.RJ45_port_list and index in self.RJ45_port_list:
|
|
|
|
sfp_object = sfp_module.RJ45Port(index)
|
|
|
|
else:
|
|
|
|
sfp_object = sfp_module.SFP(index)
|
|
|
|
self._sfp_list.append(sfp_object)
|
|
|
|
self.sfp_initialized_count = sfp_count
|
|
|
|
elif self.sfp_initialized_count != len(self._sfp_list):
|
|
|
|
sfp_module = self._import_sfp_module()
|
|
|
|
for index in range(len(self._sfp_list)):
|
|
|
|
if self._sfp_list[index] is None:
|
|
|
|
if self.RJ45_port_list and index in self.RJ45_port_list:
|
|
|
|
self._sfp_list[index] = sfp_module.RJ45Port(index)
|
|
|
|
else:
|
|
|
|
self._sfp_list[index] = sfp_module.SFP(index)
|
|
|
|
self.sfp_initialized_count = len(self._sfp_list)
|
2021-10-24 23:59:06 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
def get_num_sfps(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of sfps available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An integer, the number of sfps available on this chassis
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return DeviceDataManager.get_sfp_count()
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
def get_all_sfps(self):
|
|
|
|
"""
|
|
|
|
Retrieves all sfps available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
A list of objects derived from SfpBase representing all sfps
|
2019-08-28 13:59:37 -05:00
|
|
|
available on this chassis
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_sfp()
|
2019-08-28 13:59:37 -05:00
|
|
|
return self._sfp_list
|
|
|
|
|
|
|
|
def get_sfp(self, index):
|
|
|
|
"""
|
2020-06-23 19:21:36 -05:00
|
|
|
Retrieves sfp represented by (1-based) index <index>
|
2019-08-28 13:59:37 -05:00
|
|
|
|
|
|
|
Args:
|
2020-06-23 19:21:36 -05:00
|
|
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
2019-08-28 13:59:37 -05:00
|
|
|
The index should be the sequence of a physical port in a chassis,
|
2020-06-23 19:21:36 -05:00
|
|
|
starting from 1.
|
|
|
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
2019-08-28 13:59:37 -05:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object dervied from SfpBase representing the specified sfp
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
index = index - 1
|
|
|
|
self.initialize_single_sfp(index)
|
|
|
|
return super(Chassis, self).get_sfp(index)
|
2022-03-23 02:16:03 -05:00
|
|
|
|
2022-07-14 04:20:16 -05:00
|
|
|
def get_port_or_cage_type(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves sfp port or cage type corresponding to physical port <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer (>=0), the index of the sfp to retrieve.
|
|
|
|
The index should correspond to the physical port in a chassis.
|
|
|
|
For example:-
|
|
|
|
1 for Ethernet0, 2 for Ethernet4 and so on for one platform.
|
|
|
|
0 for Ethernet0, 1 for Ethernet4 and so on for another platform.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The masks of all types of port or cage that can be supported on the port
|
|
|
|
Types are defined in sfp_base.py
|
|
|
|
Eg.
|
|
|
|
Both SFP and SFP+ are supported on the port, the return value should be 0x0a
|
|
|
|
which is 0x02 | 0x08
|
|
|
|
"""
|
|
|
|
index = index - 1
|
|
|
|
if self.RJ45_port_list and index in self.RJ45_port_list:
|
|
|
|
from sonic_platform_base.sfp_base import SfpBase
|
|
|
|
return SfpBase.SFP_PORT_TYPE_BIT_RJ45
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_change_event(self, timeout=0):
|
|
|
|
"""
|
|
|
|
Returns a nested dictionary containing all devices which have
|
|
|
|
experienced a change at chassis level
|
[Mellanox] Optimize SFP modules initialization (#7537)
Originally, SFP modules were always accessed from platform daemons, and arbitrary SFP modules can be accessed in the daemon. So all SFP modules were initialized in one shot once one of the following chassis APIs called
- get_all_sfps
- get_sfp_numbers
- get_sfp
Recently, we noticed that SFP modules can also be accessed from CLI, eg. the latest refactor of `sfputil`.
In this case, only one SFP module is accessed in the chassis object's life cycle.
To initialize all SFP modules in one shot is waste of time and causes the CLI to take much more time to finish.
So we would like to optimize the initialization flow by introducing a two-phase initialization approach:
- Partial initialization, which means the `chassis._sfp_list` has been initialized with proper length and all elements being `None`
- Full initialization, which means all elements in `chassis._sfp_list` are created
If the relevant function is called,
- `get_sfp`, only partial initialization will be done, and then the specific SFP module is initialized.
- `get_all_sfps` or `get_num_sfps`, full initialization will be done, which means all SFP modules are initialized.
Signed-off-by: Stephen Sun <stephens@nvidia.com>
2021-05-06 12:14:48 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Args:
|
|
|
|
timeout: Timeout in milliseconds (optional). If timeout == 0,
|
|
|
|
this method will block until a change is detected.
|
2019-04-21 16:34:28 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
(bool, dict):
|
2023-12-07 06:54:56 -06:00
|
|
|
- True if call successful, False if not; - Deprecated, will always return True
|
2021-10-24 23:59:06 -05:00
|
|
|
- A nested dictionary where key is a device type,
|
|
|
|
value is a dictionary with key:value pairs in the format of
|
2022-03-23 02:16:03 -05:00
|
|
|
{'device_id':'device_event'},
|
2021-10-24 23:59:06 -05:00
|
|
|
where device_id is the device ID for this device and
|
|
|
|
device_event,
|
|
|
|
status='1' represents device inserted,
|
|
|
|
status='0' represents device removed.
|
|
|
|
Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}}
|
|
|
|
indicates that fan 0 has been removed, fan 2
|
|
|
|
has been inserted and sfp 11 has been removed.
|
|
|
|
"""
|
2023-12-07 06:54:56 -06:00
|
|
|
if not self.modules_mgmt_thread.is_alive():
|
|
|
|
# open new SFP change events thread
|
|
|
|
self.modules_mgmt_thread = modules_mgmt.ModulesMgmtTask(q=self.modules_changes_queue
|
|
|
|
, main_thread_stop_event = self.modules_mgmt_task_stopping_event)
|
|
|
|
# Set the thread as daemon so when pmon/xcvrd are shutting down, modules_mgmt will shut down immedietly.
|
|
|
|
self.modules_mgmt_thread.daemon = True
|
|
|
|
self.modules_mgmt_thread.start()
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_sfp()
|
|
|
|
wait_for_ever = (timeout == 0)
|
2023-12-07 06:54:56 -06:00
|
|
|
# poll timeout should be no more than 1000ms to ensure fast shutdown flow
|
|
|
|
timeout = 1000.0 if timeout >= 1000 else float(timeout)
|
2021-10-24 23:59:06 -05:00
|
|
|
port_dict = {}
|
|
|
|
error_dict = {}
|
2023-02-14 00:26:25 -06:00
|
|
|
begin = time.time()
|
2023-12-07 06:54:56 -06:00
|
|
|
i = 0
|
2023-02-14 00:26:25 -06:00
|
|
|
while True:
|
2023-12-07 06:54:56 -06:00
|
|
|
try:
|
|
|
|
logger.log_info(f'get_change_event() trying to get changes from queue on iteration {i}')
|
|
|
|
port_dict = self.modules_changes_queue.get(timeout=timeout / 1000)
|
|
|
|
logger.log_info(f'get_change_event() iteration {i} port_dict: {port_dict}')
|
|
|
|
except queue.Empty:
|
|
|
|
logger.log_info(f"failed to get item from modules changes queue on itertaion {i}")
|
2019-04-21 16:34:28 -05:00
|
|
|
|
2022-06-20 21:12:20 -05:00
|
|
|
if port_dict:
|
|
|
|
self.reinit_sfps(port_dict)
|
2023-12-07 06:54:56 -06:00
|
|
|
result_dict = {'sfp': port_dict}
|
2021-10-24 23:59:06 -05:00
|
|
|
result_dict['sfp_error'] = error_dict
|
2023-12-07 06:54:56 -06:00
|
|
|
return True, result_dict
|
|
|
|
else:
|
|
|
|
if not wait_for_ever:
|
|
|
|
elapse = time.time() - begin
|
|
|
|
logger.log_info(f"get_change_event: wait_for_ever {wait_for_ever} elapse {elapse} iteartion {i}")
|
|
|
|
if elapse * 1000 >= timeout:
|
|
|
|
logger.log_info(f"elapse {elapse} > timeout {timeout} iteartion {i} returning empty dict")
|
|
|
|
return True, {'sfp': {}}
|
|
|
|
i += 1
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def reinit_sfps(self, port_dict):
|
2019-08-28 13:59:37 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Re-initialize SFP if there is any newly inserted SFPs
|
|
|
|
:param port_dict: SFP event data
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
from . import sfp
|
|
|
|
for index, status in port_dict.items():
|
|
|
|
if status == sfp.SFP_STATUS_INSERTED:
|
|
|
|
try:
|
2023-12-07 06:54:56 -06:00
|
|
|
self._sfp_list[int(index) - 1].reinit()
|
2021-10-24 23:59:06 -05:00
|
|
|
except Exception as e:
|
|
|
|
logger.log_error("Fail to re-initialize SFP {} - {}".format(index, repr(e)))
|
|
|
|
|
|
|
|
def _show_capabilities(self):
|
|
|
|
"""
|
|
|
|
This function is for debug purpose
|
|
|
|
Some features require a xSFP module to support some capabilities but it's unrealistic to
|
|
|
|
check those modules one by one.
|
|
|
|
So this function is introduce to show some capabilities of all xSFP modules mounted on the device.
|
|
|
|
"""
|
|
|
|
self.initialize_sfp()
|
|
|
|
for s in self._sfp_list:
|
|
|
|
try:
|
|
|
|
print("index {} tx disable {} dom {} calibration {} temp {} volt {} power (tx {} rx {})".format(s.index,
|
|
|
|
s.dom_tx_disable_supported,
|
|
|
|
s.dom_supported,
|
|
|
|
s.calibration,
|
|
|
|
s.dom_temp_supported,
|
|
|
|
s.dom_volt_supported,
|
|
|
|
s.dom_rx_power_supported,
|
|
|
|
s.dom_tx_power_supported
|
|
|
|
))
|
|
|
|
except:
|
|
|
|
print("fail to retrieve capabilities for module index {}".format(s.index))
|
|
|
|
|
|
|
|
##############################################
|
|
|
|
# THERMAL methods
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
def initialize_thermals(self):
|
|
|
|
if not self._thermal_list:
|
|
|
|
from .thermal import initialize_chassis_thermals
|
|
|
|
# Initialize thermals
|
|
|
|
self._thermal_list = initialize_chassis_thermals()
|
|
|
|
|
|
|
|
def get_num_thermals(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of thermals available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An integer, the number of thermals available on this chassis
|
|
|
|
"""
|
|
|
|
self.initialize_thermals()
|
|
|
|
return len(self._thermal_list)
|
|
|
|
|
|
|
|
def get_all_thermals(self):
|
|
|
|
"""
|
|
|
|
Retrieves all thermals available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of objects derived from ThermalBase representing all thermals
|
|
|
|
available on this chassis
|
|
|
|
"""
|
|
|
|
self.initialize_thermals()
|
|
|
|
return self._thermal_list
|
|
|
|
|
|
|
|
def get_thermal(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves thermal unit represented by (0-based) index <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer, the index (0-based) of the thermal to
|
|
|
|
retrieve
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object dervied from ThermalBase representing the specified thermal
|
|
|
|
"""
|
|
|
|
self.initialize_thermals()
|
|
|
|
return super(Chassis, self).get_thermal(index)
|
|
|
|
|
|
|
|
##############################################
|
|
|
|
# EEPROM methods
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
def initialize_eeprom(self):
|
|
|
|
if not self._eeprom:
|
|
|
|
from .eeprom import Eeprom
|
|
|
|
# Initialize EEPROM
|
|
|
|
self._eeprom = Eeprom()
|
|
|
|
|
|
|
|
def get_eeprom(self):
|
|
|
|
"""
|
|
|
|
Retreives eeprom device on this chassis
|
2019-08-28 13:59:37 -05:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object derived from WatchdogBase representing the hardware
|
2021-10-24 23:59:06 -05:00
|
|
|
eeprom device
|
|
|
|
"""
|
|
|
|
self.initialize_eeprom()
|
|
|
|
return self._eeprom
|
2019-08-28 13:59:37 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_name(self):
|
2019-08-28 13:59:37 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves the name of the device
|
2019-08-28 13:59:37 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
string: The name of the device
|
|
|
|
"""
|
|
|
|
self.initialize_eeprom()
|
|
|
|
return self._eeprom.get_product_name()
|
|
|
|
|
|
|
|
def get_model(self):
|
|
|
|
"""
|
|
|
|
Retrieves the model number (or part number) of the device
|
2019-08-28 13:59:37 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
string: Model/part number of device
|
|
|
|
"""
|
|
|
|
self.initialize_eeprom()
|
|
|
|
return self._eeprom.get_part_number()
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2019-07-04 06:29:58 -05:00
|
|
|
def get_base_mac(self):
|
|
|
|
"""
|
|
|
|
Retrieves the base MAC address for the chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string containing the MAC address in the format
|
|
|
|
'XX:XX:XX:XX:XX:XX'
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_eeprom()
|
2019-08-28 13:59:37 -05:00
|
|
|
return self._eeprom.get_base_mac()
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2020-10-18 00:00:14 -05:00
|
|
|
def get_serial(self):
|
2019-07-04 06:29:58 -05:00
|
|
|
"""
|
|
|
|
Retrieves the hardware serial number for the chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string containing the hardware serial number for this chassis.
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_eeprom()
|
2019-08-28 13:59:37 -05:00
|
|
|
return self._eeprom.get_serial_number()
|
2019-07-04 06:29:58 -05:00
|
|
|
|
|
|
|
def get_system_eeprom_info(self):
|
|
|
|
"""
|
|
|
|
Retrieves the full content of system EEPROM information for the chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A dictionary where keys are the type code defined in
|
|
|
|
OCP ONIE TlvInfo EEPROM format and values are their corresponding
|
|
|
|
values.
|
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_eeprom()
|
2019-08-28 13:59:37 -05:00
|
|
|
return self._eeprom.get_system_eeprom_info()
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
##############################################
|
|
|
|
# Component methods
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
def initialize_components(self):
|
|
|
|
if not utils.is_host():
|
|
|
|
return
|
|
|
|
if not self._component_list:
|
|
|
|
# Initialize component list
|
|
|
|
from .component import ComponentONIE, ComponentSSD, ComponentBIOS, ComponentCPLD
|
|
|
|
self._component_list.append(ComponentONIE())
|
|
|
|
self._component_list.append(ComponentSSD())
|
2022-06-20 21:12:20 -05:00
|
|
|
self._component_list.append(DeviceDataManager.get_bios_component())
|
|
|
|
self._component_list.extend(DeviceDataManager.get_cpld_component_list())
|
2021-10-24 23:59:06 -05:00
|
|
|
|
|
|
|
def get_num_components(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of components available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An integer, the number of components available on this chassis
|
|
|
|
"""
|
|
|
|
self.initialize_components()
|
|
|
|
return len(self._component_list)
|
|
|
|
|
|
|
|
def get_all_components(self):
|
|
|
|
"""
|
|
|
|
Retrieves all components available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of objects derived from ComponentBase representing all components
|
|
|
|
available on this chassis
|
|
|
|
"""
|
|
|
|
self.initialize_components()
|
|
|
|
return self._component_list
|
|
|
|
|
|
|
|
def get_component(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves component represented by (0-based) index <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer, the index (0-based) of the component to retrieve
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object dervied from ComponentBase representing the specified component
|
|
|
|
"""
|
|
|
|
self.initialize_components()
|
|
|
|
return super(Chassis, self).get_component(index)
|
|
|
|
|
|
|
|
##############################################
|
|
|
|
# System LED methods
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
def initizalize_system_led(self):
|
|
|
|
if not Chassis._led:
|
2023-05-16 00:24:39 -05:00
|
|
|
from .led import SystemLed, \
|
|
|
|
SystemUidLed
|
2021-10-24 23:59:06 -05:00
|
|
|
Chassis._led = SystemLed()
|
2023-05-16 00:24:39 -05:00
|
|
|
Chassis._led_uid = SystemUidLed()
|
2021-10-24 23:59:06 -05:00
|
|
|
|
|
|
|
def set_status_led(self, color):
|
|
|
|
"""
|
|
|
|
Sets the state of the system LED
|
|
|
|
|
|
|
|
Args:
|
|
|
|
color: A string representing the color with which to set the
|
|
|
|
system LED
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
bool: True if system LED state is set successfully, False if not
|
2019-07-04 06:29:58 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initizalize_system_led()
|
|
|
|
return False if not Chassis._led else Chassis._led.set_status(color)
|
|
|
|
|
|
|
|
def get_status_led(self):
|
|
|
|
"""
|
|
|
|
Gets the state of the system LED
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string, one of the valid LED color strings which could be vendor
|
|
|
|
specified.
|
|
|
|
"""
|
|
|
|
self.initizalize_system_led()
|
|
|
|
return None if not Chassis._led else Chassis._led.get_status()
|
|
|
|
|
2023-05-16 00:24:39 -05:00
|
|
|
def set_uid_led(self, color):
|
|
|
|
"""
|
|
|
|
Sets the state of the system UID LED
|
|
|
|
|
|
|
|
Args:
|
|
|
|
color: A string representing the color with which to set the
|
|
|
|
system UID LED
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: True if system LED state is set successfully, False if not
|
|
|
|
"""
|
|
|
|
self.initizalize_system_led()
|
|
|
|
return False if not Chassis._led_uid else Chassis._led_uid.set_status(color)
|
|
|
|
|
|
|
|
def get_uid_led(self):
|
|
|
|
"""
|
|
|
|
Gets the state of the system UID LED
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A string, one of the valid LED color strings which could be vendor
|
|
|
|
specified.
|
|
|
|
"""
|
|
|
|
self.initizalize_system_led()
|
|
|
|
return None if not Chassis._led_uid else Chassis._led_uid.get_status()
|
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_watchdog(self):
|
|
|
|
"""
|
|
|
|
Retrieves hardware watchdog device on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
An object derived from WatchdogBase representing the hardware
|
|
|
|
watchdog device
|
|
|
|
|
|
|
|
Note:
|
|
|
|
We overload this method to ensure that watchdog is only initialized
|
|
|
|
when it is referenced. Currently, only one daemon can open the watchdog.
|
2022-03-23 02:16:03 -05:00
|
|
|
To initialize watchdog in the constructor causes multiple daemon
|
2021-10-24 23:59:06 -05:00
|
|
|
try opening watchdog when loading and constructing a chassis object
|
|
|
|
and fail. By doing so we can eliminate that risk.
|
2019-07-04 06:29:58 -05:00
|
|
|
"""
|
|
|
|
try:
|
2021-10-24 23:59:06 -05:00
|
|
|
if self._watchdog is None:
|
|
|
|
from .watchdog import get_watchdog
|
|
|
|
self._watchdog = get_watchdog()
|
[Mellanox] support new platform api, thermal and psu part (#3175)
* support new platform api, thermal and psu part
for psu, all APIs are supported.
for thermal, we support
get_temperature,
get_high_threshold
for the thermal sensors of cpu core, cpu pack, psu and sfp module
and get_temperature for the ambient thermal sensors around the asic, port, fan, comex and board.
* 1. address review comments
2. improve the handling of PSU inserting/removal
3. tolerance diverse psu thermal sensor file name conventions
* 1. adjust thermal code according to the latest version of hw-management
2. check power_good_status rather than whether file existing ahead of reading voltage, current and power of PSU
2019-07-22 09:59:49 -05:00
|
|
|
except Exception as e:
|
2021-10-24 23:59:06 -05:00
|
|
|
logger.log_info("Fail to load watchdog due to {}".format(repr(e)))
|
|
|
|
|
|
|
|
return self._watchdog
|
|
|
|
|
2022-03-23 02:16:03 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_revision(self):
|
|
|
|
"""
|
|
|
|
Retrieves the hardware revision of the device
|
2022-03-23 02:16:03 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
string: Revision value of device
|
|
|
|
"""
|
|
|
|
if self.dmi_data is None:
|
|
|
|
self.dmi_data = self._parse_dmi(DMI_FILE)
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
return self.dmi_data.get(DMI_VERSION, "N/A")
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-05-24 11:37:59 -05:00
|
|
|
def _parse_dmi(self, filename):
|
|
|
|
"""
|
|
|
|
Read DMI data chassis data and returns a dictionary of values
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A dictionary containing the dmi table of the switch chassis info
|
|
|
|
"""
|
|
|
|
result = {}
|
|
|
|
try:
|
2022-07-01 19:29:07 -05:00
|
|
|
if not os.access(filename, os.R_OK):
|
|
|
|
return result
|
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
with open(filename, "rb") as fileobj:
|
|
|
|
data = fileobj.read()
|
2021-05-24 11:37:59 -05:00
|
|
|
|
|
|
|
body = data[DMI_HEADER_LEN:]
|
|
|
|
records = body.split(b'\x00')
|
|
|
|
|
|
|
|
for k, v in DMI_TABLE_MAP.items():
|
|
|
|
result[k] = records[v].decode("utf-8")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
logger.log_error("Fail to decode DMI {} due to {}".format(filename, repr(e)))
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2019-07-04 06:29:58 -05:00
|
|
|
def _verify_reboot_cause(self, filename):
|
|
|
|
'''
|
2022-03-23 02:16:03 -05:00
|
|
|
Open and read the reboot cause file in
|
2019-07-04 06:29:58 -05:00
|
|
|
/var/run/hwmanagement/system (which is defined as REBOOT_CAUSE_ROOT)
|
|
|
|
If a reboot cause file doesn't exists, returns '0'.
|
|
|
|
'''
|
2021-10-24 23:59:06 -05:00
|
|
|
return bool(utils.read_int_from_file(os.path.join(REBOOT_CAUSE_ROOT, filename), log_func=None))
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
def initialize_reboot_cause(self):
|
|
|
|
self.reboot_major_cause_dict = {
|
|
|
|
'reset_main_pwr_fail' : self.REBOOT_CAUSE_POWER_LOSS,
|
|
|
|
'reset_aux_pwr_or_ref' : self.REBOOT_CAUSE_POWER_LOSS,
|
2022-04-18 02:55:56 -05:00
|
|
|
'reset_comex_pwr_fail' : self.REBOOT_CAUSE_POWER_LOSS,
|
2019-08-28 13:59:37 -05:00
|
|
|
'reset_asic_thermal' : self.REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC,
|
2022-04-18 02:55:56 -05:00
|
|
|
'reset_comex_thermal' : self.REBOOT_CAUSE_THERMAL_OVERLOAD_CPU,
|
2019-08-28 13:59:37 -05:00
|
|
|
'reset_hotswap_or_wd' : self.REBOOT_CAUSE_WATCHDOG,
|
2022-04-18 02:55:56 -05:00
|
|
|
'reset_comex_wd' : self.REBOOT_CAUSE_WATCHDOG,
|
2019-08-28 13:59:37 -05:00
|
|
|
'reset_swb_wd' : self.REBOOT_CAUSE_WATCHDOG,
|
2022-04-18 02:55:56 -05:00
|
|
|
'reset_sff_wd' : self.REBOOT_CAUSE_WATCHDOG,
|
|
|
|
'reset_hotswap_or_halt' : self.REBOOT_CAUSE_HARDWARE_OTHER,
|
|
|
|
'reset_voltmon_upgrade_fail': self.REBOOT_CAUSE_HARDWARE_OTHER,
|
|
|
|
'reset_reload_bios' : self.REBOOT_CAUSE_HARDWARE_BIOS,
|
|
|
|
'reset_fw_reset' : self.REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC,
|
|
|
|
'reset_from_asic' : self.REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC,
|
|
|
|
'reset_long_pb' : self.REBOOT_CAUSE_HARDWARE_BUTTON,
|
|
|
|
'reset_short_pb' : self.REBOOT_CAUSE_HARDWARE_BUTTON
|
2019-08-28 13:59:37 -05:00
|
|
|
}
|
2022-04-18 02:55:56 -05:00
|
|
|
self.reboot_minor_cause_dict = {}
|
2019-10-15 13:46:09 -05:00
|
|
|
self.reboot_by_software = 'reset_sw_reset'
|
2019-08-28 13:59:37 -05:00
|
|
|
self.reboot_cause_initialized = True
|
|
|
|
|
2023-01-11 08:50:46 -06:00
|
|
|
def _parse_warmfast_reboot_from_proc_cmdline(self):
|
|
|
|
if os.path.isfile(REBOOT_TYPE_KEXEC_FILE):
|
|
|
|
with open(REBOOT_TYPE_KEXEC_FILE) as cause_file:
|
|
|
|
cause_file_kexec = cause_file.readline()
|
|
|
|
m = re.search(REBOOT_TYPE_KEXEC_PATTERN_WARM, cause_file_kexec)
|
|
|
|
if m and m.group(1):
|
|
|
|
return 'warm-reboot'
|
|
|
|
m = re.search(REBOOT_TYPE_KEXEC_PATTERN_FAST, cause_file_kexec)
|
|
|
|
if m and m.group(1):
|
|
|
|
return 'fast-reboot'
|
|
|
|
return None
|
|
|
|
|
2023-10-03 20:58:31 -05:00
|
|
|
def _wait_reboot_cause_ready(self):
|
|
|
|
max_wait_time = REBOOT_CAUSE_MAX_WAIT_TIME
|
|
|
|
while max_wait_time > 0:
|
|
|
|
if utils.read_int_from_file(REBOOT_CAUSE_READY_FILE, log_func=None) == 1:
|
|
|
|
return True
|
|
|
|
time.sleep(REBOOT_CAUSE_CHECK_INTERVAL)
|
|
|
|
max_wait_time -= REBOOT_CAUSE_CHECK_INTERVAL
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2019-07-04 06:29:58 -05:00
|
|
|
def get_reboot_cause(self):
|
|
|
|
"""
|
|
|
|
Retrieves the cause of the previous reboot
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A tuple (string, string) where the first element is a string
|
|
|
|
containing the cause of the previous reboot. This string must be
|
|
|
|
one of the predefined strings in this class. If the first string
|
|
|
|
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
|
|
|
|
to pass a description of the reboot cause.
|
|
|
|
"""
|
|
|
|
#read reboot causes files in the following order
|
2023-01-11 08:50:46 -06:00
|
|
|
|
|
|
|
# To avoid the leftover hardware reboot cause confusing the reboot cause determine service
|
|
|
|
# Skip the hardware reboot cause check if warm/fast reboot cause found from cmdline
|
|
|
|
if utils.is_host():
|
|
|
|
reboot_cause = self._parse_warmfast_reboot_from_proc_cmdline()
|
|
|
|
if reboot_cause:
|
|
|
|
return self.REBOOT_CAUSE_NON_HARDWARE, ''
|
|
|
|
|
2023-10-03 20:58:31 -05:00
|
|
|
if not self._wait_reboot_cause_ready():
|
|
|
|
logger.log_error("Hardware reboot cause is not ready")
|
|
|
|
return self.REBOOT_CAUSE_NON_HARDWARE, ''
|
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
if not self.reboot_cause_initialized:
|
|
|
|
self.initialize_reboot_cause()
|
|
|
|
|
2020-12-11 12:51:31 -06:00
|
|
|
for reset_file, reset_cause in self.reboot_major_cause_dict.items():
|
2019-08-28 13:59:37 -05:00
|
|
|
if self._verify_reboot_cause(reset_file):
|
|
|
|
return reset_cause, ''
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2020-12-11 12:51:31 -06:00
|
|
|
for reset_file, reset_cause in self.reboot_minor_cause_dict.items():
|
2019-08-28 13:59:37 -05:00
|
|
|
if self._verify_reboot_cause(reset_file):
|
|
|
|
return self.REBOOT_CAUSE_HARDWARE_OTHER, reset_cause
|
|
|
|
|
2019-10-15 13:46:09 -05:00
|
|
|
if self._verify_reboot_cause(self.reboot_by_software):
|
|
|
|
logger.log_info("Hardware reboot cause: the system was rebooted due to software requesting")
|
|
|
|
else:
|
|
|
|
logger.log_info("Hardware reboot cause: no hardware reboot cause found")
|
|
|
|
|
2019-08-28 13:59:37 -05:00
|
|
|
return self.REBOOT_CAUSE_NON_HARDWARE, ''
|
2019-07-04 06:29:58 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_thermal_manager(self):
|
|
|
|
from .thermal_manager import ThermalManager
|
|
|
|
return ThermalManager
|
2019-07-28 07:18:39 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_position_in_parent(self):
|
2019-07-28 07:18:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
|
|
|
|
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
|
|
|
|
Returns:
|
|
|
|
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
|
|
|
|
"""
|
|
|
|
return -1
|
|
|
|
|
|
|
|
def is_replaceable(self):
|
2019-07-28 07:18:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Indicate whether this device is replaceable.
|
|
|
|
Returns:
|
|
|
|
bool: True if it is replaceable.
|
|
|
|
"""
|
|
|
|
return False
|
2019-07-28 07:18:39 -05:00
|
|
|
|
2019-10-09 13:07:30 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
class ModularChassis(Chassis):
|
|
|
|
def __init__(self):
|
|
|
|
super(ModularChassis, self).__init__()
|
|
|
|
self.module_initialized_count = 0
|
2019-07-28 07:18:39 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def is_modular_chassis(self):
|
|
|
|
"""
|
|
|
|
Retrieves whether the sonic instance is part of modular chassis
|
2019-07-28 07:18:39 -05:00
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
A bool value, should return False by default or for fixed-platforms.
|
|
|
|
Should return True for supervisor-cards, line-cards etc running as part
|
|
|
|
of modular-chassis.
|
2019-07-28 07:18:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return True
|
2019-08-28 13:59:37 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
##############################################
|
|
|
|
# Module methods
|
|
|
|
##############################################
|
|
|
|
def initialize_single_module(self, index):
|
|
|
|
count = self.get_num_modules()
|
|
|
|
if index < count:
|
|
|
|
if not self._module_list:
|
|
|
|
self._module_list = [None] * count
|
2022-03-23 02:16:03 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
if not self._module_list[index]:
|
|
|
|
from .module import Module
|
|
|
|
self._module_list[index] = Module(index + 1)
|
|
|
|
self.module_initialized_count += 1
|
|
|
|
|
|
|
|
def initialize_modules(self):
|
|
|
|
if not self._module_list:
|
|
|
|
from .module import Module
|
|
|
|
count = self.get_num_modules()
|
|
|
|
for index in range(1, count + 1):
|
|
|
|
self._module_list.append(Module(index))
|
|
|
|
self.module_initialized_count = count
|
|
|
|
elif self.module_initialized_count != len(self._module_list):
|
|
|
|
from .module import Module
|
|
|
|
for index in range(len(self._module_list)):
|
|
|
|
if self._module_list[index] is None:
|
|
|
|
self._module_list[index] = Module(index + 1)
|
|
|
|
self.module_initialized_count = len(self._module_list)
|
|
|
|
|
|
|
|
def get_num_modules(self):
|
|
|
|
"""
|
|
|
|
Retrieves the number of modules available on this chassis
|
2019-07-28 07:18:39 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
An integer, the number of modules available on this chassis
|
|
|
|
"""
|
|
|
|
return DeviceDataManager.get_linecard_count()
|
2020-03-09 12:41:10 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_all_modules(self):
|
2020-10-23 14:36:11 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves all modules available on this chassis
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of objects derived from ModuleBase representing all
|
|
|
|
modules available on this chassis
|
2020-10-23 14:36:11 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_modules()
|
|
|
|
return self._module_list
|
2020-10-23 14:36:11 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_module(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves module represented by (0-based) index <index>
|
2020-10-23 14:36:11 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Args:
|
|
|
|
index: An integer, the index (0-based) of the module to
|
|
|
|
retrieve
|
2020-03-09 12:41:10 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
An object dervied from ModuleBase representing the specified
|
|
|
|
module
|
2020-07-13 12:22:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
self.initialize_single_module(index)
|
|
|
|
return super(ModularChassis, self).get_module(index)
|
|
|
|
|
|
|
|
@utils.default_return(-1)
|
|
|
|
def get_module_index(self, module_name):
|
|
|
|
"""
|
|
|
|
Retrieves module index from the module name
|
2020-07-13 12:22:39 -05:00
|
|
|
|
|
|
|
Args:
|
2021-10-24 23:59:06 -05:00
|
|
|
module_name: A string, prefixed by SUPERVISOR, LINE-CARD or FABRIC-CARD
|
|
|
|
Ex. SUPERVISOR0, LINE-CARD1, FABRIC-CARD5
|
2020-07-13 12:22:39 -05:00
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
An integer, the index of the ModuleBase object in the module_list
|
2020-07-13 12:22:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return int(module_name[len('LINE-CARD')-1:])
|
2020-07-13 12:22:39 -05:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
##############################################
|
|
|
|
# SFP methods
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
def get_num_sfps(self):
|
2020-07-13 12:22:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves the number of sfps available on this chassis
|
2020-07-13 12:22:39 -05:00
|
|
|
|
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
An integer, the number of sfps available on this chassis
|
2020-07-13 12:22:39 -05:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return reduce(lambda x, y: x + y, (x.get_num_sfps() for x in self.get_all_modules()))
|
2020-11-16 20:56:03 -06:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
def get_all_sfps(self):
|
2020-11-16 20:56:03 -06:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
Retrieves all sfps available on this chassis
|
2020-11-16 20:56:03 -06:00
|
|
|
|
2021-10-24 23:59:06 -05:00
|
|
|
Returns:
|
|
|
|
A list of objects derived from SfpBase representing all sfps
|
|
|
|
available on this chassis
|
2020-11-16 20:56:03 -06:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
return reduce(lambda x, y: x + y, (x.get_all_sfps() for x in self.get_all_modules()))
|
|
|
|
|
|
|
|
def get_sfp(self, index):
|
|
|
|
"""
|
|
|
|
Retrieves sfp represented by (1-based) index <index>
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
|
|
|
The index should be the sequence of a physical port in a chassis,
|
|
|
|
starting from 1.
|
|
|
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
|
|
|
|
2020-11-16 20:56:03 -06:00
|
|
|
Returns:
|
2021-10-24 23:59:06 -05:00
|
|
|
An object dervied from SfpBase representing the specified sfp
|
2020-11-16 20:56:03 -06:00
|
|
|
"""
|
2021-10-24 23:59:06 -05:00
|
|
|
sfp_index = index % DeviceDataManager.get_linecard_max_port_count() - 1
|
|
|
|
slot_id = int((index - sfp_index - 1) / 16) + 1
|
|
|
|
module = self.get_module(slot_id - 1)
|
|
|
|
if not module:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return module.get_sfp(sfp_index - 1)
|