Skip to content

Commit

Permalink
Add set_power api support to xcvr api (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnoopKamath authored and mssonicbld committed Dec 20, 2024
1 parent 000f89b commit 87a182e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sonic_platform_base/sfp_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sonic_platform_base/sonic_xcvr/sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions tests/sfputilhelper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions tests/sonic_xcvr/test_sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 87a182e

Please sign in to comment.