Skip to content

Commit

Permalink
Add fan get_name() and get_status()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Jun 11, 2021
1 parent 0fc6abd commit 7e5b86a
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 31 deletions.
68 changes: 67 additions & 1 deletion device/accton/x86_64-accton_as7326_56x-r0/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
},
}

FAN_NAME_LIST = ["FAN-1F", "FAN-1R", "FAN-2F", "FAN-2R",
"FAN-3F", "FAN-3R", "FAN-4F", "FAN-4R",
"FAN-5F", "FAN-5R", "FAN-6F", "FAN-6R"]

class Fan(FanBase):
"""Platform-specific Fan class"""
Expand Down Expand Up @@ -87,7 +90,7 @@ def get_direction(self):
"""
if not self.is_psu_fan:
val = self.__read_txt_file(
CPLD_I2C_PATH + str(self.fan_tray_index) + "_direction")
CPLD_I2C_PATH + str(self.fan_tray_index+1) + "_direction")
direction = self.FAN_DIRECTION_EXHAUST if (
val == "0") else self.FAN_DIRECTION_INTAKE
else:
Expand Down Expand Up @@ -169,6 +172,31 @@ def set_status_led(self, color):
"""
return False #Not supported

def get_status_led(self):
"""
Gets the state of the fan status LED
Returns:
A string, one of the predefined STATUS_LED_COLOR_* strings above
"""
status=self.get_presence()
if status is None:
return self.STATUS_LED_COLOR_OFF

return {
1: self.STATUS_LED_COLOR_GREEN,
0: self.STATUS_LED_COLOR_RED
}.get(status, self.STATUS_LED_COLOR_OFF)

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
fan_name = FAN_NAME_LIST[self.fan_tray_index*2 + self.fan_index] \
if not self.is_psu_fan \
else "PSU-{} FAN-{}".format(self.psu_index+1, self.fan_index+1)

def get_presence(self):
"""
Retrieves the presence of the PSU
Expand All @@ -182,3 +210,41 @@ def get_presence(self):
val = self.__read_txt_file(
CPLD_I2C_PATH + str(self.fan_tray_index + 1) + "_present")
return int(val, 10)

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
if self.is_psu_fan:
psu_fan_path= "{}{}".format(self.psu_hwmon_path, 'psu_fan1_fault')
val=self.__read_txt_file(psu_fan_path)
if val is not None:
return int(val, 10)==0
else:
return False
else:
path = "{}{}{}".format(CPLD_I2C_PATH, self.fan_tray_index+1, '_fault')
val=self.__read_txt_file(path)
if val is not None:
return int(val, 10)==0
else:
return False

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""

return "N/A"

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return "N/A"
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __read_txt_file(self, file_path):
return fd.read().strip()
except IOError:
pass
return ""
return None

def get_voltage(self):
"""
Expand Down Expand Up @@ -232,7 +232,7 @@ def get_model(self):
string: Model/part number of device
"""
model = self.__read_txt_file(self.cpld_path + "psu_model_name")
if not model:
if model is None:
return "N/A"
return model

Expand All @@ -243,6 +243,6 @@ def get_serial(self):
string: Serial number of device
"""
serial = self.__read_txt_file(self.cpld_path + "psu_serial_number")
if not serial:
if serial is None:
return "N/A"
return serial
70 changes: 43 additions & 27 deletions device/accton/x86_64-accton_as7326_56x-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,13 @@ def get_rx_los(self):
A Boolean, True if SFP has RX LOS, False if not.
Note : RX LOS status is latched until a call to get_rx_los or a reset.
"""
rx_los = False
if self.port_num <= 48 or self.port_num >=57:
cpld_val = self.__read_txt_file(
rx_los = self.__read_txt_file(
self.cpld_path + "module_rx_los_" + str(self.port_num))
rx_los = (int(cpld_val, 10) == 1)
if int(rx_los, 10) == 1:
return [True]
else:
return [False]
#status_control_raw = self.__read_eeprom_specific_bytes(
# SFP_STATUS_CONTROL_OFFSET, SFP_STATUS_CONTROL_WIDTH)
#if status_control_raw:
Expand All @@ -911,21 +913,28 @@ def get_rx_los(self):
rx_los_list.append(rx_los_data & 0x02 != 0)
rx_los_list.append(rx_los_data & 0x04 != 0)
rx_los_list.append(rx_los_data & 0x08 != 0)
rx_los = rx_los_list[0] and rx_los_list[1] and rx_los_list[2] and rx_los_list[3]
return rx_los
return rx_los_list
else:
return [False]*4

def get_tx_fault(self):
"""
Retrieves the TX fault status of SFP
Returns:
A Boolean, True if SFP has TX fault, False if not
A list of boolean values, representing the TX fault status
of each available channel, value is True if SFP channel
has TX fault, False if not.
E.g., for a tranceiver with four channels: [False, False, True, False]
Note : TX fault status is lached until a call to get_tx_fault or a reset.
"""
tx_fault = False
if self.port_num <= 48 or self.port_num >=57:
cpld_val = self.__read_txt_file(
tx_fault = self.__read_txt_file(
self.cpld_path + "module_tx_fault_" + str(self.port_num))
tx_fault = (int(cpld_val, 10) == 1)
if int(tx_fault, 10) == 1:
return [True]
else:
return [False]
#status_control_raw = self.__read_eeprom_specific_bytes(
# SFP_STATUS_CONTROL_OFFSET, SFP_STATUS_CONTROL_WIDTH)
#if status_control_raw:
Expand All @@ -943,15 +952,19 @@ def get_tx_fault(self):
tx_fault_list.append(tx_fault_data & 0x02 != 0)
tx_fault_list.append(tx_fault_data & 0x04 != 0)
tx_fault_list.append(tx_fault_data & 0x08 != 0)
tx_fault = tx_fault_list[0] and tx_fault_list[1] and tx_fault_list[2] and tx_fault_list[3]
return tx_fault_list
else:
return [False]*4

return tx_fault

def get_tx_disable(self):
"""
Retrieves the tx_disable status of this SFP
Returns:
A Boolean, True if tx_disable is enabled, False if disabled
A list of boolean values, representing the TX disable status
of each available channel, value is True if SFP channel
is TX disabled, False if not.
E.g., for a tranceiver with four channels: [False, False, True, False]
"""
if self.port_num <= 48 or self.port_num >=57:
tx_disable = False
Expand All @@ -968,14 +981,20 @@ def get_tx_disable(self):
tx_disable_soft = (sffbase().test_bit(
data, SFP_TX_DISABLE_SOFT_BIT) != 0)
tx_disable = tx_disable_hard | tx_disable_soft
if tx_disable==0:
return [False]
else:
return [True]

else:
return [False]

return tx_disable
else:
tx_disable_list = []

sfpd_obj = sff8436Dom()
if sfpd_obj is None:
return False
return [False]

dom_control_raw = self.__read_eeprom_specific_bytes(
QSFP_CONTROL_OFFSET,
Expand All @@ -991,8 +1010,9 @@ def get_tx_disable(self):
'On' == dom_control_data['data']['TX3Disable']['value'])
tx_disable_list.append(
'On' == dom_control_data['data']['TX4Disable']['value'])

return tx_disable_list
return tx_disable_list
else:
return [False]*4

def get_tx_disable_channel(self):
"""
Expand All @@ -1003,18 +1023,14 @@ def get_tx_disable_channel(self):
As an example, a returned value of 0x5 indicates that channel 0
and channel 2 have been disabled.
"""
if self.port_num <= 48 or self.port_num >=57:
# SFP doesn't support this feature
return False
else:
tx_disable_list = self.get_tx_disable()
if tx_disable_list is None:
return 0
tx_disabled = 0
for i in range(len(tx_disable_list)):
if tx_disable_list[i]:
tx_disabled |= 1 << i
return tx_disabled
tx_disable_list = self.get_tx_disable()
if tx_disable_list is None:
return 0
tx_disabled = 0
for i in range(len(tx_disable_list)):
if tx_disable_list[i]:
tx_disabled |= 1 << i
return tx_disabled

def get_lpmode(self):
"""
Expand Down

0 comments on commit 7e5b86a

Please sign in to comment.