[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>
This commit is contained in:
parent
dad61f3d81
commit
1175143af1
@ -75,6 +75,9 @@ class Chassis(ChassisBase):
|
||||
# System status LED
|
||||
_led = None
|
||||
|
||||
# System UID LED
|
||||
_led_uid = None
|
||||
|
||||
def __init__(self):
|
||||
super(Chassis, self).__init__()
|
||||
|
||||
@ -622,8 +625,10 @@ class Chassis(ChassisBase):
|
||||
|
||||
def initizalize_system_led(self):
|
||||
if not Chassis._led:
|
||||
from .led import SystemLed
|
||||
from .led import SystemLed, \
|
||||
SystemUidLed
|
||||
Chassis._led = SystemLed()
|
||||
Chassis._led_uid = SystemUidLed()
|
||||
|
||||
def set_status_led(self, color):
|
||||
"""
|
||||
@ -650,6 +655,31 @@ class Chassis(ChassisBase):
|
||||
self.initizalize_system_led()
|
||||
return None if not Chassis._led else Chassis._led.get_status()
|
||||
|
||||
def set_uid_led(self, color):
|
||||
"""
|
||||
Sets the state of the system UID LED
|
||||
|
||||
Args:
|
||||
color: A string representing the color with which to set the
|
||||
system UID LED
|
||||
|
||||
Returns:
|
||||
bool: True if system LED state is set successfully, False if not
|
||||
"""
|
||||
self.initizalize_system_led()
|
||||
return False if not Chassis._led_uid else Chassis._led_uid.set_status(color)
|
||||
|
||||
def get_uid_led(self):
|
||||
"""
|
||||
Gets the state of the system UID LED
|
||||
|
||||
Returns:
|
||||
A string, one of the valid LED color strings which could be vendor
|
||||
specified.
|
||||
"""
|
||||
self.initizalize_system_led()
|
||||
return None if not Chassis._led_uid else Chassis._led_uid.get_status()
|
||||
|
||||
def get_watchdog(self):
|
||||
"""
|
||||
Retrieves hardware watchdog device on this chassis
|
||||
|
@ -28,10 +28,12 @@ class Led(object):
|
||||
STATUS_LED_COLOR_GREEN = 'green'
|
||||
STATUS_LED_COLOR_RED = 'red'
|
||||
STATUS_LED_COLOR_ORANGE = 'orange'
|
||||
STATUS_LED_COLOR_BLUE = 'blue'
|
||||
STATUS_LED_COLOR_OFF = 'off'
|
||||
STATUS_LED_COLOR_GREEN_BLINK = 'green_blink'
|
||||
STATUS_LED_COLOR_RED_BLINK = 'red_blink'
|
||||
STATUS_LED_COLOR_ORANGE_BLINK = 'orange_blink'
|
||||
STATUS_LED_COLOR_BLUE_BLINK = 'blue_blink'
|
||||
|
||||
LED_ON = '255'
|
||||
LED_OFF = '0'
|
||||
@ -47,7 +49,8 @@ class Led(object):
|
||||
'red': 'red',
|
||||
'amber': 'red',
|
||||
'orange': 'red',
|
||||
'green': 'green'
|
||||
'green': 'green',
|
||||
'blue': 'blue'
|
||||
}
|
||||
|
||||
LED_PATH = "/var/run/hw-management/led/"
|
||||
@ -273,6 +276,12 @@ class SystemLed(Led):
|
||||
self._led_id = 'status'
|
||||
|
||||
|
||||
class SystemUidLed(Led):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._led_id = 'uid'
|
||||
|
||||
|
||||
class SharedLed(object):
|
||||
# for shared LED, blink is not supported for now. Currently, only PSU and fan LED
|
||||
# might be shared LED, and there is no requirement to set PSU/fan LED to blink status.
|
||||
|
@ -44,6 +44,13 @@ class TestLed:
|
||||
assert physical_led is not None
|
||||
self._verify_non_shared_led(physical_led, chassis)
|
||||
|
||||
def test_uid_led(self):
|
||||
chassis = Chassis()
|
||||
assert chassis.set_uid_led('blue') is False
|
||||
physical_led = chassis._led_uid
|
||||
assert physical_led is not None
|
||||
self._verify_uid_led(physical_led, chassis)
|
||||
|
||||
def _verify_non_shared_led(self, physical_led, obj):
|
||||
mock_file_content = self._mock_led_file_content(physical_led)
|
||||
|
||||
@ -84,18 +91,39 @@ class TestLed:
|
||||
mock_file_content[physical_led.get_led_delay_off_path('green')] = Led.LED_OFF
|
||||
mock_file_content[physical_led.get_led_delay_on_path('green')] = Led.LED_OFF
|
||||
|
||||
def _verify_uid_led(self, physical_led, obj):
|
||||
mock_file_content = self._mock_led_file_content(physical_led)
|
||||
|
||||
def mock_read_str_from_file(file_path, **kwargs):
|
||||
return mock_file_content[file_path]
|
||||
|
||||
def mock_write_file(file_path, content, **kwargs):
|
||||
mock_file_content[file_path] = content
|
||||
|
||||
utils.read_str_from_file = mock_read_str_from_file
|
||||
utils.write_file = mock_write_file
|
||||
|
||||
assert obj.get_uid_led() == Led.STATUS_LED_COLOR_GREEN
|
||||
mock_file_content[physical_led.get_led_path('green')] = Led.LED_OFF
|
||||
assert obj.set_uid_led(Led.STATUS_LED_COLOR_BLUE) is True
|
||||
assert obj.get_uid_led() == Led.STATUS_LED_COLOR_BLUE
|
||||
mock_file_content[physical_led.get_led_path('blue')] = Led.LED_OFF
|
||||
|
||||
def _mock_led_file_content(self, led):
|
||||
return {
|
||||
led.get_led_path('green'): Led.LED_ON,
|
||||
led.get_led_path('red'): Led.LED_OFF,
|
||||
led.get_led_path('orange'): Led.LED_OFF,
|
||||
led.get_led_cap_path(): 'none green green_blink red red_blink orange',
|
||||
led.get_led_path('blue'): Led.LED_OFF,
|
||||
led.get_led_cap_path(): 'none green green_blink red red_blink orange blue',
|
||||
led.get_led_delay_off_path('green'): Led.LED_OFF,
|
||||
led.get_led_delay_on_path('green'): Led.LED_OFF,
|
||||
led.get_led_delay_off_path('red'): Led.LED_OFF,
|
||||
led.get_led_delay_on_path('red'): Led.LED_OFF,
|
||||
led.get_led_delay_off_path('orange'): Led.LED_OFF,
|
||||
led.get_led_delay_on_path('orange'): Led.LED_OFF,
|
||||
led.get_led_delay_off_path('blue'): Led.LED_OFF,
|
||||
led.get_led_delay_on_path('blue'): Led.LED_OFF,
|
||||
}
|
||||
|
||||
@mock.patch('sonic_platform.led.Led._wait_files_ready', mock.MagicMock(return_value=True))
|
||||
|
Loading…
Reference in New Issue
Block a user