Skip to content

Commit

Permalink
Update fan.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Yagami-Jiang committed Jul 25, 2023
1 parent 2b383cd commit 7fae9ab
Showing 1 changed file with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#!/usr/bin/env python
# @Company :Celestica
# @Time : 2023/5/26 16:36
# @Time : 2023/7/21 16:36
# @Mail : yajiang@celestica.com
# @Author : jiang tao
try:
from sonic_platform_pddf_base.pddf_fan import PddfFan
from . import helper
from . import bmc_present_config
import re
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

BMC_EXIST = bmc_present_config.get_bmc_status()
Fan_Direction_Cmd = "0x3a 0x62 {}"
Set_Pwm_Cmd = "0x3a 0x26 0x02 {} {}"
Disable_Fcs_mode = "0x3a 0x26 0x01 0x00"
Led_Manual_Control = "0x3a 0x42 0x02 0x00"
Set_Led_Color = "0x3a 0x39 0x02 {} {}"


class Fan(PddfFan):
"""PDDF Platform-Specific Fan class"""
Expand Down Expand Up @@ -38,6 +46,16 @@ def get_direction(self):
return 'N/A'
return super().get_direction()

def get_speed_tolerance(self):
"""
Retrieves the speed tolerance of the fan
Returns:
An integer, the percentage of variance from target speed which is
considered tolerable
"""
return 15 if "PSU" in self.get_name() else 25

def get_speed(self):
"""
Obtain the fan speed ratio (rpm/max rpm) according to the fan maximum rpm in the pd-plugin.json file
Expand All @@ -51,14 +69,25 @@ def get_speed(self):
max_psu_fan_rpm = eval(self.plugin_data['PSU']['PSU_FAN_MAX_SPEED'])
psu_speed_percentage = round(speed_rpm / max_psu_fan_rpm * 100)
return speed_rpm if psu_speed_percentage > 100 else psu_speed_percentage
# if use 'get_direction' to get the fan direction, it will make python maximum recursion depth exceeded.
idx = (self.fantray_index - 1) * self.platform['num_fans_pertray'] + self.fan_index
attr = "fan" + str(idx) + "_direction"
output = self.pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return 0
val = output['status'].rstrip()
if BMC_EXIST:
speed_rpm = speed_rpm * 150
# if use 'get_direction' to get the fan direction, it will make python maximum recursion depth exceeded.
fan_index = int(re.findall(r"Fantray(\d+)_\d+", fan_name)[0])
direction_cmd = Fan_Direction_Cmd.format(fan_index - 1)
status, direction = self.helper.ipmi_raw(direction_cmd)
if not status:
return 0
direction = str(int(direction, 16))

else:
# if use 'get_direction' to get the fan direction, it will make python maximum recursion depth exceeded.
idx = (self.fantray_index - 1) * self.platform['num_fans_pertray'] + self.fan_index
attr = "fan" + str(idx) + "_direction"
output = self.pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return 0
direction = output['status'].rstrip()
f_r_fan = "Front" if fan_name.endswith("1") else "Rear"
max_fan_rpm = eval(self.plugin_data['FAN']['FAN_MAX_RPM_SPEED'][val][f_r_fan])
max_fan_rpm = eval(self.plugin_data['FAN']['FAN_MAX_RPM_SPEED'][direction][f_r_fan])
speed_percentage = round(speed_rpm / max_fan_rpm * 100)
return speed_rpm if speed_percentage > 100 else speed_percentage

0 comments on commit 7fae9ab

Please sign in to comment.