[Nokia ixs7215] Platform API fixes (#9025)

* [Nokia ixs7215] Platform API fixes

This commit delivers the following fixes
    - Fix bug preventing access to second PSU eeprom
    - Fix bug preventing updates to front panel PSU status led
    - Fix SFP reset test case failure

* Fix LGTM alert
This commit is contained in:
dflynn-Nokia 2021-10-26 21:57:56 -04:00 committed by Qi Luo
parent f5fbb0bb31
commit 5b6fdf244c
4 changed files with 82 additions and 20 deletions

View File

@ -52,8 +52,8 @@ echo eeprom 0x55 > /sys/class/i2c-adapter/i2c-0/new_device
echo eeprom 0x56 > /sys/class/i2c-adapter/i2c-0/new_device
# Enumerate PSU eeprom devices
echo eeprom 0x50 > /sys/class/i2c-adapter/i2c-1/new_device
echo eeprom 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
echo eeprom 0x52 > /sys/class/i2c-adapter/i2c-1/new_device
# Enable optical SFP Tx
i2cset -y -m 0x0f 0 0x41 0x5 0x00

View File

@ -16,6 +16,7 @@
try:
from sonic_platform_base.sonic_eeprom.eeprom_base import EepromDecoder
from sonic_platform_base.sonic_eeprom.eeprom_tlvinfo import TlvInfoDecoder
from sonic_py_common import logger
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
@ -27,6 +28,8 @@ psu_eeprom_format = [
('Serial Number', 's', 11)
]
sonic_logger = logger.Logger('eeprom')
class Eeprom(TlvInfoDecoder):
"""Nokia platform-specific EEPROM class"""
@ -51,7 +54,7 @@ class Eeprom(TlvInfoDecoder):
self.index = psu_index
self.start_offset = 18
self.eeprom_path = self.I2C_DIR \
+ "i2c-1/1-005{}/eeprom".format(self.index)
+ "i2c-1/1-005{}/eeprom".format(self.index - 1)
self.format = psu_eeprom_format
# Decode device eeprom as per specified format
@ -79,6 +82,7 @@ class Eeprom(TlvInfoDecoder):
# Read System EEPROM as per ONIE TlvInfo EEPROM format.
self.eeprom_data = self.read_eeprom()
except Exception as e:
sonic_logger.log_warning("Unable to read system eeprom")
self.base_mac = 'NA'
self.serial_number = 'NA'
self.part_number = 'NA'
@ -88,6 +92,7 @@ class Eeprom(TlvInfoDecoder):
else:
eeprom = self.eeprom_data
if not self.is_valid_tlvinfo_header(eeprom):
sonic_logger.log_warning("Invalid system eeprom TLV header")
self.base_mac = 'NA'
self.serial_number = 'NA'
self.part_number = 'NA'
@ -144,10 +149,12 @@ class Eeprom(TlvInfoDecoder):
# Read Fan/PSU EEPROM as per the specified format.
self.eeprom_data = EepromDecoder.read_eeprom(self)
except Exception as e:
sonic_logger.log_warning("Unable to read device eeprom for PSU#{}".format(self.index))
return
# Bail out if PSU eeprom unavailable
if self.eeprom_data[0] == 255:
sonic_logger.log_warning("Uninitialized device eeprom for PSU#{}".format(self.index))
return
(valid, data) = self._get_eeprom_field("Model")
@ -164,6 +171,7 @@ class Eeprom(TlvInfoDecoder):
if valid:
self.serial_number = data.decode()
except Exception as e:
sonic_logger.log_warning("Unable to read serial# of PSU#{}".format(self.index))
return
# Fan device eeproms use ONIE TLV format
@ -172,10 +180,12 @@ class Eeprom(TlvInfoDecoder):
# Read Fan EEPROM as per ONIE TlvInfo EEPROM format.
self.eeprom_data = self.read_eeprom()
except Exception as e:
sonic_logger.log_warning("Unable to read device eeprom for Fan#{}".format(self.index))
return
eeprom = self.eeprom_data
if not self.is_valid_tlvinfo_header(eeprom):
sonic_logger.log_warning("Invalid device eeprom TLV header for Fan#{}".format(self.index))
return
total_length = (eeprom[9] << 8) | eeprom[10]

View File

@ -7,6 +7,7 @@
########################################################################
try:
import os
import sys
from sonic_platform_base.psu_base import PsuBase
from sonic_py_common import logger
@ -39,6 +40,34 @@ class Psu(PsuBase):
# PSU eeprom
self.eeprom = Eeprom(is_psu=True, psu_index=self.index)
def _write_sysfs_file(self, sysfs_file, value):
rv = 'ERR'
if (not os.path.isfile(sysfs_file)):
return rv
try:
with open(sysfs_file, 'w') as fd:
rv = fd.write(str(value))
except Exception as e:
rv = 'ERR'
return rv
def _read_sysfs_file(self, sysfs_file):
rv = 'ERR'
if (not os.path.isfile(sysfs_file)):
return rv
try:
with open(sysfs_file, 'r') as fd:
rv = fd.read()
except Exception as e:
rv = 'ERR'
rv = rv.rstrip('\r\n')
rv = rv.lstrip(" ")
return rv
def get_name(self):
"""
Retrieves the name of the device
@ -242,7 +271,20 @@ class Psu(PsuBase):
Returns:
A string, one of the predefined STATUS_LED_COLOR_* strings.
"""
return self._psu_master_led_color
if (not os.path.isfile("/sys/class/gpio/psuLedGreen/value") or
not os.path.isfile("/sys/class/gpio/psuLedAmber/value")):
return None
green = self._read_sysfs_file("/sys/class/gpio/psuLedGreen/value")
amber = self._read_sysfs_file("/sys/class/gpio/psuLedAmber/value")
if green == "ERR" or amber == "ERR":
return None
if green == "1":
return self.STATUS_LED_COLOR_GREEN
elif amber == "1":
return self.STATUS_LED_COLOR_AMBER
else:
return None
def set_status_master_led(self, color):
"""
@ -252,5 +294,22 @@ class Psu(PsuBase):
bool: True if status LED state is set successfully, False if
not
"""
self._psu_master_led_color = color
if (not os.path.isfile("/sys/class/gpio/psuLedGreen/value") or
not os.path.isfile("/sys/class/gpio/psuLedAmber/value")):
return False
if color == self.STATUS_LED_COLOR_GREEN:
rvg = self._write_sysfs_file("/sys/class/gpio/psuLedGreen/value", 1)
if rvg != "ERR":
rva = self._write_sysfs_file("/sys/class/gpio/psuLedAmber/value", 0)
elif color == self.STATUS_LED_COLOR_AMBER:
rvg = self._write_sysfs_file("/sys/class/gpio/psuLedGreen/value", 0)
if rvg != "ERR":
rva = self._write_sysfs_file("/sys/class/gpio/psuLedAmber/value", 1)
else:
return False
if rvg == "ERR" or rva == "ERR":
return False
return True

View File

@ -5,7 +5,6 @@
import os
import sys
import time
try:
from sonic_platform_base.sfp_base import SfpBase
@ -796,15 +795,9 @@ class Sfp(SfpBase):
Returns:
A boolean, True if successful, False if not
"""
if self.sfp_type == COPPER_TYPE:
# RJ45 and SFP ports not resettable
return False
self.tx_disable(True)
time.sleep(1)
self.tx_disable(False)
return True
def tx_disable(self, tx_disable):
"""
Disable SFP TX