Skip to content

Commit

Permalink
[pmon][xcvrd]xcvrd process show backtrace on the internal port. (soni…
Browse files Browse the repository at this point in the history
…c-net#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 <marty.lok@nokia.com>
  • Loading branch information
mlok-nokia committed Jan 7, 2022
1 parent 3e432e7 commit 07542cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/port_mapping.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 07542cb

Please sign in to comment.