Skip to content

Commit 120aa78

Browse files
authored
[pddf]: Modifying the PDDF common platform APIs as per the LED driver changes (#13474)
Why I did it LED driver changed due to introduction of FPGA support. The PDDF parser and APIs need to be updated. In turn the common platform APIs also require changes. How I did it Changed the get/set status LED APIs for PSU, fan and fan_drawer. Changed the color strings to plain color name. e.g. 'STATUS_LED_COLOR_GREEN' has been changed to 'green' Added support for LED color get operation via BMC How to verify it Verified the new changes on Accton AS7816-64X platform. root@sonic:/home/admin# root@sonic:/home/admin# show platform summary Platform: x86_64-accton_as7816_64x-r0 HwSKU: Accton-AS7816-64X ASIC: broadcom ASIC Count: 1 Serial Number: AAA1903AAEV Model Number: FP3AT7664000A Hardware Revision: N/A root@sonic:/home/admin# root@sonic:/home/admin# show ver |more SONiC Software Version: SONiC.master.0-dirty-20230111.010655 Distribution: Debian 11.6 Kernel: 5.10.0-18-2-amd64 Build commit: 3176b15ae Build date: Wed Jan 11 09:12:54 UTC 2023 Built by: fk410167@sonic-lvn-csg-006 Platform: x86_64-accton_as7816_64x-r0 HwSKU: Accton-AS7816-64X ASIC: broadcom ASIC Count: 1 Serial Number: AAA1903AAEV Model Number: FP3AT7664000A Hardware Revision: N/A Uptime: 09:24:42 up 4 days, 22:45, 1 user, load average: 1.97, 1.80, 1.51 Date: Mon 23 Jan 2023 09:24:42 Docker images: REPOSITORY TAG IMAGE ID SI ZE docker-orchagent latest 63262c7468d7 38 5MB root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# pddf_ledutil getstatusled LOC_LED off root@sonic:/home/admin# pddf_ledutil getstatusled DIAG_LED green root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# pddf_ledutil setstatusled DIAG_LED red True root@sonic:/home/admin# pddf_ledutil getstatusled DIAG_LED red root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# pddf_ledutil setstatusled DIAG_LED amber Invalid color False root@sonic:/home/admin# pddf_ledutil getstatusled DIAG_LED red root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# pddf_ledutil setstatusled DIAG_LED green True root@sonic:/home/admin# pddf_ledutil getstatusled DIAG_LED green root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# root@sonic:/home/admin# pddf_ledutil getstatusled LOC_LED off root@sonic:/home/admin# pddf_ledutil setstatusled LOC_LED amber True root@sonic:/home/admin# pddf_ledutil getstatusled LOC_LED amber root@sonic:/home/admin# pddf_ledutil setstatusled LOC_LED off True root@sonic:/home/admin# pddf_ledutil getstatusled LOC_LED off root@sonic:/home/admin#
1 parent 0abc4f0 commit 120aa78

File tree

5 files changed

+98
-129
lines changed

5 files changed

+98
-129
lines changed

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

+20-22
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,30 @@ def get_reboot_cause(self):
193193
##############################################
194194
# System LED methods
195195
##############################################
196+
# APIs used by PDDF. Use them for debugging front panel
197+
# system LED and fantray LED issues
196198
def set_system_led(self, led_device_name, color):
197-
result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color)
198-
if result == False:
199+
"""
200+
Sets the color of an LED device in PDDF
201+
Args:
202+
led_device_name: a pre-defined LED device name list used in pddf-device.json.
203+
color: A string representing the color with which to set a LED
204+
Returns:
205+
bool: True if the LED state is set successfully, False if not
206+
"""
207+
result, msg = self.pddf_obj.set_system_led_color(led_device_name, color)
208+
if not result and msg:
199209
print(msg)
200-
return (False)
201-
202-
index = self.pddf_obj.data[led_device_name]['dev_attr']['index']
203-
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
204-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
205-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
206-
self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path())
207-
self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path())
208-
return (True)
210+
return (result)
209211

210212
def get_system_led(self, led_device_name):
211-
if led_device_name not in self.pddf_obj.data.keys():
212-
status = "[FAILED] " + led_device_name + " is not configured"
213-
return (status)
214-
215-
index = self.pddf_obj.data[led_device_name]['dev_attr']['index']
216-
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
217-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
218-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
219-
self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path())
220-
color = self.pddf_obj.get_led_color()
221-
return (color)
213+
"""
214+
Gets the color of an LED device in PDDF
215+
Returns:
216+
string: color of LED or message if failed.
217+
"""
218+
result, output = self.pddf_obj.get_system_led_color(led_device_name)
219+
return (output)
222220

223221
##############################################
224222
# Other methods

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

+23-30
Original file line numberDiff line numberDiff line change
@@ -297,38 +297,31 @@ def set_speed(self, speed):
297297
return status
298298

299299
def set_status_led(self, color):
300-
index = str(self.fantray_index-1)
301-
led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED"
302-
303-
result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color)
304-
if result == False:
305-
print(msg)
306-
return (False)
307-
308-
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
309-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
310-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
311-
self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path())
312-
self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path())
313-
return (True)
300+
result = False
301+
if self.is_psu_fan:
302+
# Usually no led for psu_fan hence raise a NotImplementedError
303+
raise NotImplementedError
304+
else:
305+
# Usually there is no led for psu_fan
306+
led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED"
307+
result, msg = self.pddf_obj.set_system_led_color(led_device_name, color)
308+
return (result)
314309

315310
def get_status_led(self):
316-
index = str(self.fantray_index-1)
317-
fan_led_device = "FANTRAY{}".format(self.fantray_index) + "_LED"
318-
319-
if fan_led_device not in self.pddf_obj.data.keys():
320-
# Implement a generic status_led color scheme
321-
if self.get_status():
322-
return self.STATUS_LED_COLOR_GREEN
323-
else:
324-
return self.STATUS_LED_COLOR_OFF
325-
326-
device_name = self.pddf_obj.data[fan_led_device]['dev_info']['device_name']
327-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
328-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
329-
self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path())
330-
color = self.pddf_obj.get_led_color()
331-
return (color)
311+
if self.is_psu_fan:
312+
# Usually no led for psu_fan hence raise a NotImplementedError
313+
raise NotImplementedError
314+
else:
315+
fan_led_device = "FANTRAY{}".format(self.fantray_index) + "_LED"
316+
if (not fan_led_device in self.pddf_obj.data.keys()):
317+
# Implement a generic status_led color scheme
318+
if self.get_status():
319+
return self.STATUS_LED_COLOR_GREEN
320+
else:
321+
return self.STATUS_LED_COLOR_OFF
322+
323+
result, color = self.pddf_obj.get_system_led_color(fan_led_device)
324+
return (color)
332325

333326
def get_position_in_parent(self):
334327
"""

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

+5-19
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,19 @@ def get_position_in_parent(self):
7878
return self.fantray_index
7979

8080
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():
81+
fan_led_device = "FANTRAY{}".format(self.fantray_index) + "_LED"
82+
if (not fan_led_device in self.pddf_obj.data.keys()):
8483
# Implement a generic status_led color scheme
8584
if self.get_status():
8685
return self.STATUS_LED_COLOR_GREEN
8786
else:
8887
return self.STATUS_LED_COLOR_OFF
8988

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()
89+
result, color = self.pddf_obj.get_system_led_color(fan_led_device)
9590
return (color)
9691

9792
def set_status_led(self, color):
9893
result = False
9994
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)
95+
result, msg = self.pddf_obj.set_system_led_color(led_device_name, color)
96+
return (result)

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

+9-19
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,17 @@ def get_powergood_status(self):
250250
return self.get_status()
251251

252252
def set_status_led(self, color):
253-
index = str(self.psu_index-1)
253+
if 'psu_led_color' in self.plugin_data['PSU']:
254+
led_color_map = self.plugin_data['PSU']['psu_led_color']['colmap']
255+
if color in led_color_map:
256+
# change the color properly
257+
new_color = led_color_map[color]
258+
color = new_color
254259
led_device_name = "PSU{}".format(self.psu_index) + "_LED"
255-
256-
result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color)
257-
if result == False:
258-
print(msg)
259-
return (False)
260-
261-
device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name']
262-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
263-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
264-
self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path())
265-
self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path())
266-
return (True)
260+
result, msg = self.pddf_obj.set_system_led_color(led_device_name, color)
261+
return (result)
267262

268263
def get_status_led(self):
269-
index = str(self.psu_index-1)
270264
psu_led_device = "PSU{}_LED".format(self.psu_index)
271265
if psu_led_device not in self.pddf_obj.data.keys():
272266
# Implement a generic status_led color scheme
@@ -275,11 +269,7 @@ def get_status_led(self):
275269
else:
276270
return self.STATUS_LED_COLOR_OFF
277271

278-
device_name = self.pddf_obj.data[psu_led_device]['dev_info']['device_name']
279-
self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path())
280-
self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path())
281-
self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path())
282-
color = self.pddf_obj.get_led_color()
272+
result, color = self.pddf_obj.get_system_led_color(psu_led_device)
283273
return (color)
284274

285275
def get_temperature(self):

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

+41-39
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616

1717
dirname = os.path.dirname(os.path.realpath(__file__))
1818

19-
color_map = {
20-
"STATUS_LED_COLOR_GREEN": "green",
21-
"STATUS_LED_COLOR_RED": "red",
22-
"STATUS_LED_COLOR_AMBER": "amber",
23-
"STATUS_LED_COLOR_BLUE": "blue",
24-
"STATUS_LED_COLOR_GREEN_BLINK": "blinking green",
25-
"STATUS_LED_COLOR_RED_BLINK": "blinking red",
26-
"STATUS_LED_COLOR_AMBER_BLINK": "blinking amber",
27-
"STATUS_LED_COLOR_BLUE_BLINK": "blinking blue",
28-
"STATUS_LED_COLOR_OFF": "off"
29-
}
30-
31-
3219
class PddfApi():
3320
def __init__(self):
3421
if not os.path.exists("/usr/share/sonic/platform"):
@@ -123,10 +110,12 @@ def get_led_color(self):
123110
color = f.read().strip("\r\n")
124111
except IOError:
125112
return ("Error")
126-
127-
return (color_map[color])
113+
return color
128114

129115
def get_led_color_devtype(self, key):
116+
if 'bmc' in self.data[key]:
117+
return 'bmc'
118+
130119
attr_list = self.data[key]['i2c']['attr_list']
131120
for attr in attr_list:
132121
if 'attr_devtype' in attr:
@@ -163,8 +152,8 @@ def get_led_color_from_gpio(self, led_device_name):
163152

164153
for attr in attr_list:
165154
if int(attr['value'].strip(), 16) == value:
166-
return(color_map[attr['attr_name']])
167-
return (color_map['STATUS_LED_COLOR_OFF'])
155+
return (attr['attr_name'])
156+
return ("off")
168157

169158
def get_led_color_from_cpld(self, led_device_name):
170159
index = self.data[led_device_name]['dev_attr']['index']
@@ -174,6 +163,12 @@ def get_led_color_from_cpld(self, led_device_name):
174163
self.create_attr('dev_ops', 'get_status', self.get_led_path())
175164
return self.get_led_color()
176165

166+
def get_led_color_from_bmc(self, led_device_name):
167+
for bmc_attr in self.data[led_device_name]['bmc']['ipmitool']['attr_list']:
168+
if (self.bmc_get_cmd(bmc_attr) == str(int(bmc_attr['value'], 16))):
169+
return (bmc_attr['attr_name'])
170+
return ("off")
171+
177172
def set_led_color_from_gpio(self, led_device_name, color):
178173
attr_list = self.data[led_device_name]['i2c']['attr_list']
179174
for attr in attr_list:
@@ -196,9 +191,9 @@ def set_led_color_from_gpio(self, led_device_name, color):
196191
cmd = "echo {} > {}".format(_value, attr_path)
197192
self.runcmd(cmd)
198193
except Exception as e:
199-
print("Invalid gpio path : " + attr_path)
200-
return (False)
201-
return (True)
194+
msg = "Invalid gpio path : " + attr_path
195+
return (False, msg)
196+
return (True, "Success")
202197

203198
def set_led_color_from_cpld(self, led_device_name, color):
204199
index = self.data[led_device_name]['dev_attr']['index']
@@ -207,26 +202,42 @@ def set_led_color_from_cpld(self, led_device_name, color):
207202
self.create_attr('index', index, self.get_led_path())
208203
self.create_attr('color', color, self.get_led_cur_state_path())
209204
self.create_attr('dev_ops', 'set_status', self.get_led_path())
210-
return (True)
205+
return (True, "Success")
211206

212207
def get_system_led_color(self, led_device_name):
213208
if led_device_name not in self.data.keys():
214-
status = "[FAILED] " + led_device_name + " is not configured"
215-
return (status)
209+
msg = led_device_name + " is not configured"
210+
return (False, msg)
216211

217212
dtype = self.get_led_color_devtype(led_device_name)
218213

219214
if dtype == 'gpio':
220215
color = self.get_led_color_from_gpio(led_device_name)
221-
elif dtype == 'cpld':
216+
elif dtype == 'bmc':
217+
color = self.get_led_color_from_bmc(led_device_name)
218+
else:
219+
# This case takes care of CPLD as well as I2CFPGA
222220
color = self.get_led_color_from_cpld(led_device_name)
223-
return color
221+
222+
return (True, color)
224223

225224
def set_system_led_color(self, led_device_name, color):
226-
result, msg = self.is_supported_sysled_state(led_device_name, color)
227-
if result == False:
228-
print(msg)
229-
return (result)
225+
# Check if the device is configured
226+
if led_device_name not in self.data.keys():
227+
msg = led_device_name + " is not configured"
228+
return (False, msg)
229+
230+
# Check for the write permission
231+
if 'flag' in self.data[led_device_name]['dev_attr']:
232+
if self.data[led_device_name]['dev_attr']['flag'] == 'ro':
233+
return (False, "Set LED operation not supported or handled separately")
234+
235+
found = False
236+
for attr in self.data[led_device_name]['i2c']['attr_list']:
237+
if attr['attr_name'] == color:
238+
found = True
239+
if not found:
240+
return (False, "Invalid color")
230241

231242
dtype = self.get_led_color_devtype(led_device_name)
232243

@@ -391,7 +402,6 @@ def show_attr_fan_device(self, dev, ops):
391402
ret.append(dsysfs_path)
392403
return ret
393404

394-
# This is only valid for LM75
395405
def show_attr_temp_sensor_device(self, dev, ops):
396406
ret = []
397407
if 'i2c' not in dev.keys():
@@ -412,7 +422,7 @@ def show_attr_temp_sensor_device(self, dev, ops):
412422
real_name = attr['attr_name']
413423

414424
if 'topo_info' in dev['i2c']:
415-
path = self.show_device_sysfs(dev, ops)+"/%d-00%x/" % (int(dev['i2c']['topo_info']['parent_bus'], 0),
425+
path = self.show_device_sysfs(dev, ops)+"/%d-00%x/"%(int(dev['i2c']['topo_info']['parent_bus'], 0),
416426
int(dev['i2c']['topo_info']['dev_addr'], 0))
417427
if (os.path.exists(path)):
418428
full_path = glob.glob(path + 'hwmon/hwmon*/' + real_name)[0]
@@ -810,14 +820,6 @@ def dev_parse(self, dev, ops):
810820
if attr['device_type'] == 'SYSSTAT':
811821
return self.sysstatus_parse(dev, ops)
812822

813-
def is_supported_sysled_state(self, sysled_name, sysled_state):
814-
if sysled_name not in self.data.keys():
815-
return False, "[FAILED] " + sysled_name + " is not configured"
816-
for attr in self.data[sysled_name]['i2c']['attr_list']:
817-
if attr['attr_name'] == sysled_state:
818-
return True, "supported"
819-
return False, "[FAILED]: Invalid color"
820-
821823
def create_attr(self, key, value, path):
822824
cmd = "echo '%s' > /sys/kernel/%s/%s" % (value, path, key)
823825
self.runcmd(cmd)

0 commit comments

Comments
 (0)