Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ def get_port_or_cage_type(self, index):
# System LED methods
##############################################

def initizalize_system_led(self):
"""
Initialize the system status LED.

Returns:
bool: True if the system LED was initialized successfully.
"""
if device_info.is_switch_bmc():
# BMC platforms have no controllable system LED, nothing to initialize.
return True
raise NotImplementedError

def set_status_led(self, color):
"""
Sets the state of the system LED
Expand All @@ -889,6 +901,9 @@ def set_status_led(self, color):
Returns:
bool: True if system LED state is set successfully, False if not
"""
if device_info.is_switch_bmc():
# BMC platforms have no controllable system LED.
return False
raise NotImplementedError

def get_status_led(self):
Expand All @@ -899,6 +914,9 @@ def get_status_led(self):
A string, one of the valid LED color strings which could be vendor
specified.
"""
if device_info.is_switch_bmc():
# BMC platforms have no controllable system LED.
return "N/A"
raise NotImplementedError

##############################################
Expand Down
31 changes: 31 additions & 0 deletions tests/chassis_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@ def test_chassis_base(self):

assert exception_raised

@mock.patch('sonic_py_common.device_info.is_switch_bmc', return_value=True)
def test_system_led_bmc(self, _mock_is_switch_bmc):
# BMC platforms have no controllable system LED, so the base class
# provides no-op defaults instead of raising NotImplementedError.
chassis = ChassisBase()
assert(chassis.initizalize_system_led() == True)
assert(chassis.set_status_led("green") == False)
assert(chassis.get_status_led() == "N/A")

@mock.patch('sonic_py_common.device_info.is_switch_bmc', return_value=False)
def test_system_led_non_bmc(self, _mock_is_switch_bmc):
# Non-BMC platforms are expected to implement these themselves.
chassis = ChassisBase()
not_implemented_methods = [
[chassis.initizalize_system_led, [], {}],
[chassis.set_status_led, ["COLOR"], {}],
[chassis.get_status_led, [], {}],
]

for method in not_implemented_methods:
exception_raised = False
try:
func = method[0]
args = method[1]
kwargs = method[2]
func(*args, **kwargs)
except NotImplementedError:
exception_raised = True

assert exception_raised

def test_smartswitch(self):
chassis = ChassisBase()
assert(chassis.is_smartswitch() == False)
Expand Down
Loading