Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to set_high_power_class
Browse files Browse the repository at this point in the history
longhuan-cisco committed Dec 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f6f12cd commit 480963e
Showing 3 changed files with 57 additions and 8 deletions.
17 changes: 9 additions & 8 deletions sonic_platform_base/sonic_xcvr/api/public/sff8636.py
Original file line number Diff line number Diff line change
@@ -425,11 +425,14 @@ def get_power_class(self):

return power_class

def handle_high_power_class(self):
def set_high_power_class(self, enable):
'''
This function enables high power class for the module if needed.
This function sets high power class for the module if needed.
It is only applicable for power class >= 5.
Args:
enable (bool): True to enable high power class, False to disable
Returns:
bool: True if the provision succeeds, False if it fails
'''
@@ -438,11 +441,9 @@ def handle_high_power_class(self):

if power_class < 5:
return ret
if power_class >= 8:
if not self.xcvr_eeprom.read(consts.HIGH_POWER_CLASS_ENABLE_CLASS_8):
ret = self.xcvr_eeprom.write(consts.HIGH_POWER_CLASS_ENABLE_CLASS_8, 0x1)
# Power class 5, 6, 7
if not self.xcvr_eeprom.read(consts.HIGH_POWER_CLASS_ENABLE_CLASS_5_TO_7):
ret = self.xcvr_eeprom.write(consts.HIGH_POWER_CLASS_ENABLE_CLASS_5_TO_7, 0x1)
elif power_class >= 8:
ret = self.xcvr_eeprom.write(consts.HIGH_POWER_CLASS_ENABLE_CLASS_8, enable)
else: # Power class 5, 6, 7
ret = self.xcvr_eeprom.write(consts.HIGH_POWER_CLASS_ENABLE_CLASS_5_TO_7, enable)

return ret
11 changes: 11 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/xcvr_api.py
Original file line number Diff line number Diff line change
@@ -637,3 +637,14 @@ def get_error_description(self):
"""
raise NotImplementedError

def set_high_power_class(self, enable):
"""
This function sets high power class for the module if needed.
Args:
enable (bool): True to enable high power class, False to disable
Returns:
bool: True if the provision succeeds, False if it fails
"""
raise NotImplementedError
37 changes: 37 additions & 0 deletions tests/sonic_xcvr/test_sff8636.py
Original file line number Diff line number Diff line change
@@ -156,6 +156,43 @@ def test_set_lpmode(self):
self.api.get_power_override_support.return_value = False
assert not self.api.set_lpmode(True)

def test_set_high_power_class(self):
with patch.object(self.api, 'get_power_class', new=MagicMock()) as mock_get_power_class, \
patch.object(self.api, 'xcvr_eeprom', new=MagicMock()) as mock_eeprom:

# Mock read method
mock_eeprom.read = MagicMock()
mock_get_power_class.return_value = 4

# Test low power class
mock_eeprom.read.return_value = 1
assert self.api.set_high_power_class(True)

# Test high power class 5-7
mock_get_power_class.return_value = 5
assert self.api.set_high_power_class(True)

# Test high power class 8
mock_get_power_class.return_value = 8
assert self.api.set_high_power_class(True)

# Test high power class disable
mock_get_power_class.return_value = 8
assert self.api.set_high_power_class(False)

def test_get_power_class(self):
with patch.object(self.api, 'xcvr_eeprom') as mock_eeprom:
mock_eeprom.read = MagicMock()

mock_eeprom.read.return_value = "Power Class 1 Module (1.5W max.)"
assert self.api.get_power_class() == 1

mock_eeprom.read.return_value = "XYZ"
assert self.api.get_power_class() == -1

mock_eeprom.read.return_value = None
assert self.api.get_power_class() == -1

@pytest.mark.parametrize("mock_response, expected",[
(
[

0 comments on commit 480963e

Please sign in to comment.