Skip to content

Commit

Permalink
[AS9726-32D] support system-health check
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Wu <sean_wu@edge-core.com>
  • Loading branch information
seanwu-ec committed Aug 5, 2021
1 parent a3a9242 commit 2ec7542
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__all__ = ['chassis', 'eeprom', 'platform', 'psu', 'sfp', 'thermal', 'fan']
__all__ = [ "platform", "chassis", "sfp", "eeprom", "component", "psu", "thermal", "fan", "fan_drawer" ]
from . import platform
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
#############################################################################

import os
import sys

try:
from sonic_platform_base.chassis_base import ChassisBase
from .helper import APIHelper
from .event import SfpEvent
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

NUM_FAN_TRAY = 6
NUM_FAN = 2
NUM_PSU = 2
NUM_THERMAL = 3
NUM_THERMAL = 6
NUM_QSFP = 32
PORT_START = 1
PORT_END = 34
Expand Down Expand Up @@ -62,11 +64,11 @@ def __initialize_sfp(self):
self.sfp_module_initialized = True

def __initialize_fan(self):
from sonic_platform.fan import Fan
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)
from sonic_platform.fan_drawer import FanDrawer
for fant_index in range(NUM_FAN_TRAY):
fandrawer = FanDrawer(fant_index)
self._fan_drawer_list.append(fandrawer)
self._fan_list.extend(fandrawer._fan_list)

def __initialize_psu(self):
from sonic_platform.psu import Psu
Expand Down Expand Up @@ -141,7 +143,15 @@ def get_base_mac(self):
"""
return self._eeprom.get_mac()

def get_serial_number(self):
def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return self._eeprom.get_pn()

def get_serial(self):
"""
Retrieves the hardware serial number for the chassis
Returns:
Expand Down Expand Up @@ -177,6 +187,15 @@ def get_reboot_cause(self):

return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause)

def get_change_event(self, timeout=0):
# SFP event
if not self.sfp_module_initialized:
self.__initialize_sfp()

status, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout)

return status, sfp_event

def get_sfp(self, index):
"""
Retrieves sfp represented by (1-based) index <index>
Expand All @@ -199,3 +218,29 @@ def get_sfp(self, index):
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

def get_position_in_parent(self):
"""
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):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False

def initizalize_system_led(self):
return True

def get_status_led(self):
return "ControlledByFPGA"

def set_status_led(self, color):
return True
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,55 @@ def install_firmware(self, image_path):
A boolean, True if install successfully, False if not
"""
raise NotImplementedError

def get_presence(self):
"""
Retrieves the presence of the device
Returns:
bool: True if device is present, False if not
"""
return True

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return 'N/A'

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return 'N/A'

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
return True

def get_position_in_parent(self):
"""
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):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def _load_eeprom(self):
def get_eeprom(self):
return self._eeprom

def get_pn(self):
return self._eeprom.get('0x22', "Undefined.")

def get_serial(self):
return self._eeprom.get('0x23', "Undefined.")

Expand Down
55 changes: 55 additions & 0 deletions device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
try:
import time
from .helper import APIHelper
from sonic_py_common.logger import Logger
except ImportError as e:
raise ImportError(repr(e) + " - required module not found")


class SfpEvent:
''' Listen to insert/remove sfp events '''

def __init__(self, sfp_list):
self._api_helper = APIHelper()
self._sfp_list = sfp_list
self._logger = Logger()

sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
def get_sfp_event(self, timeout=2000):
now = time.time()
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
timeout = 1000
timeout = timeout / float(1000) # Convert to secs

if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
return True, change_dict

bitmap = 0
for sfp in self._sfp_list:
modpres = sfp.get_presence()
i=sfp.port_num-1
if modpres:
bitmap = bitmap | (1 << i)

changed_ports = self.sfp_change_event_data['present'] ^ bitmap
if changed_ports:
for sfp in self._sfp_list:
i=sfp.port_num-1
if (changed_ports & (1 << i)):
if (bitmap & (1 << i)) == 0:
port_dict[i+1] = '0'
else:
port_dict[i+1] = '1'


# Update the cache dict
self.sfp_change_event_data['present'] = bitmap
self.sfp_change_event_data['last'] = now
self.sfp_change_event_data['valid'] = 1
return True, change_dict
else:
return True, change_dict
Loading

0 comments on commit 2ec7542

Please sign in to comment.