diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py index 5834ac4f49..4cf2aacce8 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py @@ -308,3 +308,35 @@ def get_lpmode_support(self): def get_power_override_support(self): return not self.is_copper() + + def set_lpmode(self, lpmode): + ''' + This function sets LPMode for the module. + + Args: + lpmode (bool): False means LPMode Off, True means LPMode On + + Returns: + bool: True if the provision succeeds, False if it fails + ''' + if not self.get_lpmode_support() or not self.get_power_override_support(): + return False + + return self.set_power_override(True, lpmode) + + def get_lpmode(self): + ''' + Retrieves low power mode status + + Returns: + bool: True if module in low power else returns False. + ''' + if not self.get_lpmode_support() or not self.get_power_override_support(): + return False + + power_set = self.get_power_set() + power_override = self.get_power_override() + + # Since typically optics come up by default set to high power, in this case, + # power_override not being set, function will return high power mode. + return power_set and power_override diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py index 8f98fb4c7a..e14c07da56 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py @@ -360,3 +360,35 @@ def get_lpmode_support(self): def get_power_override_support(self): return not self.is_copper() + + def set_lpmode(self, lpmode): + ''' + This function sets LPMode for the module. + + Args: + lpmode (bool): False means LPMode Off, True means LPMode On + + Returns: + bool: True if the provision succeeds, False if it fails + ''' + if not self.get_lpmode_support() or not self.get_power_override_support(): + return False + + return self.set_power_override(True, lpmode) + + def get_lpmode(self): + ''' + Retrieves low power mode status + + Returns: + bool: True if module in low power else returns False. + ''' + if not self.get_lpmode_support() or not self.get_power_override_support(): + return False + + power_set = self.get_power_set() + power_override = self.get_power_override() + + # Since typically optics come up by default set to high power, in this case, + # power_override not being set, function will return high power mode. + return power_set and power_override diff --git a/tests/sonic_xcvr/test_sff8436.py b/tests/sonic_xcvr/test_sff8436.py index 54d07f0383..e7419e2be1 100644 --- a/tests/sonic_xcvr/test_sff8436.py +++ b/tests/sonic_xcvr/test_sff8436.py @@ -54,6 +54,8 @@ def test_api(self): self.api.get_transceiver_thresholds_support() self.api.get_lpmode_support() self.api.get_power_override_support() + self.api.set_lpmode(True) + self.api.get_lpmode() @pytest.mark.parametrize("mock_response, expected", [ (bytearray([0x0]), "Power Class 1 Module (1.5W max. Power consumption)"), @@ -104,3 +106,32 @@ def test_simulate_copper(self): assert not self.api.get_temperature_support() assert not self.api.get_voltage_support() + def test_get_lpmode(self): + self.api.get_lpmode_support = MagicMock() + self.api.get_lpmode_support.return_value = True + self.api.get_power_override_support = MagicMock() + self.api.get_power_override_support.return_value = True + self.api.get_power_set = MagicMock() + self.api.get_power_set.return_value = True + self.api.get_power_override = MagicMock() + self.api.get_power_override.return_value = True + assert self.api.get_lpmode() + self.api.get_power_set.return_value = False + self.api.get_power_override.return_value = True + assert not self.api.get_lpmode() + self.api.get_lpmode_support.return_value = False + self.api.get_power_override_support.return_value = False + assert not self.api.get_lpmode() + + def test_set_lpmode(self): + self.api.get_lpmode_support = MagicMock() + self.api.get_lpmode_support.return_value = True + self.api.get_power_override_support = MagicMock() + self.api.get_power_override_support.return_value = True + self.api.set_power_override = MagicMock() + self.api.set_power_override.return_value = True + assert self.api.set_lpmode(True) + assert self.api.set_lpmode(False) + self.api.get_lpmode_support.return_value = False + self.api.get_power_override_support.return_value = False + assert not self.api.set_lpmode(True) diff --git a/tests/sonic_xcvr/test_sff8636.py b/tests/sonic_xcvr/test_sff8636.py index 82ea1a7f2b..7c623bcfd7 100644 --- a/tests/sonic_xcvr/test_sff8636.py +++ b/tests/sonic_xcvr/test_sff8636.py @@ -54,6 +54,8 @@ def test_api(self): self.api.get_transceiver_thresholds_support() self.api.get_lpmode_support() self.api.get_power_override_support() + self.api.set_lpmode(True) + self.api.get_lpmode() @pytest.mark.parametrize("mock_response, expected", [ (bytearray([0x0]), "Power Class 1 Module (1.5W max.)"), @@ -105,3 +107,33 @@ def test_simulate_copper(self): assert not self.api.get_temperature_support() assert not self.api.get_voltage_support() + def test_get_lpmode(self): + self.api.get_lpmode_support = MagicMock() + self.api.get_lpmode_support.return_value = True + self.api.get_power_override_support = MagicMock() + self.api.get_power_override_support.return_value = True + self.api.get_power_set = MagicMock() + self.api.get_power_set.return_value = True + self.api.get_power_override = MagicMock() + self.api.get_power_override.return_value = True + assert self.api.get_lpmode() + self.api.get_power_set.return_value = False + self.api.get_power_override.return_value = True + assert not self.api.get_lpmode() + self.api.get_lpmode_support.return_value = False + self.api.get_power_override_support.return_value = False + assert not self.api.get_lpmode() + + def test_set_lpmode(self): + self.api.get_lpmode_support = MagicMock() + self.api.get_lpmode_support.return_value = True + self.api.get_power_override_support = MagicMock() + self.api.get_power_override_support.return_value = True + self.api.set_power_override = MagicMock() + self.api.set_power_override.return_value = True + assert self.api.set_lpmode(True) + assert self.api.set_lpmode(False) + self.api.get_lpmode_support.return_value = False + self.api.get_power_override_support.return_value = False + assert not self.api.set_lpmode(True) +