Skip to content

Commit

Permalink
[device/celestica]: update dx010 sfp port name api
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirut Getbamrung committed Nov 13, 2020
1 parent 8d69f37 commit 6470c93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
try:
import sys
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper
from sonic_py_common import device_info
from event import SfpEvent
from helper import APIHelper
except ImportError as e:
Expand Down Expand Up @@ -48,9 +50,14 @@ def __init__(self):
self.__initialize_components()

def __initialize_sfp(self):
sfputil_helper = SfpUtilHelper()
port_config_file_path = device_info.get_path_to_port_config_file()
sfputil_helper.read_porttab_mappings(port_config_file_path, 0)

from sonic_platform.sfp import Sfp
for index in range(0, NUM_SFP):
sfp = Sfp(index)
name_idx = 0 if index+1 == NUM_SFP else index+1
sfp = Sfp(index, sfputil_helper.logical[name_idx])
self._sfp_list.append(sfp)
self.sfp_module_initialized = True

Expand Down Expand Up @@ -174,7 +181,7 @@ def get_change_event(self, timeout=0):
if sfp_event:
return True, {'sfp': sfp_event}

return False, {}
return False, {'sfp': {}}

##############################################################
######################## SFP methods #########################
Expand Down
20 changes: 3 additions & 17 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId
from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom
from sonic_platform_base.sonic_sfp.inf8628 import inf8628InterfaceId
from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper
from helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
Expand Down Expand Up @@ -168,19 +167,16 @@ class Sfp(SfpBase):
RESET_PATH = "/sys/devices/platform/dx010_cpld/qsfp_reset"
LP_PATH = "/sys/devices/platform/dx010_cpld/qsfp_lpmode"
PRS_PATH = "/sys/devices/platform/dx010_cpld/qsfp_modprs"
PLATFORM_ROOT_PATH = "/usr/share/sonic/device"
PMON_HWSKU_PATH = "/usr/share/sonic/hwsku"

def __init__(self, sfp_index):
def __init__(self, sfp_index, sfp_name):
SfpBase.__init__(self)
# Init index
self.index = sfp_index
self.port_num = self.index + 1
self.dom_supported = False
self.sfp_type, self.port_name = self.__get_sfp_info()
self._api_helper = APIHelper()
self.platform = self._api_helper.platform
self.hwsku = self._api_helper.hwsku
self.name = sfp_name

# Init eeprom path
eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom'
Expand Down Expand Up @@ -235,12 +231,6 @@ def __convert_string_to_num(self, value_str):
else:
return 'N/A'

def __get_path_to_port_config_file(self):
platform_path = "/".join([self.PLATFORM_ROOT_PATH, self.platform])
hwsku_path = "/".join([platform_path, self.hwsku]
) if self._api_helper.is_host() else self.PMON_HWSKU_PATH
return "/".join([hwsku_path, "port_config.ini"])

def __read_eeprom_specific_bytes(self, offset, num_bytes):
sysfsfile_eeprom = None
eeprom_raw = []
Expand Down Expand Up @@ -1320,11 +1310,7 @@ def get_name(self):
Returns:
string: The name of the device
"""
sfputil_helper = SfpUtilHelper()
sfputil_helper.read_porttab_mappings(
self.__get_path_to_port_config_file())
name = sfputil_helper.logical[self.index] or "Unknown"
return name
return self.name

def get_presence(self):
"""
Expand Down

0 comments on commit 6470c93

Please sign in to comment.