7f4ab8fbd8
Submodule updates include the following commits: * src/sonic-utilities 9dc58ea...f9eb739 (18): > Remove unnecessary calls to str.encode() now that the package is Python 3; Fix deprecation warning (#1260) > [generate_dump] Ignoring file/directory not found Errors (#1201) > Fixed porstat rate and util issues (#1140) > fix error: interface counters is mismatch after warm-reboot (#1099) > Remove unnecessary calls to str.decode() now that the package is Python 3 (#1255) > [acl-loader] Make list sorting compliant with Python 3 (#1257) > Replace hard-coded fast-reboot with variable. And some typo corrections (#1254) > [configlet][portconfig] Remove calls to dict.has_key() which is not available in Python 3 (#1247) > Remove unnecessary conversions to list() and calls to dict.keys() (#1243) > Clean up LGTM alerts (#1239) > Add 'requests' as install dependency in setup.py (#1240) > Convert to Python 3 (#1128) > Fix mock SonicV2Connector in python3: use decode_responses mode so caller code will be the same as python2 (#1238) > [tests] Do not trim from PATH if we did not append to it; Clean up/fix shebangs in scripts (#1233) > Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (#1224) > [cli]: NAT show commands newline issue after migrated to Python3 (#1204) > [doc]: Update Command-Reference.md (#1231) > Added 'import sys' in feature.py file (#1232) * src/sonic-py-swsssdk 9d9f0c6...1664be9 (2): > Fix: no need to decode() after redis client scan, so it will work for both python2 and python3 (#96) > FieldValueMap `contains`(`in`) will also work when migrated to libswsscommon(C++ with SWIG wrapper) (#94) - Also fix Python 3-related issues: - Use integer (floor) division in config_samples.py (sonic-config-engine) - Replace print statement with print function in eeprom.py plugin for x86_64-kvm_x86_64-r0 platform - Update all platform plugins to be compatible with both Python 2 and Python 3 - Remove shebangs from plugins files which are not intended to be executable - Replace tabs with spaces in Python plugin files and fix alignment, because Python 3 is more strict - Remove trailing whitespace from plugins files
148 lines
4.8 KiB
Python
148 lines
4.8 KiB
Python
#############################################################################
|
|
# 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
|
|
from sonic_platform.psu import Psu
|
|
from sonic_platform.component import Component
|
|
from sonic_platform.thermal import Thermal
|
|
from sonic_platform.sfp import Sfp
|
|
from sonic_platform.eeprom import Tlv
|
|
except ImportError as e:
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
NUM_FAN_TRAY = 3
|
|
NUM_FAN = 1
|
|
NUM_PSU = 2
|
|
NUM_THERMAL = 7
|
|
NUM_SFP = 52
|
|
NUM_COMPONENT = 3
|
|
RESET_REGISTER = "0x112"
|
|
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"
|
|
|
|
|
|
class Chassis(ChassisBase):
|
|
"""Platform-specific Chassis class"""
|
|
|
|
def __init__(self):
|
|
ChassisBase.__init__(self)
|
|
self.config_data = {}
|
|
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)
|
|
for index in range(0, NUM_PSU):
|
|
psu = Psu(index)
|
|
self._psu_list.append(psu)
|
|
for index in range(0, NUM_THERMAL):
|
|
thermal = Thermal(index)
|
|
self._thermal_list.append(thermal)
|
|
# sfp index start from 1
|
|
self._sfp_list.append(None)
|
|
for index in range(1, NUM_SFP+1):
|
|
sfp = Sfp(index)
|
|
self._sfp_list.append(sfp)
|
|
for index in range(0, NUM_COMPONENT):
|
|
component = Component(index)
|
|
self._component_list.append(component)
|
|
self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self.__is_host(
|
|
) else PMON_REBOOT_CAUSE_PATH
|
|
|
|
self._eeprom = Tlv()
|
|
|
|
def __is_host(self):
|
|
return os.system(HOST_CHK_CMD) == 0
|
|
|
|
def __read_txt_file(self, file_path):
|
|
try:
|
|
with open(file_path, 'r') as fd:
|
|
data = fd.read()
|
|
return data.strip()
|
|
except IOError:
|
|
pass
|
|
return None
|
|
|
|
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'
|
|
"""
|
|
return self._eeprom.get_mac()
|
|
|
|
def get_serial(self):
|
|
"""
|
|
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()
|
|
|
|
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
|
|
hw_reboot_cause = self._component_list[0].get_register_value(RESET_REGISTER)
|
|
sw_reboot_cause = self.__read_txt_file(
|
|
self._reboot_cause_path) or "Unknown"
|
|
|
|
if hw_reboot_cause == "0x55":
|
|
reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE
|
|
description = sw_reboot_cause
|
|
elif hw_reboot_cause == "0x11":
|
|
reboot_cause = self.REBOOT_CAUSE_POWER_LOSS
|
|
elif hw_reboot_cause == "0x33":
|
|
reboot_cause = self.REBOOT_CAUSE_WATCHDOG
|
|
else:
|
|
reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER
|
|
description = 'Unknown reason'
|
|
|
|
return (reboot_cause, description)
|
|
|
|
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
|