Skip to content

Commit

Permalink
Enable periodic polling of TRANSCEIVER_FIRMWARE_INFO table in DomInfo…
Browse files Browse the repository at this point in the history
…UpdateTask (sonic-net#443)

* Enable periodic polling of TRANSCEIVER_FIRMWARE_INFO table in DomInfoUpdateTask

Signed-off-by: Mihir Patel <[email protected]>

* Addressed testcase failure

* Renamed dom_status to dom_polling

---------

Signed-off-by: Mihir Patel <[email protected]>
  • Loading branch information
mihirpat1 authored and yuazhe committed Jul 2, 2024
1 parent 8538e39 commit 29fe740
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
34 changes: 33 additions & 1 deletion sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,39 @@ def test_DomInfoUpdateTask_is_port_in_cmis_initialization_process(self, mock_get
lport='INVALID_PORT'
assert task.is_port_in_cmis_initialization_process(lport) == expected_result

@pytest.mark.parametrize("lport, expected_dom_polling", [
('Ethernet0', 'disabled'),
('Ethernet4', 'disabled'),
('Ethernet8', 'disabled'),
('Ethernet12', 'disabled'),
('Ethernet16', 'enabled'),
('Ethernet20', 'enabled')
])
def test_DomInfoUpdateTask_get_dom_polling_from_config_db(self, lport, expected_dom_polling):
# Define the mock_get function inside the test function
def mock_get(key):
if key in ['Ethernet4', 'Ethernet8', 'Ethernet12', 'Ethernet16']:
return (True, [('dom_polling', 'enabled')])
elif key == 'Ethernet0':
return (True, [('dom_polling', 'disabled')])
else:
return None

port_mapping = PortMapping()
stop_event = threading.Event()
task = DomInfoUpdateTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
task.xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE)
task.port_mapping.handle_port_change_event(PortChangeEvent('Ethernet4', 1, 0, PortChangeEvent.PORT_ADD))
task.port_mapping.handle_port_change_event(PortChangeEvent('Ethernet12', 1, 0, PortChangeEvent.PORT_ADD))
task.port_mapping.handle_port_change_event(PortChangeEvent('Ethernet8', 1, 0, PortChangeEvent.PORT_ADD))
task.port_mapping.handle_port_change_event(PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_ADD))
task.port_mapping.handle_port_change_event(PortChangeEvent('Ethernet16', 2, 0, PortChangeEvent.PORT_ADD))
cfg_port_tbl = MagicMock()
cfg_port_tbl.get = MagicMock(side_effect=mock_get)
task.xcvr_table_helper.get_cfg_port_tbl = MagicMock(return_value=cfg_port_tbl)

assert task.get_dom_polling_from_config_db(lport) == expected_dom_polling

@patch('xcvrd.xcvrd.XcvrTableHelper', MagicMock())
@patch('xcvrd.xcvrd.delete_port_from_status_table_hw')
def test_DomInfoUpdateTask_handle_port_change_event(self, mock_del_status_tbl_hw):
Expand Down Expand Up @@ -1957,7 +1990,6 @@ def test_DomInfoUpdateTask_task_worker(self, mock_post_pm_info, mock_update_stat
task.xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE)
task.task_stopping_event.wait = MagicMock(side_effect=[False, True])
task.get_dom_polling_from_config_db = MagicMock(return_value='enabled')
task.is_port_in_cmis_terminal_state = MagicMock(return_value=False)
mock_detect_error.return_value = True
task.task_worker()
assert task.port_mapping.logical_port_list.count('Ethernet0')
Expand Down
39 changes: 39 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,45 @@ def is_port_dom_monitoring_disabled(self, logical_port_name):
return self.get_dom_polling_from_config_db(logical_port_name) == 'disabled' or \
self.is_port_in_cmis_initialization_process(logical_port_name)

def get_dom_polling_from_config_db(self, lport):
"""
Returns the value of dom_polling field from PORT table in CONFIG_DB
For non-breakout ports, this function will get dom_polling field from PORT table of lport (subport = 0)
For breakout ports, this function will get dom_polling field from PORT table of the first subport
of lport's correpsonding breakout group (subport = 1)
Returns:
'disabled' if dom_polling is set to 'disabled', otherwise 'enabled'
"""
dom_polling = 'enabled'

pport_list = self.port_mapping.get_logical_to_physical(lport)
if not pport_list:
helper_logger.log_warning("Get dom disabled: Got unknown physical port list {} for lport {}".format(pport_list, lport))
return dom_polling
pport = pport_list[0]

logical_port_list = self.port_mapping.get_physical_to_logical(pport)
if logical_port_list is None:
helper_logger.log_warning("Get dom disabled: Got unknown FP port index {}".format(pport))
return dom_polling

# Sort the logical port list to make sure we always get the first subport
logical_port_list = natsorted(logical_port_list, key=lambda y: y.lower())
first_logical_port = logical_port_list[0]

asic_index = self.port_mapping.get_asic_id_for_logical_port(first_logical_port)
port_tbl = self.xcvr_table_helper.get_cfg_port_tbl(asic_index)

found, port_info = port_tbl.get(first_logical_port)
if found and 'dom_polling' in dict(port_info):
dom_polling = dict(port_info)['dom_polling']

return dom_polling

def is_port_dom_monitoring_disabled(self, logical_port_name):
return self.get_dom_polling_from_config_db(logical_port_name) == 'disabled'

def task_worker(self):
self.xcvr_table_helper = XcvrTableHelper(self.namespaces)
helper_logger.log_info("Start DOM monitoring loop")
Expand Down

0 comments on commit 29fe740

Please sign in to comment.