From 07542cb2c39320ba7e76743b4d728610d3753177 Mon Sep 17 00:00:00 2001 From: "Marty Y. Lok" <76118573+mlok-nokia@users.noreply.github.com> Date: Fri, 7 Jan 2022 18:32:28 -0500 Subject: [PATCH] [pmon][xcvrd]xcvrd process show backtrace on the internal port. (#233) port_mapping class returns the port_mapping_data info incldue internal ports. Internal port doesn't have transceiver. It should not be in the list for the xcvrd. Signed-off-by: mlok --- sonic-xcvrd/tests/test_xcvrd.py | 9 +++++++-- sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 5c56730f354d..506ca694c945 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -341,8 +341,8 @@ def test_handle_port_config_change(self, mock_select, mock_sub_table): @patch('swsscommon.swsscommon.Table') def test_get_port_mapping(self, mock_swsscommon_table): mock_table = MagicMock() - mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) - mock_table.get = MagicMock(side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) + mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4', 'Ethernet-IB0']) + mock_table.get = MagicMock(side_effect=[(True, (('index', 1), )), (True, (('index', 2), )), (True, (('index', 3), ))]) mock_swsscommon_table.return_value = mock_table port_mapping = get_port_mapping() assert port_mapping.logical_port_list.count('Ethernet0') @@ -355,6 +355,11 @@ def test_get_port_mapping(self, mock_swsscommon_table): assert port_mapping.get_physical_to_logical(2) == ['Ethernet4'] assert port_mapping.get_logical_to_physical('Ethernet4') == [2] + assert port_mapping.logical_port_list.count('Ethernet-IB0') == 0 + assert port_mapping.get_asic_id_for_logical_port('Ethernet-IB0') == None + assert port_mapping.get_physical_to_logical(3) == None + assert port_mapping.get_logical_to_physical('Ethernet-IB0') == None + @patch('swsscommon.swsscommon.Select.addSelectable', MagicMock()) @patch('swsscommon.swsscommon.SubscriberStateTable') @patch('swsscommon.swsscommon.Select.select') diff --git a/sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py b/sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py index 39e55656e913..201bc33f6be6 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py @@ -1,5 +1,6 @@ from sonic_py_common import daemon_base from sonic_py_common import multi_asic +from sonic_py_common.interface import backplane_prefix, inband_prefix, recirc_prefix from swsscommon import swsscommon SELECT_TIMEOUT_MSECS = 1000 @@ -88,6 +89,11 @@ def logical_port_name_to_physical_port_list(self, port_name): else: return None +def validate_port(port): + if port.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())): + return False + return True + def subscribe_port_config_change(): sel = swsscommon.Select() asic_context = {} @@ -138,6 +144,8 @@ def handle_port_update_event(sel, asic_context, stop_event, logger, port_change_ (key, op, fvp) = port_tbl.pop() if not key: break + if not validate_port(key): + continue fvp = dict(fvp) if fvp is not None else {} if 'index' not in fvp: fvp['index'] = '-1' @@ -177,6 +185,8 @@ def read_port_config_change(asic_context, port_mapping, logger, port_change_even (key, op, fvp) = port_tbl.pop() if not key: break + if not validate_port(key): + continue if op == swsscommon.SET_COMMAND: fvp = dict(fvp) if 'index' not in fvp: @@ -218,6 +228,8 @@ def get_port_mapping(): config_db = daemon_base.db_connect("CONFIG_DB", namespace=namespace) port_table = swsscommon.Table(config_db, swsscommon.CFG_PORT_TABLE_NAME) for key in port_table.getKeys(): + if not validate_port(key): + continue _, port_config = port_table.get(key) port_config_dict = dict(port_config) port_change_event = PortChangeEvent(key, port_config_dict['index'], asic_id, PortChangeEvent.PORT_ADD)