Skip to content

Commit

Permalink
[Xcvrd] Skip to get dom/threshold/pm for flat memory (#458)
Browse files Browse the repository at this point in the history
* [Xcvrd] Skip to get dom/threshold/pm for flat memory

Signed-off-by: chiourung_huang <[email protected]>

* Add test case

---------

Signed-off-by: chiourung_huang <[email protected]>
  • Loading branch information
chiourung authored Apr 22, 2024
1 parent 4533780 commit 759862e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,20 @@ def test_wrapper_get_sfp_error_description(self, mock_chassis):
mock_chassis.get_sfp = MagicMock(side_effect=NotImplementedError)
assert not _wrapper_get_sfp_error_description(1)

@patch('xcvrd.xcvrd.platform_chassis')
def test_wrapper_is_flat_memory(self, mock_chassis):
mock_api = MagicMock()
mock_api.is_flat_memory = MagicMock(return_value=True)
mock_object = MagicMock()
mock_object.get_xcvr_api = MagicMock(return_value=mock_api)
mock_chassis.get_sfp = MagicMock(return_value=mock_object)

from xcvrd.xcvrd import _wrapper_is_flat_memory
assert _wrapper_is_flat_memory(1) == True

mock_chassis.get_sfp = MagicMock(side_effect=NotImplementedError)
assert not _wrapper_is_flat_memory(1)

def test_check_port_in_range(self):
range_str = '1 - 32'
physical_port = 1
Expand Down
18 changes: 18 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ def _wrapper_get_transceiver_pm(physical_port):
pass
return {}

def _wrapper_is_flat_memory(physical_port):
if platform_chassis is not None:
try:
sfp = platform_chassis.get_sfp(physical_port)
api = sfp.get_xcvr_api()
return api.is_flat_memory()
except NotImplementedError:
pass
return None

# Soak SFP insert event until management init completes
def _wrapper_soak_sfp_insert_event(sfp_insert_events, port_dict):
Expand Down Expand Up @@ -584,6 +593,9 @@ def post_port_dom_threshold_info_to_db(logical_port_name, port_mapping, table,
if not _wrapper_get_presence(physical_port):
continue

if _wrapper_is_flat_memory(physical_port) == True:
continue

port_name = get_physical_port_name(logical_port_name,
ganged_member_num, ganged_port)
ganged_member_num += 1
Expand Down Expand Up @@ -619,6 +631,9 @@ def post_port_dom_info_to_db(logical_port_name, port_mapping, table, stop_event=
if not _wrapper_get_presence(physical_port):
continue

if _wrapper_is_flat_memory(physical_port) == True:
continue

try:
if dom_info_cache is not None and physical_port in dom_info_cache:
# If cache is enabled and dom information is in cache, just read from cache, no need read from EEPROM
Expand Down Expand Up @@ -650,6 +665,9 @@ def post_port_pm_info_to_db(logical_port_name, port_mapping, table, stop_event=t
if not _wrapper_get_presence(physical_port):
continue

if _wrapper_is_flat_memory(physical_port) == True:
continue

if pm_info_cache is not None and physical_port in pm_info_cache:
# If cache is enabled and pm info is in cache, just read from cache, no need read from EEPROM
pm_info_dict = pm_info_cache[physical_port]
Expand Down

0 comments on commit 759862e

Please sign in to comment.