Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action] [PR:484] Add set_power api support to xcvr api (#484) #525

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
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

Loading