Skip to content

Commit d3f2da8

Browse files
authored
[pddf]: Adding support for fan_drawer class in PDDF common platform APIs (#10213)
Why I did it fan_drawer support was missing in PDDF common platform APIs. This resulted in 'thermalctld' not working and 'show platform fan' and 'show platfomr temperature' commands not working. _thermal_list array inside PSU class was not initialized. Made changes to attach the PSU related thermal sensors in the PSU instance. How I did it Added a common class pddf_fan_drawer.py. This class uses the PDDF JSON to fetch the platform specific data. A platform which uses PDDF would follow the below hierarchy. fan_drawer_base.py ---> pddf_fan_drawer.py ---> fan_drawer.py How to verify it Run the 'show platform fan' and 'show platform temperature' commands and check the o/p. o/p on AS7326: root@sonic:/home/admin# show platform fan s Drawer LED FAN Speed Direction Presence Status Timestamp -------- ----- ---------- ------- ----------- ---------- -------- ----------------- Fantray1 green Fantray1_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray1 green Fantray1_2 38% EXHAUST Present OK 20220311 04:15:03 Fantray2 green Fantray2_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray2 green Fantray2_2 38% EXHAUST Present OK 20220311 04:15:03 Fantray3 green Fantray3_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray3 green Fantray3_2 38% EXHAUST Present OK 20220311 04:15:03 Fantray4 green Fantray4_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray4 green Fantray4_2 38% EXHAUST Present OK 20220311 04:15:03 Fantray5 green Fantray5_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray5 green Fantray5_2 38% EXHAUST Present OK 20220311 04:15:03 Fantray6 green Fantray6_1 38% EXHAUST Present OK 20220311 04:15:03 Fantray6 green Fantray6_2 38% EXHAUST Present OK 20220311 04:15:03 N/A off PSU1_FAN1 0% Present Not OK 20220311 04:15:05 N/A green PSU2_FAN1 34% EXHAUST Present OK 20220311 04:15:05 hroot@sonic:/home/admin# show platform temperature Sensor Temperature High TH Low TH Crit High TH Crit Low TH Warning Timestamp ---------- ------------- --------- -------- -------------- ------------- --------- ----------------- PSU1_TEMP1 0 N/A N/A N/A N/A False 20220311 04:15:05 PSU2_TEMP1 37 N/A N/A N/A N/A False 20220311 04:15:05 TEMP1 37 80.0 N/A N/A N/A False 20220311 04:15:05 TEMP2 27 80.0 N/A N/A N/A False 20220311 04:15:05 TEMP3 28.5 80.0 N/A N/A N/A False 20220311 04:15:05 TEMP4 30.5 80.0 N/A N/A N/A False 20220311 04:15:05 root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# o/p on AS7726: root@as7726-32x-2:~# show platform fan Drawer LED FAN Speed Direction Presence Status Timestamp -------- ----- ---------- ------- ----------- ---------- -------- ----------------- Fantray1 green Fantray1_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray1 green Fantray1_2 38% EXHAUST Present OK 20220311 08:13:04 Fantray2 green Fantray2_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray2 green Fantray2_2 38% EXHAUST Present OK 20220311 08:13:04 Fantray3 green Fantray3_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray3 green Fantray3_2 38% EXHAUST Present OK 20220311 08:13:04 Fantray4 green Fantray4_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray4 green Fantray4_2 38% EXHAUST Present OK 20220311 08:13:04 Fantray5 green Fantray5_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray5 green Fantray5_2 38% EXHAUST Present OK 20220311 08:13:04 Fantray6 green Fantray6_1 38% EXHAUST Present OK 20220311 08:13:04 Fantray6 green Fantray6_2 38% EXHAUST Present OK 20220311 08:13:04 N/A green PSU1_FAN1 23% EXHAUST Present OK 20220311 08:13:04 N/A green PSU2_FAN1 22% EXHAUST Present OK 20220311 08:13:04 root@as7726-32x-2:~# show platform temp Sensor Temperature High TH Low TH Crit High TH Crit Low TH Warning Timestamp ---------- ------------- --------- -------- -------------- ------------- --------- ----------------- PSU1_TEMP1 28 N/A N/A N/A N/A False 20220311 08:13:04 PSU2_TEMP1 25 N/A N/A N/A N/A False 20220311 08:13:04 TEMP1 23.5 80.0 N/A N/A N/A False 20220311 08:13:04 TEMP2 27 80.0 N/A N/A N/A False 20220311 08:13:04 TEMP3 24 80.0 N/A N/A N/A False 20220311 08:13:04 TEMP4 27 80.0 N/A N/A N/A False 20220311 08:13:04 TEMP5 24 80.0 N/A N/A N/A False 20220311 08:13:04
1 parent ad62000 commit d3f2da8

File tree

5 files changed

+248
-76
lines changed

5 files changed

+248
-76
lines changed

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_chassis.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sonic_platform_base.chassis_base import ChassisBase
1111
from sonic_platform.sfp import Sfp
1212
from sonic_platform.psu import Psu
13-
from sonic_platform.fan import Fan
13+
from sonic_platform.fan_drawer import FanDrawer
1414
from sonic_platform.thermal import Thermal
1515
from sonic_platform.eeprom import Eeprom
1616
except ImportError as e:
@@ -52,9 +52,9 @@ def __init__(self, pddf_data=None, pddf_plugin_data=None):
5252

5353
# FANs
5454
for i in range(self.platform_inventory['num_fantrays']):
55-
for j in range(self.platform_inventory['num_fans_pertray']):
56-
fan = Fan(i, j, self.pddf_obj, self.plugin_data)
57-
self._fan_list.append(fan)
55+
fandrawer = FanDrawer(i, self.pddf_obj, self.plugin_data)
56+
self._fan_drawer_list.append(fandrawer)
57+
self._fan_list.extend(fandrawer._fan_list)
5858

5959
# PSUs
6060
for i in range(self.platform_inventory['num_psus']):

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_fan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get_speed(self):
153153
speed = int(output['status'])
154154

155155
max_speed = int(self.plugin_data['PSU']['PSU_FAN_MAX_SPEED'])
156-
speed_percentage = (speed*100)/max_speed
156+
speed_percentage = round((speed*100)/max_speed)
157157
return speed_percentage
158158
else:
159159
# TODO This calculation should change based on MAX FAN SPEED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#############################################################################
2+
# PDDF
3+
#
4+
# PDDF fan_drawer base class inherited from the common base class fan_drawer.py
5+
#
6+
#############################################################################
7+
8+
try:
9+
from sonic_platform_base.fan_drawer_base import FanDrawerBase
10+
from sonic_platform.fan import Fan
11+
except ImportError as e:
12+
raise ImportError(str(e) + "- required module not found")
13+
14+
15+
class PddfFanDrawer(FanDrawerBase):
16+
"""PDDF generic Fan Drawer class"""
17+
18+
pddf_obj = {}
19+
plugin_data = {}
20+
21+
def __init__(self, tray_idx, pddf_data=None, pddf_plugin_data=None):
22+
FanDrawerBase.__init__(self)
23+
if not pddf_data or not pddf_plugin_data:
24+
raise ValueError('PDDF JSON data error')
25+
26+
self.pddf_obj = pddf_data
27+
self.plugin_data = pddf_plugin_data
28+
self.platform = self.pddf_obj.get_platform()
29+
30+
if tray_idx < 0 or tray_idx >= self.platform['num_fantrays']:
31+
print("Invalid fantray index %d\n" % tray_idx)
32+
return
33+
34+
self.fantray_index = tray_idx+1
35+
for j in range(self.platform['num_fans_pertray']):
36+
# Fan index is 0-based for the init call
37+
self._fan_list.append(Fan(tray_idx, j, self.pddf_obj, self.plugin_data))
38+
39+
def get_name(self):
40+
"""
41+
Retrieves the fan drawer name
42+
Returns: String containing fan-drawer name
43+
"""
44+
return "Fantray{0}".format(self.fantray_index)
45+
46+
def get_presence(self):
47+
status = False
48+
# Usually if a tray is removed, all the fans inside it are absent
49+
if self._fan_list:
50+
status = self._fan_list[0].get_presence()
51+
52+
return status
53+
54+
def get_status(self):
55+
status = False
56+
# if all the fans are working fine, then tray status should be okay
57+
if self._fan_list:
58+
status = all(fan.get_status() == True for fan in self._fan_list)
59+
60+
return status
61+
62+
def is_replaceable(self):
63+
"""
64+
Indicate whether this device is replaceable.
65+
Returns:
66+
bool: True if it is replaceable.
67+
"""
68+
# Usually Fantrays are replaceable
69+
return True
70+
71+
def get_position_in_parent(self):
72+
"""
73+
Retrieves 1-based relative physical position in parent device.
74+
Returns:
75+
integer: The 1-based relative physical position in parent
76+
device or -1 if cannot determine the position
77+
"""
78+
return self.fantray_index
79+
80+
def get_status_led(self):
81+
led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED"
82+
83+
if led_device_name not in self.pddf_obj.data.keys():
84+
# Implement a generic status_led color scheme
85+
if self.get_status():
86+
return self.STATUS_LED_COLOR_GREEN
87+
else:
88+
return self.STATUS_LED_COLOR_OFF
89+
90+
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
91+
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
92+
self.pddf_obj.create_attr('index', str(self.fantray_index-1), self.pddf_obj.get_led_path())
93+
self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path())
94+
color = self.pddf_obj.get_led_color()
95+
return (color)
96+
97+
def set_status_led(self, color):
98+
result = False
99+
led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED"
100+
result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color)
101+
if result == False:
102+
print(msg)
103+
return (False)
104+
105+
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
106+
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
107+
self.pddf_obj.create_attr('index', str(self.fantray_index-1), self.pddf_obj.get_led_path())
108+
self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path())
109+
self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path())
110+
return (True)

platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
try:
2121
from sonic_platform_base.psu_base import PsuBase
2222
from sonic_platform.fan import Fan
23+
from sonic_platform.thermal import Thermal
2324
except ImportError as e:
2425
raise ImportError(str(e) + "- required module not found")
2526

@@ -45,6 +46,11 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
4546
psu_fan = Fan(0, psu_fan_idx, pddf_data, pddf_plugin_data, True, self.psu_index)
4647
self._fan_list.append(psu_fan)
4748

49+
self.num_psu_thermals = 1 # Fixing it 1 for now
50+
for psu_thermal_idx in range(self.num_psu_thermals):
51+
psu_thermal = Thermal(psu_thermal_idx, pddf_data, pddf_plugin_data, True, self.psu_index)
52+
self._thermal_list.append(psu_thermal)
53+
4854
def get_num_fans(self):
4955
"""
5056
Retrieves the number of fan modules available on this PSU

0 commit comments

Comments
 (0)