Skip to content

Commit

Permalink
[ag9032v2]Fixed python lgtm alerts.
Browse files Browse the repository at this point in the history
Signed-off-by: johnson <johnson.lu@deltaww.com>
  • Loading branch information
JohnsonYJLu committed Sep 30, 2021
1 parent c0d1027 commit cf6a42d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ["platform", "chassis", "fan", "psu", "fan_drawer", "thermal", "eeprom", "sfp"]
__all__ = ['platform', 'chassis', 'fan', 'psu', 'fan_drawer', 'thermal', 'eeprom', 'sfp']
from sonic_platform import *

Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
class Fan(FanBase):
def __init__(self, fantray_index, fan_index, psu_fan):
FanBase.__init__(self)
self.is_psu_fan = psu_fan
if not self.is_psu_fan:
self.fantrayindex = fantray_index + 1
self.fanindex = fan_index + 1
self.psu_fan = psu_fan
if not self.psu_fan:
self.fantray_index = fantray_index + 1
self.fan_index = fan_index + 1
else:
self.fanindex = fan_index
self.fan_index = fan_index
def get_name(self):
"""
Retrieves the fan name
Returns:
string: The name of the device
"""
if not self.is_psu_fan:
return "FanTray{}-Fan{}".format(self.fantrayindex, self.fanindex)
if not self.psu_fan:
return "FanTray{}-Fan{}".format(self.fantray_index, self.fan_index)
else:
return "PSU{} Fan".format(self.fanindex)
return "PSU{} Fan".format(self.fan_index)

def get_model(self):
"""
Retrieves the part number of the FAN
Returns:
string: Part number of FAN
"""
if self.is_psu_fan:
if self.psu_fan:
return None
else:
return 'N/A'
Expand All @@ -52,7 +52,7 @@ def get_serial(self):
Returns:
string: Serial number of FAN
"""
if self.is_psu_fan:
if self.psu_fan:
return None
else:
return 'N/A'
Expand All @@ -65,11 +65,11 @@ def get_presence(self):
"""
presence = False
try:
if self.is_psu_fan:
if self.psu_fan:
p = os.popen("ipmitool raw 0x38 0x2 3 0x6a 0x3 1")
content = p.readline().rstrip()
reg_value = int(content,16)
if self.fanindex == 1:
if self.fan_index == 1:
mask = (1 << 7)
else:
mask = (1 << 3)
Expand All @@ -80,7 +80,7 @@ def get_presence(self):
p = os.popen(command)
content = p.readline().rstrip()
reg_value = int(content, 16)
mask = (16 >> self.fantrayindex - 1)
mask = (16 >> self.fantray_index - 1)
if reg_value & mask == 0:
presence = True
p.close()
Expand All @@ -95,12 +95,12 @@ def get_status(self):
bool: True if FAN is operating properly, False if not
"""
presence = True
if self.is_psu_fan:
if self.psu_fan:
try:
p = os.popen("ipmitool raw 0x38 0x2 3 0x6a 0x3 1")
content = p.readline().rstrip()
reg_value = int(content,16)
if self.fanindex == 1:
if self.fan_index == 1:
mask = (1 << 6)
else:
mask = (1 << 2)
Expand Down Expand Up @@ -133,10 +133,10 @@ def get_speed(self):
int: percentage of the max fan speed
"""
try:
if self.is_psu_fan:
command = "ipmitool sdr get PSU{}_Fan".format(self.fanindex)
if self.psu_fan:
command = "ipmitool sdr get PSU{}_Fan".format(self.fan_index)
else:
command = "ipmitool sdr get Fantray_{}_{}".format(self.fantrayindex, self.fanindex)
command = "ipmitool sdr get Fantray_{}_{}".format(self.fantray_index, self.fan_index)
p = os.popen(command)
content = p.read().rstrip()
info_req = re.search(r"%s\s*:(.*)" % "Sensor Reading", content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def __init__(self, fantray_index):

FanDrawerBase.__init__(self)
# FanTray is 1-based in Delta platforms
self.index = fantray_index + 1
self.fantray_index = fantray_index + 1

def get_name(self):
"""
Retrieves the fan drawer name
Returns:
string: The name of the device
"""
return "FanTray{}".format(self.index)
return "FanTray{}".format(self.fantray_index)
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class Psu(PsuBase):
def __init__(self, index):
PsuBase.__init__(self)
self.index = index + 1
fan_index = self.index
# Passing True to specify it is a PSU fan
self._fan_list.append(Fan(0, fan_index, True))
self._fan_list.append(Fan(0, self.index, True))

def get_name(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ def __init__(self, index, sfp_type, eeprom_path):
self.eeprom_path = eeprom_path
#port_type is the native port type and sfp_type is the transceiver type
#sfp_type will be detected in get_transceiver_info
self.port_type = sfp_type
self.sfp_type = self.port_type
self.sfp_type = sfp_type
self.qsfpInfo = sff8436InterfaceId()
self.qsfpDomInfo = sff8436Dom()
self.sfpInfo = sff8472InterfaceId()
Expand Down Expand Up @@ -1344,7 +1343,7 @@ def get_port_form_factor(self):
"""
Retrieves the native port type
"""
return self.port_type
return self.sfp_type

def get_max_port_power(self):
"""
Expand All @@ -1354,7 +1353,7 @@ def get_max_port_power(self):
TODO: enhance by placing power limits in config file
***
"""
return 12.0 if self.port_type == 'QSFP_DD' else 2.5
return 12.0 if self.sfp_type == 'QSFP_DD' else 2.5

def set_media_type(self):
"""
Expand All @@ -1371,9 +1370,9 @@ def set_media_type(self):
self.sfp_type = 'QSFP_DD'
else:
#Set native port type if EEPROM type is not recognized/readable
self.sfp_type = self.port_type
self.sfp_type = self.sfp_type
else:
self.sfp_type = self.port_type
self.sfp_type = self.sfp_type

return self.sfp_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Thermal(ThermalBase):

def __init__(self, thermal_index):
ThermalBase.__init__(self)
self.index = thermal_index + 1
self.thermal_index = thermal_index + 1

def get_name(self):
"""
Expand All @@ -37,7 +37,7 @@ def get_name(self):
Returns:
string: The name of the thermal
"""
return self.THERMAL_NAME[self.index - 1]
return self.THERMAL_NAME[self.thermal_index - 1]

def get_presence(self):
"""
Expand Down Expand Up @@ -84,7 +84,7 @@ def get_position_in_parent(self):
integer: The 1-based relative physical position in parent
device or -1 if cannot determine the position
"""
return self.index
return self.thermal_index

def is_replaceable(self):
"""
Expand All @@ -103,7 +103,7 @@ def get_temperature(self):
nearest thousandth of one degree Celsius, e.g. 30.125
"""
try:
command = ("ipmitool sdr get Sensor_Temp_{}").format(self.index)
command = ("ipmitool sdr get Sensor_Temp_{}").format(self.thermal_index)
p = os.popen(command)
content = p.read().rstrip()
info_req = re.search(r"%s\s*:(.*)" % "Sensor Reading", content)
Expand All @@ -124,7 +124,7 @@ def get_high_threshold(self):
Celsius up to nearest thousandth of one degree Celsius,
e.g. 30.125
"""
thermal_high_threshold = self.THERMAL_THRESHOLD_MAPPING[self.index]["high_threshold"]
thermal_high_threshold = self.THERMAL_THRESHOLD_MAPPING[self.thermal_index]["high_threshold"]
return thermal_high_threshold / 1.0

def get_low_threshold(self):
Expand All @@ -136,7 +136,7 @@ def get_low_threshold(self):
Celsius up to nearest thousandth of one degree Celsius,
e.g. 30.125
"""
thermal_low_threshold = self.THERMAL_THRESHOLD_MAPPING[self.index]["low_threshold"]
thermal_low_threshold = self.THERMAL_THRESHOLD_MAPPING[self.thermal_index]["low_threshold"]
return thermal_low_threshold / 1.0

def get_high_critical_threshold(self):
Expand All @@ -148,7 +148,7 @@ def get_high_critical_threshold(self):
thermal in Celsius up to nearest thousandth of one degree
Celsius, e.g. 30.125
"""
thermal_high_crit_threshold = self.THERMAL_THRESHOLD_MAPPING[self.index]["critical_threshold"]
thermal_high_crit_threshold = self.THERMAL_THRESHOLD_MAPPING[self.thermal_index]["critical_threshold"]
return thermal_high_crit_threshold / 1.0

def set_high_threshold(self, temperature):
Expand Down

0 comments on commit cf6a42d

Please sign in to comment.