Skip to content

Commit 2bce349

Browse files
ArunSaravananBalachandranyxieca
authored andcommitted
DellEMC: S5232, Z9264, Z9332 - Platform API fixes (sonic-net#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
1 parent c9351ad commit 2bce349

10 files changed

Lines changed: 32 additions & 53 deletions

File tree

platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/chassis.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def __del__(self):
8787
# check for this event change for sfp / do we need to handle timeout/sleep
8888

8989
def get_change_event(self, timeout=0):
90-
from time import sleep
9190
"""
9291
Returns a nested dictionary containing all devices which have
9392
experienced a change at chassis level
@@ -116,7 +115,6 @@ def get_change_event(self, timeout=0):
116115
if (now_ms - start_ms >= timeout):
117116
return True, change_dict
118117

119-
120118
def get_sfp(self, index):
121119
"""
122120
Retrieves sfp represented by (0-based) index <index>
@@ -136,7 +134,7 @@ def get_sfp(self, index):
136134
# The index will start from 0
137135
sfp = self._sfp_list[index-1]
138136
except IndexError:
139-
sys.stderr.write("SFP index {} out of range (0-{})\n".format(
137+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
140138
index, len(self._sfp_list)))
141139
return sfp
142140

@@ -223,6 +221,7 @@ def get_num_sfps(self):
223221
An integer represences the number of SFPs on the chassis.
224222
"""
225223
return self._num_sfps
224+
226225
def get_reboot_cause(self):
227226
"""
228227
Retrieves the cause of the previous reboot
@@ -259,4 +258,3 @@ def get_reboot_cause(self):
259258
return (self.REBOOT_CAUSE_HARDWARE_OTHER, "Reset Button Cold Reboot")
260259
else:
261260
return (self.REBOOT_CAUSE_NON_HARDWARE, None)
262-

platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/thermal.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def get_high_threshold(self):
105105
Celsius up to nearest thousandth of one degree Celsius,
106106
e.g. 30.125
107107
"""
108-
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical")
108+
is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
109109
if not is_valid:
110-
high_threshold = 0
110+
return super(Thermal, self).get_high_threshold()
111111

112112
return float(high_threshold)
113113

@@ -134,12 +134,11 @@ def get_high_critical_threshold(self):
134134
thermal in Celsius up to nearest thousandth of one degree
135135
Celsius, e.g. 30.125
136136
"""
137-
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable")
137+
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
138138
if not is_valid:
139-
high_crit_threshold = 0
139+
return super(Thermal, self).get_high_critical_threshold()
140140

141141
return float(high_crit_threshold)
142-
143142

144143
def set_high_threshold(self, temperature):
145144
"""

platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/watchdog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self):
4343
def _get_command_result(self, cmdline):
4444
try:
4545
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
46-
stderr=subprocess.STDOUT)
46+
stderr=subprocess.STDOUT, universal_newlines=True)
4747
stdout = proc.communicate()[0]
4848
proc.wait()
4949
result = stdout.rstrip('\n')
@@ -207,4 +207,3 @@ def get_remaining_time(self):
207207
return self.timeout - diff_time
208208

209209
return 0
210-

platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/chassis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _get_register(self, reg_file):
104104
try:
105105
with os.fdopen(os.open(reg_file, os.O_RDONLY)) as fd:
106106
retval = fd.read()
107-
except:
107+
except Exception:
108108
pass
109109
retval = retval.rstrip('\r\n')
110110
retval = retval.lstrip(" ")
@@ -134,6 +134,8 @@ def get_change_event(self, timeout=0):
134134
port_dict = {}
135135
change_dict = {}
136136
change_dict['sfp'] = port_dict
137+
if timeout != 0:
138+
timeout = timeout / 1000
137139
try:
138140
# We get notified when there is a MSI interrupt (vector 4/5)CVR
139141
# Open the sysfs file and register the epoll object
@@ -174,7 +176,7 @@ def get_change_event(self, timeout=0):
174176
if (retval != 0):
175177
return False, change_dict
176178
return True, change_dict
177-
except:
179+
except Exception:
178180
return False, change_dict
179181
finally:
180182
if self.oir_fd != -1:
@@ -183,7 +185,6 @@ def get_change_event(self, timeout=0):
183185
self.oir_fd.close()
184186
self.oir_fd = -1
185187
self.epoll = -1
186-
return False, change_dict
187188

188189
def get_sfp(self, index):
189190
"""
@@ -281,7 +282,7 @@ def get_reboot_cause(self):
281282
try:
282283
with open(self.REBOOT_CAUSE_PATH) as fd:
283284
reboot_cause = int(fd.read(), 16)
284-
except:
285+
except Exception:
285286
return (self.REBOOT_CAUSE_NON_HARDWARE, None)
286287

287288
if reboot_cause & 0x1:

platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/component.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
########################################################################
1111

1212
try:
13-
import os
1413
import re
1514
from sonic_platform_base.component_base import ComponentBase
1615

@@ -24,17 +23,18 @@ class Component(ComponentBase):
2423

2524
CHASSIS_COMPONENTS = [
2625
["BIOS", ("Performs initialization of hardware components during "
27-
"booting")],
26+
"booting")],
2827
["FPGA", ("Used for managing the system LEDs")],
2928
["BMC", ("Platform management controller for on-board temperature "
30-
"monitoring, in-chassis power, Fan and LED control")],
29+
"monitoring, in-chassis power, Fan and LED control")],
3130
["System CPLD", ("Used for managing the CPU power sequence and CPU states")],
3231
["Slave CPLD 1", ("Used for managing QSFP/QSFP28 port transceivers (1-16)")],
3332
["Slave CPLD 2", ("Used for managing QSFP/QSFP28 port transceivers (17-32)")],
3433
["Slave CPLD 3", ("Used for managing QSFP/QSFP28 port transceivers (33-48)")],
3534
["Slave CPLD 4", ("Used for managing QSFP/QSFP28 port transceivers (49-64) and SFP/SFP28 "
36-
"port transceivers (65 and 66)")],
37-
]
35+
"port transceivers (65 and 66)")],
36+
]
37+
3838
def __init__(self, component_index=0):
3939
self.index = component_index
4040
self.name = self.CHASSIS_COMPONENTS[self.index][0]
@@ -48,7 +48,6 @@ def get_name(self):
4848
"""
4949
return self.name
5050

51-
5251
def get_description(self):
5352
"""
5453
Retrieves the description of the component
@@ -77,7 +76,7 @@ def get_firmware_version(self):
7776
if version:
7877
rv = version.group(1).strip()
7978
return rv
80-
79+
8180
def install_firmware(self, image_path):
8281
"""
8382
Installs firmware to the component
@@ -87,5 +86,3 @@ def install_firmware(self, image_path):
8786
A boolean, True if install was successful, False if not
8887
"""
8988
return False
90-
91-

platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/sfp.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
import os
1313
import time
1414
import struct
15-
import sys
16-
import getopt
17-
import select
1815
import mmap
19-
from sonic_platform_base.chassis_base import ChassisBase
2016
from sonic_platform_base.sfp_base import SfpBase
2117
from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId
2218
from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom
@@ -976,15 +972,15 @@ def reset(self):
976972
reg_value = reg_value & ~mask
977973

978974
# Convert our register value back to a hex string and write back
979-
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
975+
self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
980976

981977
# Sleep 1 second to allow it to settle
982978
time.sleep(1)
983979

984980
reg_value = reg_value | mask
985981

986982
# Convert our register value back to a hex string and write back
987-
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
983+
self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
988984

989985
return True
990986

@@ -1016,7 +1012,7 @@ def set_lpmode(self, lpmode):
10161012
reg_value = reg_value & ~mask
10171013

10181014
# Convert our register value back to a hex string and write back
1019-
status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
1015+
self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset)
10201016

10211017
return True
10221018

@@ -1035,12 +1031,6 @@ def tx_disable_channel(self, channel, disable):
10351031
"""
10361032
return False
10371033

1038-
def tx_disable_channel(self, channel, disable):
1039-
"""
1040-
Sets the tx_disable for specified SFP channels
1041-
"""
1042-
return False
1043-
10441034
def set_power_override(self, power_override, power_set):
10451035
"""
10461036
Sets SFP power level using power_override and power_set

platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/thermal.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
try:
1313
from sonic_platform_base.thermal_base import ThermalBase
14-
from sonic_platform.ipmihelper import IpmiSensor, IpmiFru
14+
from sonic_platform.ipmihelper import IpmiSensor
1515
except ImportError as e:
1616
raise ImportError(str(e) + "- required module not found")
1717

@@ -105,9 +105,9 @@ def get_high_threshold(self):
105105
Celsius up to nearest thousandth of one degree Celsius,
106106
e.g. 30.125
107107
"""
108-
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical")
108+
is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
109109
if not is_valid:
110-
high_threshold = 0
110+
return super(Thermal, self).get_high_threshold()
111111

112112
return float(high_threshold)
113113

@@ -135,9 +135,9 @@ def get_high_critical_threshold(self):
135135
thermal in Celsius up to nearest thousandth of one degree
136136
Celsius, e.g. 30.125
137137
"""
138-
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable")
138+
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
139139
if not is_valid:
140-
high_crit_threshold = 0
140+
return super(Thermal, self).get_high_critical_threshold()
141141

142142
return float(high_crit_threshold)
143143

platform/broadcom/sonic-platform-modules-dell/z9264f/sonic_platform/watchdog.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
########################################################################
1111

1212
try:
13-
import sys
14-
import struct
1513
import ctypes
1614
import subprocess
1715
from sonic_platform_base.watchdog_base import WatchdogBase
@@ -45,7 +43,7 @@ def __init__(self):
4543
def _get_command_result(self, cmdline):
4644
try:
4745
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
48-
stderr=subprocess.STDOUT)
46+
stderr=subprocess.STDOUT, universal_newlines=True)
4947
stdout = proc.communicate()[0]
5048
proc.wait()
5149
result = stdout.rstrip('\n')
@@ -139,8 +137,6 @@ def arm(self, seconds):
139137
self.timeout = seconds
140138
return seconds
141139

142-
return -1
143-
144140
def disarm(self):
145141
"""
146142
Disarm the hardware watchdog
@@ -211,4 +207,3 @@ def get_remaining_time(self):
211207
return self.timeout - diff_time
212208

213209
return 0
214-

platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/chassis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def get_sfp(self, index):
200200
# The index will start from 0
201201
sfp = self._sfp_list[index-1]
202202
except IndexError:
203-
sys.stderr.write("SFP index {} out of range (0-{})\n".format(
203+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
204204
index, len(self._sfp_list)))
205205
return sfp
206206

platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/thermal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ def get_high_threshold(self):
111111
Celsius up to nearest thousandth of one degree Celsius,
112112
e.g. 30.125
113113
"""
114-
is_valid, high_threshold = self.sensor.get_threshold("UpperCritical")
114+
is_valid, high_threshold = self.sensor.get_threshold("UpperNonCritical")
115115
if not is_valid:
116-
high_threshold = 0
116+
return super(Thermal, self).get_high_threshold()
117117

118118
return float(high_threshold)
119119

@@ -140,9 +140,9 @@ def get_high_critical_threshold(self):
140140
thermal in Celsius up to nearest thousandth of one degree
141141
Celsius, e.g. 30.125
142142
"""
143-
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperNonRecoverable")
143+
is_valid, high_crit_threshold = self.sensor.get_threshold("UpperCritical")
144144
if not is_valid:
145-
high_crit_threshold = 0
145+
return super(Thermal, self).get_high_critical_threshold()
146146

147147
return float(high_crit_threshold)
148148

0 commit comments

Comments
 (0)