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

Update TRANSCIEVER_INFO table for ports that doesn't exist in Config DB #556

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
17 changes: 17 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,23 @@ def test_DaemonXcvrd_wait_for_port_config_done(self, mock_select, mock_sub_table
xcvrd.wait_for_port_config_done('')
assert swsscommon.Select.select.call_count == 2

def test_DaemonXcvrd_remove_ports_from_transceiver_table(self):
xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE)

mock_transceiver_info_table = MagicMock()
mock_transceiver_info_table.getKeys.return_value = ['EthernetXXX']
mock_transceiver_info_table._del = MagicMock()

xcvr_table_helper.get_intf_tbl = MagicMock(return_value=mock_transceiver_info_table)

xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER)
xcvrd.xcvr_table_helper = xcvr_table_helper

logical_ports_list = ['Ethernet0', 'Ethernet1']
xcvrd.remove_ports_from_transceiver_table(logical_ports_list)

mock_transceiver_info_table._del.assert_called_once_with('EthernetXXX')

def test_DaemonXcvrd_initialize_port_init_control_fields_in_port_table(self):
port_mapping = PortMapping()
xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER)
Expand Down
12 changes: 12 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,17 @@ def wait_for_port_config_done(self, namespace):
if key in ["PortConfigDone", "PortInitDone"]:
break

# remove ports from TRANSCEIVER_INFO table, if they don't exist in CONFIG DB
def remove_ports_from_transceiver_table(self, logical_ports_list):
for namespace in self.namespaces:
asic_id = multi_asic.get_asic_index_from_namespace(namespace)
transceiver_info_table = self.xcvr_table_helper.get_intf_tbl(asic_id)
ports_in_transceiver_only = list(set(transceiver_info_table.getKeys()) - set(logical_ports_list))

for trans_port in ports_in_transceiver_only:
transceiver_info_table._del(trans_port)
helper_logger.log_info("Port {} was removed from TRANSCEIVER_INFO table as it doesn't exist in Config DB".format(trans_port))

"""
Initialize NPU_SI_SETTINGS_SYNC_STATUS_KEY field in STATE_DB PORT_TABLE|<lport>
if not already present for a port.
Expand Down Expand Up @@ -2174,6 +2185,7 @@ def init(self):

self.log_notice("XCVRD INIT: After port config is done")
port_mapping_data = port_event_helper.get_port_mapping(self.namespaces)
self.remove_ports_from_transceiver_table(port_mapping_data.logical_port_list)

self.initialize_port_init_control_fields_in_port_table(port_mapping_data)

Expand Down
Loading