diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index db865e753..b9ee9f57f 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -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 @@ -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): @@ -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 ############################################## diff --git a/tests/chassis_base_test.py b/tests/chassis_base_test.py index 685eacd81..9303a3626 100644 --- a/tests/chassis_base_test.py +++ b/tests/chassis_base_test.py @@ -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)