From 30895d1a98099935852c6aa170acd8ab16262039 Mon Sep 17 00:00:00 2001 From: Anoop Kamath <115578705+AnoopKamath@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:17:37 -0700 Subject: [PATCH] Add set_power api support to xcvr api (#484) --- sonic_platform_base/sfp_base.py | 12 ++++++++++++ sonic_platform_base/sonic_xcvr/sfp_optoe_base.py | 3 +++ tests/sfputilhelper_test.py | 10 ++++++++++ tests/sonic_xcvr/test_sfp_optoe_base.py | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/sonic_platform_base/sfp_base.py b/sonic_platform_base/sfp_base.py index 804b51ab8..bd0ae4076 100644 --- a/sonic_platform_base/sfp_base.py +++ b/sonic_platform_base/sfp_base.py @@ -385,6 +385,18 @@ def set_lpmode(self, lpmode): """ raise NotImplementedError + def set_power(self, mode): + """ + Enables or Disables the power of QSFP + + Args: + mode: A Boolean, True to enable power, False to disable it + + Returns: + A boolean, True if power is enabled or disbaled successfully, False if not + """ + raise NotImplementedError + def set_power_override(self, power_override, power_set): """ Sets SFP power level using power_override and power_set diff --git a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py index 73854f25f..a1933d1e9 100644 --- a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py +++ b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py @@ -221,6 +221,9 @@ def set_lpmode(self, lpmode): api = self.get_xcvr_api() return api.set_lpmode(lpmode) if api is not None else None + def set_power(self, mode): + raise NotImplementedError + def set_optoe_write_max(self, write_max): sys_path = self.get_eeprom_path() sys_path = sys_path.replace("eeprom", "write_max") diff --git a/tests/sfputilhelper_test.py b/tests/sfputilhelper_test.py index 3c4449239..19f1dc76c 100644 --- a/tests/sfputilhelper_test.py +++ b/tests/sfputilhelper_test.py @@ -4,6 +4,7 @@ import pytest from sonic_platform_base.sonic_sfp import sfputilhelper +from sonic_platform_base.sfp_base import SfpBase from unittest import mock PORT_LIST = [ @@ -144,3 +145,12 @@ def test_read_all_port_mappings_role(self): logical_port_list = sfputil_helper.logical assert len(logical_port_list) == len(PORT_FILTERED_LIST) + + def test_set_power(self): + sfpbase = SfpBase() + mode = 1 + try: + sfpbase.set_power(mode) + except NotImplementedError: + exception_raised = True + assert exception_raised diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py index 97c6dfb92..49b4faad5 100644 --- a/tests/sonic_xcvr/test_sfp_optoe_base.py +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -113,3 +113,12 @@ def test_set_optoe_write_timeout_oserror(self, mock_get_eeprom_path, mock_open): self.sfp_optoe_api.set_optoe_write_timeout(expected_timeout) mock_open.assert_called() + + def test_set_power(self): + mode = 1 + try: + self.sfp_optoe_api.set_power(mode) + except NotImplementedError: + exception_raised = True + assert exception_raised +