Skip to content

Commit 1175143

Browse files
authoredMay 16, 2023
[Mellanox] Support UID LED in platform API (#11592)
- Why I did it As a LED indicator to help user to find switch location in the lab, UID LED is a useful LED in Mellanox switch. - How I did it I add a new member _led_uid in Mellanox/Chassis.py, and extend Mellanox/led.py to support blue color. Relevant platform-common PR sonic-net/sonic-platform-common#369 - How to verify it Add unit test cases in test.py, and do manual test including turn-on/off/show uid led. Signed-off-by: David Xia <daxia@nvidia.com>
1 parent dad61f3 commit 1175143

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed
 

‎platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class Chassis(ChassisBase):
7575
# System status LED
7676
_led = None
7777

78+
# System UID LED
79+
_led_uid = None
80+
7881
def __init__(self):
7982
super(Chassis, self).__init__()
8083

@@ -622,8 +625,10 @@ def get_component(self, index):
622625

623626
def initizalize_system_led(self):
624627
if not Chassis._led:
625-
from .led import SystemLed
628+
from .led import SystemLed, \
629+
SystemUidLed
626630
Chassis._led = SystemLed()
631+
Chassis._led_uid = SystemUidLed()
627632

628633
def set_status_led(self, color):
629634
"""
@@ -650,6 +655,31 @@ def get_status_led(self):
650655
self.initizalize_system_led()
651656
return None if not Chassis._led else Chassis._led.get_status()
652657

658+
def set_uid_led(self, color):
659+
"""
660+
Sets the state of the system UID LED
661+
662+
Args:
663+
color: A string representing the color with which to set the
664+
system UID LED
665+
666+
Returns:
667+
bool: True if system LED state is set successfully, False if not
668+
"""
669+
self.initizalize_system_led()
670+
return False if not Chassis._led_uid else Chassis._led_uid.set_status(color)
671+
672+
def get_uid_led(self):
673+
"""
674+
Gets the state of the system UID LED
675+
676+
Returns:
677+
A string, one of the valid LED color strings which could be vendor
678+
specified.
679+
"""
680+
self.initizalize_system_led()
681+
return None if not Chassis._led_uid else Chassis._led_uid.get_status()
682+
653683
def get_watchdog(self):
654684
"""
655685
Retrieves hardware watchdog device on this chassis

‎platform/mellanox/mlnx-platform-api/sonic_platform/led.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ class Led(object):
2828
STATUS_LED_COLOR_GREEN = 'green'
2929
STATUS_LED_COLOR_RED = 'red'
3030
STATUS_LED_COLOR_ORANGE = 'orange'
31+
STATUS_LED_COLOR_BLUE = 'blue'
3132
STATUS_LED_COLOR_OFF = 'off'
3233
STATUS_LED_COLOR_GREEN_BLINK = 'green_blink'
3334
STATUS_LED_COLOR_RED_BLINK = 'red_blink'
3435
STATUS_LED_COLOR_ORANGE_BLINK = 'orange_blink'
36+
STATUS_LED_COLOR_BLUE_BLINK = 'blue_blink'
3537

3638
LED_ON = '255'
3739
LED_OFF = '0'
@@ -47,7 +49,8 @@ class Led(object):
4749
'red': 'red',
4850
'amber': 'red',
4951
'orange': 'red',
50-
'green': 'green'
52+
'green': 'green',
53+
'blue': 'blue'
5154
}
5255

5356
LED_PATH = "/var/run/hw-management/led/"
@@ -273,6 +276,12 @@ def __init__(self):
273276
self._led_id = 'status'
274277

275278

279+
class SystemUidLed(Led):
280+
def __init__(self):
281+
super().__init__()
282+
self._led_id = 'uid'
283+
284+
276285
class SharedLed(object):
277286
# for shared LED, blink is not supported for now. Currently, only PSU and fan LED
278287
# might be shared LED, and there is no requirement to set PSU/fan LED to blink status.

‎platform/mellanox/mlnx-platform-api/tests/test_led.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def test_chassis_led(self):
4444
assert physical_led is not None
4545
self._verify_non_shared_led(physical_led, chassis)
4646

47+
def test_uid_led(self):
48+
chassis = Chassis()
49+
assert chassis.set_uid_led('blue') is False
50+
physical_led = chassis._led_uid
51+
assert physical_led is not None
52+
self._verify_uid_led(physical_led, chassis)
53+
4754
def _verify_non_shared_led(self, physical_led, obj):
4855
mock_file_content = self._mock_led_file_content(physical_led)
4956

@@ -84,18 +91,39 @@ def mock_write_file(file_path, content, **kwargs):
8491
mock_file_content[physical_led.get_led_delay_off_path('green')] = Led.LED_OFF
8592
mock_file_content[physical_led.get_led_delay_on_path('green')] = Led.LED_OFF
8693

94+
def _verify_uid_led(self, physical_led, obj):
95+
mock_file_content = self._mock_led_file_content(physical_led)
96+
97+
def mock_read_str_from_file(file_path, **kwargs):
98+
return mock_file_content[file_path]
99+
100+
def mock_write_file(file_path, content, **kwargs):
101+
mock_file_content[file_path] = content
102+
103+
utils.read_str_from_file = mock_read_str_from_file
104+
utils.write_file = mock_write_file
105+
106+
assert obj.get_uid_led() == Led.STATUS_LED_COLOR_GREEN
107+
mock_file_content[physical_led.get_led_path('green')] = Led.LED_OFF
108+
assert obj.set_uid_led(Led.STATUS_LED_COLOR_BLUE) is True
109+
assert obj.get_uid_led() == Led.STATUS_LED_COLOR_BLUE
110+
mock_file_content[physical_led.get_led_path('blue')] = Led.LED_OFF
111+
87112
def _mock_led_file_content(self, led):
88113
return {
89114
led.get_led_path('green'): Led.LED_ON,
90115
led.get_led_path('red'): Led.LED_OFF,
91116
led.get_led_path('orange'): Led.LED_OFF,
92-
led.get_led_cap_path(): 'none green green_blink red red_blink orange',
117+
led.get_led_path('blue'): Led.LED_OFF,
118+
led.get_led_cap_path(): 'none green green_blink red red_blink orange blue',
93119
led.get_led_delay_off_path('green'): Led.LED_OFF,
94120
led.get_led_delay_on_path('green'): Led.LED_OFF,
95121
led.get_led_delay_off_path('red'): Led.LED_OFF,
96122
led.get_led_delay_on_path('red'): Led.LED_OFF,
97123
led.get_led_delay_off_path('orange'): Led.LED_OFF,
98124
led.get_led_delay_on_path('orange'): Led.LED_OFF,
125+
led.get_led_delay_off_path('blue'): Led.LED_OFF,
126+
led.get_led_delay_on_path('blue'): Led.LED_OFF,
99127
}
100128

101129
@mock.patch('sonic_platform.led.Led._wait_files_ready', mock.MagicMock(return_value=True))

0 commit comments

Comments
 (0)