Skip to content

Commit

Permalink
also update host_lane_count and media_lane_count
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWangSmci committed Jun 27, 2023
1 parent b64604c commit 71348ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
42 changes: 32 additions & 10 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ def get_host_lane_assignment_option_side_effect(app):
def test_CmisManagerTask_post_port_active_apsel_to_db(self):
mock_xcvr_api = MagicMock()
mock_xcvr_api.get_active_apsel_hostlane = MagicMock(side_effect=[
NotImplementedError,
{
'ActiveAppSelLane1': 1,
'ActiveAppSelLane2': 1,
Expand All @@ -787,43 +786,66 @@ def test_CmisManagerTask_post_port_active_apsel_to_db(self):
'ActiveAppSelLane6': 2,
'ActiveAppSelLane7': 2,
'ActiveAppSelLane8': 2
},
NotImplementedError
])
mock_xcvr_api.get_application_advertisement = MagicMock(side_effect=[
{
1: {
'media_lane_count': 4,
'host_lane_count': 8
}
},
{
2: {
'media_lane_count': 1,
'host_lane_count': 2
}
}
])

int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE)

port_mapping = PortMapping()
stop_event = threading.Event()
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=int_tbl)

# case: NotImplementedError
lport = "Ethernet0"
host_lanes_mask = 0xc
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
assert int_tbl.getKeys() == []

# case: partial lanes update
lport = "Ethernet0"
host_lanes_mask = 0xc
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
assert int_tbl.getKeys() == ["Ethernet0"]
assert dict(int_tbl.mock_dict["Ethernet0"]) == {'active_apsel_hostlane3': '1',
'active_apsel_hostlane4': '1'}
'active_apsel_hostlane4': '1',
'host_lane_count': '8',
'media_lane_count': '4'}
# case: full lanes update
lport = "Ethernet8"
host_lanes_mask = 0xff
task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8"]
assert dict(int_tbl.mock_dict["Ethernet0"]) == {'active_apsel_hostlane3': '1',
'active_apsel_hostlane4': '1'}
'active_apsel_hostlane4': '1',
'host_lane_count': '8',
'media_lane_count': '4'}
assert dict(int_tbl.mock_dict["Ethernet8"]) == {'active_apsel_hostlane1': '2',
'active_apsel_hostlane2': '2',
'active_apsel_hostlane3': '2',
'active_apsel_hostlane4': '2',
'active_apsel_hostlane5': '2',
'active_apsel_hostlane6': '2',
'active_apsel_hostlane7': '2',
'active_apsel_hostlane8': '2'}
'active_apsel_hostlane8': '2',
'host_lane_count': '2',
'media_lane_count': '1'}

# case: NotImplementedError
int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE) # a new empty table
lport = "Ethernet0"
host_lanes_mask = 0xf
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
assert int_tbl.getKeys() == []

@patch('xcvrd.xcvrd.platform_chassis')
@patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event', MagicMock(return_value=(None, None)))
Expand Down
9 changes: 9 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ def configure_laser_frequency(self, api, lport, freq, grid=75):
def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
try:
act_apsel = api.get_active_apsel_hostlane()
appl_advt = api.get_application_advertisement()
except NotImplementedError:
helper_logger.log_error("Required feature is not implemented")
return
Expand All @@ -1350,6 +1351,14 @@ def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
str(act_apsel_lane)))

# also update host_lane_count and media_lane_count
if len(tuple_list) > 0:
appl_advt_act = appl_advt.get(act_apsel_lane)
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('host_lane_count', str(host_lane_count)))
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('media_lane_count', str(media_lane_count)))

asic_index = self.port_mapping.get_asic_id_for_logical_port(lport)
intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index)
fvs = swsscommon.FieldValuePairs(tuple_list)
Expand Down

0 comments on commit 71348ba

Please sign in to comment.