DellEMC: S5232, Z9264, Z9332 - Platform API fixes (#6842)

#### Why I did it

To incorporate the below changes in DellEMC S5232, Z9264, Z9332 platforms.

- Update thermal high threshold values
- Make watchdog API Python2 and Python3 compatible
- Fix LGTM alerts
- Z9264: Fix get_change_event timer value

#### How I did it

- Use 'universal_newlines=True' in subprocess.Popen call.
- Change the timeout in 'get_change_event' to milliseconds to match specification in sonic_platform_common/chassis_base.py
This commit is contained in:
Arun Saravanan Balachandran 2021-02-24 20:42:01 +00:00 committed by GitHub
parent cf55ca110d
commit 142d93b80a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 32 additions and 53 deletions

View File

@ -87,7 +87,6 @@ class Chassis(ChassisBase):
# check for this event change for sfp / do we need to handle timeout/sleep # check for this event change for sfp / do we need to handle timeout/sleep
def get_change_event(self, timeout=0): def get_change_event(self, timeout=0):
from time import sleep
""" """
Returns a nested dictionary containing all devices which have Returns a nested dictionary containing all devices which have
experienced a change at chassis level experienced a change at chassis level
@ -116,7 +115,6 @@ class Chassis(ChassisBase):
if (now_ms - start_ms >= timeout): if (now_ms - start_ms >= timeout):
return True, change_dict return True, change_dict
def get_sfp(self, index): def get_sfp(self, index):
""" """
Retrieves sfp represented by (0-based) index <index> Retrieves sfp represented by (0-based) index <index>
@ -136,7 +134,7 @@ class Chassis(ChassisBase):
# The index will start from 0 # The index will start from 0
sfp = self._sfp_list[index-1] sfp = self._sfp_list[index-1]
except IndexError: except IndexError:
sys.stderr.write("SFP index {} out of range (0-{})\n".format( sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list))) index, len(self._sfp_list)))
return sfp return sfp
@ -223,6 +221,7 @@ class Chassis(ChassisBase):
An integer represences the number of SFPs on the chassis. An integer represences the number of SFPs on the chassis.
""" """
return self._num_sfps return self._num_sfps
def get_reboot_cause(self): def get_reboot_cause(self):
""" """
Retrieves the cause of the previous reboot Retrieves the cause of the previous reboot
@ -259,4 +258,3 @@ class Chassis(ChassisBase):
return (self.REBOOT_CAUSE_HARDWARE_OTHER, "Reset Button Cold Reboot") return (self.REBOOT_CAUSE_HARDWARE_OTHER, "Reset Button Cold Reboot")
else: else:
return (self.REBOOT_CAUSE_NON_HARDWARE, None) return (self.REBOOT_CAUSE_NON_HARDWARE, None)

View File

@ -105,9 +105,9 @@ class Thermal(ThermalBase):
Celsius up to nearest thousandth of one degree Celsius, Celsius up to nearest thousandth of one degree Celsius,
e.g. 30.125 e.g. 30.125
""" """
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical") is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
if not is_valid: if not is_valid:
high_threshold = 0 return super(Thermal, self).get_high_threshold()
return float(high_threshold) return float(high_threshold)
@ -134,12 +134,11 @@ class Thermal(ThermalBase):
thermal in Celsius up to nearest thousandth of one degree thermal in Celsius up to nearest thousandth of one degree
Celsius, e.g. 30.125 Celsius, e.g. 30.125
""" """
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable") is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
if not is_valid: if not is_valid:
high_crit_threshold = 0 return super(Thermal, self).get_high_critical_threshold()
return float(high_crit_threshold) return float(high_crit_threshold)
def set_high_threshold(self, temperature): def set_high_threshold(self, temperature):
""" """

View File

@ -43,7 +43,7 @@ class Watchdog(WatchdogBase):
def _get_command_result(self, cmdline): def _get_command_result(self, cmdline):
try: try:
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE, proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT, universal_newlines=True)
stdout = proc.communicate()[0] stdout = proc.communicate()[0]
proc.wait() proc.wait()
result = stdout.rstrip('\n') result = stdout.rstrip('\n')
@ -207,4 +207,3 @@ class Watchdog(WatchdogBase):
return self.timeout - diff_time return self.timeout - diff_time
return 0 return 0

View File

@ -104,7 +104,7 @@ class Chassis(ChassisBase):
try: try:
with os.fdopen(os.open(reg_file, os.O_RDONLY)) as fd: with os.fdopen(os.open(reg_file, os.O_RDONLY)) as fd:
retval = fd.read() retval = fd.read()
except: except Exception:
pass pass
retval = retval.rstrip('\r\n') retval = retval.rstrip('\r\n')
retval = retval.lstrip(" ") retval = retval.lstrip(" ")
@ -134,6 +134,8 @@ class Chassis(ChassisBase):
port_dict = {} port_dict = {}
change_dict = {} change_dict = {}
change_dict['sfp'] = port_dict change_dict['sfp'] = port_dict
if timeout != 0:
timeout = timeout / 1000
try: try:
# We get notified when there is a MSI interrupt (vector 4/5)CVR # We get notified when there is a MSI interrupt (vector 4/5)CVR
# Open the sysfs file and register the epoll object # Open the sysfs file and register the epoll object
@ -174,7 +176,7 @@ class Chassis(ChassisBase):
if (retval != 0): if (retval != 0):
return False, change_dict return False, change_dict
return True, change_dict return True, change_dict
except: except Exception:
return False, change_dict return False, change_dict
finally: finally:
if self.oir_fd != -1: if self.oir_fd != -1:
@ -183,7 +185,6 @@ class Chassis(ChassisBase):
self.oir_fd.close() self.oir_fd.close()
self.oir_fd = -1 self.oir_fd = -1
self.epoll = -1 self.epoll = -1
return False, change_dict
def get_sfp(self, index): def get_sfp(self, index):
""" """
@ -281,7 +282,7 @@ class Chassis(ChassisBase):
try: try:
with open(self.REBOOT_CAUSE_PATH) as fd: with open(self.REBOOT_CAUSE_PATH) as fd:
reboot_cause = int(fd.read(), 16) reboot_cause = int(fd.read(), 16)
except: except Exception:
return (self.REBOOT_CAUSE_NON_HARDWARE, None) return (self.REBOOT_CAUSE_NON_HARDWARE, None)
if reboot_cause & 0x1: if reboot_cause & 0x1:

View File

@ -10,7 +10,6 @@
######################################################################## ########################################################################
try: try:
import os
import re import re
from sonic_platform_base.component_base import ComponentBase from sonic_platform_base.component_base import ComponentBase
@ -24,17 +23,18 @@ class Component(ComponentBase):
CHASSIS_COMPONENTS = [ CHASSIS_COMPONENTS = [
["BIOS", ("Performs initialization of hardware components during " ["BIOS", ("Performs initialization of hardware components during "
"booting")], "booting")],
["FPGA", ("Used for managing the system LEDs")], ["FPGA", ("Used for managing the system LEDs")],
["BMC", ("Platform management controller for on-board temperature " ["BMC", ("Platform management controller for on-board temperature "
"monitoring, in-chassis power, Fan and LED control")], "monitoring, in-chassis power, Fan and LED control")],
["System CPLD", ("Used for managing the CPU power sequence and CPU states")], ["System CPLD", ("Used for managing the CPU power sequence and CPU states")],
["Slave CPLD 1", ("Used for managing QSFP/QSFP28 port transceivers (1-16)")], ["Slave CPLD 1", ("Used for managing QSFP/QSFP28 port transceivers (1-16)")],
["Slave CPLD 2", ("Used for managing QSFP/QSFP28 port transceivers (17-32)")], ["Slave CPLD 2", ("Used for managing QSFP/QSFP28 port transceivers (17-32)")],
["Slave CPLD 3", ("Used for managing QSFP/QSFP28 port transceivers (33-48)")], ["Slave CPLD 3", ("Used for managing QSFP/QSFP28 port transceivers (33-48)")],
["Slave CPLD 4", ("Used for managing QSFP/QSFP28 port transceivers (49-64) and SFP/SFP28 " ["Slave CPLD 4", ("Used for managing QSFP/QSFP28 port transceivers (49-64) and SFP/SFP28 "
"port transceivers (65 and 66)")], "port transceivers (65 and 66)")],
] ]
def __init__(self, component_index=0): def __init__(self, component_index=0):
self.index = component_index self.index = component_index
self.name = self.CHASSIS_COMPONENTS[self.index][0] self.name = self.CHASSIS_COMPONENTS[self.index][0]
@ -48,7 +48,6 @@ class Component(ComponentBase):
""" """
return self.name return self.name
def get_description(self): def get_description(self):
""" """
Retrieves the description of the component Retrieves the description of the component
@ -77,7 +76,7 @@ class Component(ComponentBase):
if version: if version:
rv = version.group(1).strip() rv = version.group(1).strip()
return rv return rv
def install_firmware(self, image_path): def install_firmware(self, image_path):
""" """
Installs firmware to the component Installs firmware to the component
@ -87,5 +86,3 @@ class Component(ComponentBase):
A boolean, True if install was successful, False if not A boolean, True if install was successful, False if not
""" """
return False return False

View File

@ -12,11 +12,7 @@ try:
import os import os
import time import time
import struct import struct
import sys
import getopt
import select
import mmap import mmap
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform_base.sfp_base import SfpBase from sonic_platform_base.sfp_base import SfpBase
from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId
from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom
@ -971,7 +967,7 @@ class Sfp(SfpBase):
reg_value = reg_value & ~mask reg_value = reg_value & ~mask
# Convert our register value back to a hex string and write back # Convert our register value back to a hex string and write back
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
# Sleep 1 second to allow it to settle # Sleep 1 second to allow it to settle
time.sleep(1) time.sleep(1)
@ -979,7 +975,7 @@ class Sfp(SfpBase):
reg_value = reg_value | mask reg_value = reg_value | mask
# Convert our register value back to a hex string and write back # Convert our register value back to a hex string and write back
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
return True return True
@ -1011,7 +1007,7 @@ class Sfp(SfpBase):
reg_value = reg_value & ~mask reg_value = reg_value & ~mask
# Convert our register value back to a hex string and write back # Convert our register value back to a hex string and write back
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
return True return True
@ -1030,12 +1026,6 @@ class Sfp(SfpBase):
""" """
return False return False
def tx_disable_channel(self, channel, disable):
"""
Sets the tx_disable for specified SFP channels
"""
return False
def set_power_override(self, power_override, power_set): def set_power_override(self, power_override, power_set):
""" """
Sets SFP power level using power_override and power_set Sets SFP power level using power_override and power_set

View File

@ -11,7 +11,7 @@
try: try:
from sonic_platform_base.thermal_base import ThermalBase from sonic_platform_base.thermal_base import ThermalBase
from sonic_platform.ipmihelper import IpmiSensor, IpmiFru from sonic_platform.ipmihelper import IpmiSensor
except ImportError as e: except ImportError as e:
raise ImportError(str(e) + "- required module not found") raise ImportError(str(e) + "- required module not found")
@ -105,9 +105,9 @@ class Thermal(ThermalBase):
Celsius up to nearest thousandth of one degree Celsius, Celsius up to nearest thousandth of one degree Celsius,
e.g. 30.125 e.g. 30.125
""" """
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical") is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
if not is_valid: if not is_valid:
high_threshold = 0 return super(Thermal, self).get_high_threshold()
return float(high_threshold) return float(high_threshold)
@ -135,9 +135,9 @@ class Thermal(ThermalBase):
thermal in Celsius up to nearest thousandth of one degree thermal in Celsius up to nearest thousandth of one degree
Celsius, e.g. 30.125 Celsius, e.g. 30.125
""" """
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable") is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
if not is_valid: if not is_valid:
high_crit_threshold = 0 return super(Thermal, self).get_high_critical_threshold()
return float(high_crit_threshold) return float(high_crit_threshold)

View File

@ -10,8 +10,6 @@
######################################################################## ########################################################################
try: try:
import sys
import struct
import ctypes import ctypes
import subprocess import subprocess
from sonic_platform_base.watchdog_base import WatchdogBase from sonic_platform_base.watchdog_base import WatchdogBase
@ -45,7 +43,7 @@ class Watchdog(WatchdogBase):
def _get_command_result(self, cmdline): def _get_command_result(self, cmdline):
try: try:
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE, proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT, universal_newlines=True)
stdout = proc.communicate()[0] stdout = proc.communicate()[0]
proc.wait() proc.wait()
result = stdout.rstrip('\n') result = stdout.rstrip('\n')
@ -139,8 +137,6 @@ class Watchdog(WatchdogBase):
self.timeout = seconds self.timeout = seconds
return seconds return seconds
return -1
def disarm(self): def disarm(self):
""" """
Disarm the hardware watchdog Disarm the hardware watchdog
@ -211,4 +207,3 @@ class Watchdog(WatchdogBase):
return self.timeout - diff_time return self.timeout - diff_time
return 0 return 0

View File

@ -200,7 +200,7 @@ class Chassis(ChassisBase):
# The index will start from 0 # The index will start from 0
sfp = self._sfp_list[index-1] sfp = self._sfp_list[index-1]
except IndexError: except IndexError:
sys.stderr.write("SFP index {} out of range (0-{})\n".format( sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list))) index, len(self._sfp_list)))
return sfp return sfp

View File

@ -111,9 +111,9 @@ class Thermal(ThermalBase):
Celsius up to nearest thousandth of one degree Celsius, Celsius up to nearest thousandth of one degree Celsius,
e.g. 30.125 e.g. 30.125
""" """
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical") is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
if not is_valid: if not is_valid:
high_threshold = 0 return super(Thermal, self).get_high_threshold()
return float(high_threshold) return float(high_threshold)
@ -140,9 +140,9 @@ class Thermal(ThermalBase):
thermal in Celsius up to nearest thousandth of one degree thermal in Celsius up to nearest thousandth of one degree
Celsius, e.g. 30.125 Celsius, e.g. 30.125
""" """
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable") is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
if not is_valid: if not is_valid:
high_crit_threshold = 0 return super(Thermal, self).get_high_critical_threshold()
return float(high_crit_threshold) return float(high_crit_threshold)