Skip to content

Commit

Permalink
Create TRANSCEIVER_DOM_THRESHOLD table in state DB (sonic-net#320)
Browse files Browse the repository at this point in the history
* Create TRANSCEIVER_DOM_THRESHOLD table in state DB

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

* Removed debug statement

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

* Fixed test failure

Signed-off-by: Mihir Patel <patelmi@microsoft.com>

Signed-off-by: Mihir Patel <patelmi@microsoft.com>
  • Loading branch information
mihirpat1 authored Dec 6, 2022
1 parent 0573416 commit adcd69b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 58 deletions.
30 changes: 25 additions & 5 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,25 @@ def test_post_port_dom_info_to_db(self, mock_get_sfp_type):
mock_get_sfp_type.return_value = 'QSFP_DD'
post_port_dom_info_to_db(logical_port_name, port_mapping, dom_tbl, stop_event)

def test_post_port_dom_threshold_info_to_db(self, mock_get_sfp_type):
logical_port_name = "Ethernet0"
port_mapping = PortMapping()
stop_event = threading.Event()
dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE)
post_port_dom_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event)
mock_get_sfp_type.return_value = 'QSFP_DD'
post_port_dom_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event)

@patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
def test_del_port_sfp_dom_info_from_db(self):
logical_port_name = "Ethernet0"
port_mapping = PortMapping()
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE)
init_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE)
del_port_sfp_dom_info_from_db(logical_port_name, port_mapping, init_tbl, dom_tbl)
del_port_sfp_dom_info_from_db(logical_port_name, port_mapping, init_tbl, dom_threshold_tbl)

@patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
Expand Down Expand Up @@ -115,8 +126,8 @@ def test_post_port_dom_threshold_info_to_db(self):
logical_port_name = "Ethernet0"
port_mapping = PortMapping()
stop_event = threading.Event()
dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE)
post_port_dom_threshold_info_to_db(logical_port_name, port_mapping, dom_tbl, stop_event)
dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE)
post_port_dom_threshold_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event)

@patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True))
Expand Down Expand Up @@ -709,6 +720,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
mock_table_helper.get_status_tbl = MagicMock(return_value=mock_table)
mock_table_helper.get_int_tbl = MagicMock(return_value=mock_table)
mock_table_helper.get_dom_tbl = MagicMock(return_value=mock_table)
mock_table_helper.get_dom_threshold_tbl = MagicMock(return_value=mock_table)
stopping_event = multiprocessing.Event()
port_mapping = PortMapping()
retry_eeprom_set = set()
Expand Down Expand Up @@ -762,6 +774,7 @@ def test_SfpStateUpdateTask_retry_eeprom_reading(self, mock_post_sfp_info):
task.xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE)
task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=mock_table)
task.xcvr_table_helper.get_dom_tbl = MagicMock(return_value=mock_table)
task.xcvr_table_helper.get_dom_threshold_tbl = MagicMock(return_value=mock_table)
task.xcvr_table_helper.get_app_port_tbl = MagicMock(return_value=mock_table)
task.retry_eeprom_reading()
assert mock_post_sfp_info.call_count == 0
Expand Down Expand Up @@ -888,7 +901,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
# Test state machine: handle SFP remove event
task.task_worker(stop_event, sfp_error_event)
assert mock_updata_status.call_count == 1
assert mock_del_dom.call_count == 1
assert mock_del_dom.call_count == 2

stop_event.is_set = MagicMock(side_effect=[False, True])
error = int(SFP_STATUS_INSERTED) | SfpBase.SFP_ERROR_BIT_BLOCKING | SfpBase.SFP_ERROR_BIT_POWER_BUDGET_EXCEEDED
Expand All @@ -898,7 +911,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
# Test state machine: handle SFP error event
task.task_worker(stop_event, sfp_error_event)
assert mock_updata_status.call_count == 1
assert mock_del_dom.call_count == 1
assert mock_del_dom.call_count == 2

@patch('xcvrd.xcvrd.XcvrTableHelper')
@patch('xcvrd.xcvrd._wrapper_get_presence')
Expand All @@ -920,9 +933,13 @@ class MockTable:
dom_tbl = MockTable()
dom_tbl.get = MagicMock(return_value=(True, (('key3', 'value3'),)))
dom_tbl.set = MagicMock()
dom_threshold_tbl = MockTable()
dom_threshold_tbl.get = MagicMock(return_value=(True, (('key4', 'value4'),)))
dom_threshold_tbl.set = MagicMock()
mock_table_helper.get_status_tbl = MagicMock(return_value=status_tbl)
mock_table_helper.get_intf_tbl = MagicMock(return_value=int_tbl)
mock_table_helper.get_dom_tbl = MagicMock(return_value=dom_tbl)
mock_table_helper.get_dom_threshold_tbl = MagicMock(return_value=dom_threshold_tbl)

port_mapping = PortMapping()
retry_eeprom_set = set()
Expand All @@ -931,6 +948,7 @@ class MockTable:
task.xcvr_table_helper.get_status_tbl = mock_table_helper.get_status_tbl
task.xcvr_table_helper.get_intf_tbl = mock_table_helper.get_intf_tbl
task.xcvr_table_helper.get_dom_tbl = mock_table_helper.get_dom_tbl
task.xcvr_table_helper.get_dom_threshold_tbl = mock_table_helper.get_dom_threshold_tbl
port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_ADD)
task.port_mapping.handle_port_change_event(port_change_event)
# SFP information is in the DB, copy the SFP information for the newly added logical port
Expand All @@ -941,6 +959,8 @@ class MockTable:
int_tbl.set.assert_called_with('Ethernet0', (('key2', 'value2'),))
dom_tbl.get.assert_called_with('Ethernet0')
dom_tbl.set.assert_called_with('Ethernet0', (('key3', 'value3'),))
dom_threshold_tbl.get.assert_called_with('Ethernet0')
dom_threshold_tbl.set.assert_called_with('Ethernet0', (('key4', 'value4'),))

status_tbl.get.return_value = (False, ())
mock_get_presence.return_value = True
Expand Down Expand Up @@ -969,7 +989,7 @@ class MockTable:
assert mock_post_dom_info.call_count == 1
mock_post_dom_info.assert_called_with('Ethernet0', task.port_mapping, dom_tbl)
assert mock_post_dom_th.call_count == 1
mock_post_dom_th.assert_called_with('Ethernet0', task.port_mapping, dom_tbl)
mock_post_dom_th.assert_called_with('Ethernet0', task.port_mapping, dom_threshold_tbl)
assert mock_update_media_setting.call_count == 1
assert 'Ethernet0' not in task.retry_eeprom_set

Expand Down
Loading

0 comments on commit adcd69b

Please sign in to comment.