2019-05-09 02:57:17 -05:00
|
|
|
#############################################################################
|
|
|
|
# Celestica
|
|
|
|
#
|
|
|
|
# Module contains an implementation of SONiC Platform Base API and
|
|
|
|
# provides the Chassis information which are available in the platform
|
|
|
|
#
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
|
|
|
|
try:
|
|
|
|
from sonic_platform_base.chassis_base import ChassisBase
|
|
|
|
from sonic_platform.fan import Fan
|
2019-06-25 14:22:13 -05:00
|
|
|
from sonic_platform.psu import Psu
|
2019-07-02 13:05:18 -05:00
|
|
|
from sonic_platform.component import Component
|
2019-08-05 11:01:51 -05:00
|
|
|
from sonic_platform.thermal import Thermal
|
2019-08-14 19:51:20 -05:00
|
|
|
from sonic_platform.sfp import Sfp
|
|
|
|
from sonic_platform.eeprom import Tlv
|
2019-05-09 02:57:17 -05:00
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
2019-09-06 16:58:12 -05:00
|
|
|
NUM_FAN_TRAY = 3
|
|
|
|
NUM_FAN = 1
|
2019-06-25 14:22:13 -05:00
|
|
|
NUM_PSU = 2
|
2019-08-05 11:01:51 -05:00
|
|
|
NUM_THERMAL = 7
|
2019-08-14 19:51:20 -05:00
|
|
|
NUM_SFP = 52
|
2019-09-27 14:44:16 -05:00
|
|
|
NUM_COMPONENT = 3
|
2019-07-08 13:26:27 -05:00
|
|
|
RESET_REGISTER = "0x112"
|
2019-08-28 13:19:34 -05:00
|
|
|
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
|
|
|
|
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/previous-reboot-cause.txt"
|
|
|
|
HOST_CHK_CMD = "docker > /dev/null 2>&1"
|
2019-05-09 02:57:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Chassis(ChassisBase):
|
|
|
|
"""Platform-specific Chassis class"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2019-11-12 17:26:11 -06:00
|
|
|
ChassisBase.__init__(self)
|
2019-05-09 02:57:17 -05:00
|
|
|
self.config_data = {}
|
2019-09-06 16:58:12 -05:00
|
|
|
for fant_index in range(0, NUM_FAN_TRAY):
|
|
|
|
for fan_index in range(0, NUM_FAN):
|
|
|
|
fan = Fan(fant_index, fan_index)
|
|
|
|
self._fan_list.append(fan)
|
2019-06-25 14:22:13 -05:00
|
|
|
for index in range(0, NUM_PSU):
|
|
|
|
psu = Psu(index)
|
|
|
|
self._psu_list.append(psu)
|
2019-08-05 11:01:51 -05:00
|
|
|
for index in range(0, NUM_THERMAL):
|
|
|
|
thermal = Thermal(index)
|
|
|
|
self._thermal_list.append(thermal)
|
2020-01-10 14:50:51 -06:00
|
|
|
# sfp index start from 1
|
|
|
|
self._sfp_list.append(None)
|
|
|
|
for index in range(1, NUM_SFP+1):
|
2019-08-14 19:51:20 -05:00
|
|
|
sfp = Sfp(index)
|
|
|
|
self._sfp_list.append(sfp)
|
2019-09-27 14:44:16 -05:00
|
|
|
for index in range(0, NUM_COMPONENT):
|
|
|
|
component = Component(index)
|
|
|
|
self._component_list.append(component)
|
2019-08-28 13:19:34 -05:00
|
|
|
self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self.__is_host(
|
|
|
|
) else PMON_REBOOT_CAUSE_PATH
|
2019-09-27 14:44:16 -05:00
|
|
|
|
2019-08-14 19:51:20 -05:00
|
|
|
self._eeprom = Tlv()
|
2019-05-09 02:57:17 -05:00
|
|
|
|
2019-08-28 13:19:34 -05:00
|
|
|
def __is_host(self):
|
|
|
|
return os.system(HOST_CHK_CMD) == 0
|
|
|
|
|
2019-07-08 13:26:27 -05:00
|
|
|
def __read_txt_file(self, file_path):
|
|
|
|
try:
|
|
|
|
with open(file_path, 'r') as fd:
|
|
|
|
data = fd.read()
|
|
|
|
return data.strip()
|
|
|
|
except IOError:
|
2019-08-28 13:19:34 -05:00
|
|
|
pass
|
|
|
|
return None
|
2019-07-08 13:26:27 -05:00
|
|
|
|
2019-05-09 02:57:17 -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'
|
|
|
|
"""
|
2019-08-14 19:51:20 -05:00
|
|
|
return self._eeprom.get_mac()
|
|
|
|
|
2020-10-18 00:00:14 -05:00
|
|
|
def get_serial(self):
|
2019-08-14 19:51:20 -05:00
|
|
|
"""
|
|
|
|
Retrieves the hardware serial number for the chassis
|
|
|
|
Returns:
|
|
|
|
A string containing the hardware serial number for this chassis.
|
|
|
|
"""
|
|
|
|
return self._eeprom.get_serial()
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
return self._eeprom.get_eeprom()
|
2019-05-09 02:57:17 -05:00
|
|
|
|
2019-07-08 13:26:27 -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.
|
|
|
|
"""
|
|
|
|
description = 'None'
|
|
|
|
reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER
|
2019-09-27 14:44:16 -05:00
|
|
|
hw_reboot_cause = self._component_list[0].get_register_value(RESET_REGISTER)
|
2019-08-28 13:19:34 -05:00
|
|
|
sw_reboot_cause = self.__read_txt_file(
|
|
|
|
self._reboot_cause_path) or "Unknown"
|
2019-07-08 13:26:27 -05:00
|
|
|
|
2019-08-28 13:19:34 -05:00
|
|
|
if hw_reboot_cause == "0x55":
|
2019-07-08 13:26:27 -05:00
|
|
|
reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE
|
2019-08-05 11:01:51 -05:00
|
|
|
description = sw_reboot_cause
|
2019-07-08 13:26:27 -05:00
|
|
|
elif hw_reboot_cause == "0x11":
|
|
|
|
reboot_cause = self.REBOOT_CAUSE_POWER_LOSS
|
2019-08-28 13:19:34 -05:00
|
|
|
elif hw_reboot_cause == "0x33":
|
2019-07-08 13:26:27 -05:00
|
|
|
reboot_cause = self.REBOOT_CAUSE_WATCHDOG
|
|
|
|
else:
|
|
|
|
reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER
|
|
|
|
description = 'Unknown reason'
|
|
|
|
|
|
|
|
return (reboot_cause, description)
|
2020-01-10 14:50:51 -06:00
|
|
|
|
|
|
|
def get_watchdog(self):
|
|
|
|
"""
|
|
|
|
Retreives hardware watchdog device on this chassis
|
|
|
|
Returns:
|
|
|
|
An object derived from WatchdogBase representing the hardware
|
|
|
|
watchdog device
|
|
|
|
"""
|
|
|
|
if self._watchdog is None:
|
|
|
|
from sonic_platform.watchdog import Watchdog
|
|
|
|
self._watchdog = Watchdog()
|
|
|
|
|
|
|
|
return self._watchdog
|