Skip to content
Open
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
6 changes: 3 additions & 3 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def get_host_lane_count(self, appl=None):
if appl <= 0:
return 0
appl_advt = self.get_application_advertisement()
return appl_advt[appl]['host_lane_count'] if len(appl_advt) >= appl else 0
return appl_advt[appl]['host_lane_count'] if appl in appl_advt else 0

def get_media_lane_count(self, appl=1):
'''
Expand All @@ -1154,7 +1154,7 @@ def get_media_lane_count(self, appl=1):
return 0

appl_advt = self.get_application_advertisement()
return appl_advt[appl]['media_lane_count'] if len(appl_advt) >= appl else 0
return appl_advt[appl]['media_lane_count'] if appl in appl_advt else 0

def get_media_interface_technology(self):
'''
Expand Down Expand Up @@ -1190,7 +1190,7 @@ def get_media_lane_assignment_option(self, appl=1):
return 0

appl_advt = self.get_application_advertisement()
return appl_advt[appl]['media_lane_assignment_options'] if len(appl_advt) >= appl else 0
return appl_advt[appl]['media_lane_assignment_options'] if appl in appl_advt else 0

def get_active_apsel_hostlane(self):
'''
Expand Down
30 changes: 30 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,19 @@ def test_get_media_lane_count(self, appl, expected):
result = self.api.get_media_lane_count(appl)
assert result == expected

@pytest.mark.parametrize("appl, appl_advt, expected", [
# Sparse advertisement: only a high-index App is present (lower ones
# were skipped as undecodable SFF-8024 codes), so the App must be
# looked up by key - appl_advt[9] exists and returns its count.
(9, {9: {'media_lane_count': 4}}, 4),
# appl genuinely absent from the advertisement still returns 0.
(5, {1: {'media_lane_count': 1}}, 0),
])
def test_get_media_lane_count_sparse_appl_advt(self, appl, appl_advt, expected):
self.api.is_flat_memory = MagicMock(return_value=False)
with patch.object(self.api, 'get_application_advertisement', return_value=appl_advt):
assert self.api.get_media_lane_count(appl) == expected

@pytest.mark.parametrize("mock_response, expected", [
('C-band tunable laser', 'C-band tunable laser')
])
Expand Down Expand Up @@ -1164,6 +1177,19 @@ def test_get_media_lane_assignment_option(self, appl, expected):
result = self.api.get_media_lane_assignment_option(appl)
assert result == expected

@pytest.mark.parametrize("appl, appl_advt, expected", [
# Sparse advertisement: only a high-index App is present (lower ones
# were skipped as undecodable SFF-8024 codes), so the App must be
# looked up by key - appl_advt[9] exists and returns its value.
(9, {9: {'media_lane_assignment_options': 1}}, 1),
# appl genuinely absent from the advertisement still returns 0.
(5, {1: {'media_lane_assignment_options': 1}}, 0),
])
def test_get_media_lane_assignment_option_sparse_appl_advt(self, appl, appl_advt, expected):
self.api.is_flat_memory = MagicMock(return_value=False)
with patch.object(self.api, 'get_application_advertisement', return_value=appl_advt):
assert self.api.get_media_lane_assignment_option(appl) == expected

@pytest.mark.parametrize("mock_response, expected", [
({'ActiveAppSelLane1': 1},
{'ActiveAppSelLane1': 1})
Expand Down Expand Up @@ -1194,6 +1220,10 @@ def test_get_active_apsel_hostlane(self, mock_response, expected):
(0, False, {1: {'host_lane_count': 1}}, 0),
# appl not in advertisement returns 0.
(5, False, {1: {'host_lane_count': 1}}, 0),
# Sparse advertisement: only a high-index App is present (lower
# ones were skipped as undecodable SFF-8024 codes), so the App
# must be looked up by key - appl_advt[9] returns its count.
(9, False, {9: {'host_lane_count': 8}}, 8),
]
)
def test_get_host_lane_count(self, appl, is_flat_memory, appl_advt, expected):
Expand Down
Loading