[device/celestica]: Fix sfp index on dx010 platform api (#4346)

This commit is contained in:
Wirut Getbamrung 2020-04-26 01:54:45 +07:00 committed by GitHub
parent c56752a5f8
commit e75da77f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -56,8 +56,7 @@ class Chassis(ChassisBase):
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):
for index in range(0, NUM_SFP):
sfp = Sfp(index)
self._sfp_list.append(sfp)
for index in range(0, NUM_COMPONENT):
@ -159,3 +158,24 @@ class Chassis(ChassisBase):
self._watchdog = Watchdog()
return self._watchdog
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.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None
try:
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

View File

@ -100,7 +100,7 @@ class Sfp(SfpBase):
def __init__(self, sfp_index):
# Init index
self.index = sfp_index
self.port_num = self.index
self.port_num = self.index + 1
# Init eeprom path
eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom'
@ -593,7 +593,7 @@ class Sfp(SfpBase):
reg_value = int(content, 16)
# Determind if port_num start from 1 or 0
bit_index = self.port_num - 1 if self.PORT_START == 1 else self.port_num
bit_index = self.index
# Mask off the bit corresponding to our port
mask = (1 << bit_index)
@ -710,7 +710,7 @@ class Sfp(SfpBase):
reg_value = int(content, 16)
# Determind if port_num start from 1 or 0
bit_index = self.port_num - 1 if self.PORT_START == 1 else self.port_num
bit_index = self.index
# Mask off the bit corresponding to our port
mask = (1 << bit_index)
@ -823,7 +823,7 @@ class Sfp(SfpBase):
reg_value = int(content, 16)
# Determind if port_num start from 1 or 0
bit_index = self.port_num - 1 if self.PORT_START == 1 else self.port_num
bit_index = self.index
# Mask off the bit corresponding to our port
mask = (1 << bit_index)
@ -907,7 +907,7 @@ class Sfp(SfpBase):
reg_value = int(content, 16)
# Determind if port_num start from 1 or 0
bit_index = self.port_num - 1 if self.PORT_START == 1 else self.port_num
bit_index = self.index
# Mask off the bit corresponding to our port
mask = (1 << bit_index)
@ -942,4 +942,4 @@ class Sfp(SfpBase):
Returns:
A boolean value, True if device is operating properly, False if not
"""
return self.get_presence() and self.get_transceiver_bulk_status()
return self.get_presence() and not self.get_reset_status()