Skip to content

Commit

Permalink
[warm/fast-reboot] Retain TRANSCEIVER_INFO/STATUS tables on deinit (s…
Browse files Browse the repository at this point in the history
…onic-net#454)

* [warmboot] Retain TRANSCEIVER_INFO/STATUS tables on deinit

Signed-off-by: Stepan Blyschak <[email protected]>

* add UT

Signed-off-by: Stepan Blyschak <[email protected]>

* Update IT

Signed-off-by: Stepan Blyschak <[email protected]>

---------

Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak authored Apr 5, 2024
1 parent 2770fd2 commit d0fd1e1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
44 changes: 44 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,13 @@ def test_get_media_val_str(self):
media_str = get_media_val_str(num_logical_ports, lane_dict, logical_idx)
assert media_str == '3,4'

class MockPortMapping:
logical_port_list = [0, 1, 2]
logical_port_name_to_physical_port_list = MagicMock()
get_asic_id_for_logical_port = MagicMock()

@patch('xcvrd.xcvrd.DaemonXcvrd.load_platform_util', MagicMock())
@patch('xcvrd.xcvrd_utilities.port_event_helper.get_port_mapping', MagicMock(return_value=MockPortMapping))
@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None)))
@patch('swsscommon.swsscommon.WarmStart', MagicMock())
@patch('xcvrd.xcvrd.DaemonXcvrd.wait_for_port_config_done', MagicMock())
Expand All @@ -2444,8 +2450,46 @@ def test_DaemonXcvrd_init_deinit_fastboot_enabled(self):
mock_run.return_value = "true"

xcvrd.init()

status_tbl = MagicMock()
xcvrd.xcvr_table_helper.get_status_tbl = MagicMock(return_value=status_tbl)
xcvrd.xcvr_table_helper.get_dom_tbl = MagicMock(return_value=MagicMock)
xcvrd.xcvr_table_helper.get_dom_threshold_tbl = MagicMock(return_value=MagicMock)
xcvrd.xcvr_table_helper.get_pm_tbl = MagicMock(return_value=MagicMock)
xcvrd.xcvr_table_helper.get_firmware_info_tbl = MagicMock(return_value=MagicMock)

xcvrd.deinit()

status_tbl.hdel.assert_not_called()

@patch('xcvrd.xcvrd.DaemonXcvrd.load_platform_util', MagicMock())
@patch('xcvrd.xcvrd_utilities.port_event_helper.get_port_mapping', MagicMock(return_value=MockPortMapping))
@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None)))
@patch('xcvrd.xcvrd.is_warm_reboot_enabled', MagicMock(return_value=False))
@patch('xcvrd.xcvrd.DaemonXcvrd.wait_for_port_config_done', MagicMock())
@patch('subprocess.check_output', MagicMock(return_value='false'))
def test_DaemonXcvrd_init_deinit_cold(self):
xcvrd.platform_chassis = MagicMock()

xcvrdaemon = DaemonXcvrd(SYSLOG_IDENTIFIER)
with patch("subprocess.check_output") as mock_run:
mock_run.return_value = "false"

xcvrdaemon.init()

status_tbl = MagicMock()
xcvrdaemon.xcvr_table_helper.get_status_tbl = MagicMock(return_value=status_tbl)
xcvrdaemon.xcvr_table_helper.get_dom_tbl = MagicMock(return_value=MagicMock)
xcvrdaemon.xcvr_table_helper.get_dom_threshold_tbl = MagicMock(return_value=MagicMock)
xcvrdaemon.xcvr_table_helper.get_pm_tbl = MagicMock(return_value=MagicMock)
xcvrdaemon.xcvr_table_helper.get_firmware_info_tbl = MagicMock(return_value=MagicMock)
xcvrdaemon.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=MagicMock)

xcvrdaemon.deinit()

status_tbl.hdel.assert_called()


def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
wait_time = 0
while wait_time <= total_wait_time:
Expand Down
25 changes: 17 additions & 8 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ def is_fast_reboot_enabled():
fastboot_enabled = subprocess.check_output('sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable', shell=True, universal_newlines=True)
return "true" in fastboot_enabled


def is_warm_reboot_enabled():
warmstart = swsscommon.WarmStart()
warmstart.initialize("xcvrd", "pmon")
warmstart.checkWarmStart("xcvrd", "pmon", False)
is_warm_start = warmstart.isWarmStart()
return is_warm_start

#
# Helper classes ===============================================================
#
Expand Down Expand Up @@ -1837,11 +1845,7 @@ def _post_port_sfp_info_and_dom_thr_to_db_once(self, port_mapping, xcvr_table_he
transceiver_dict = {}
retry_eeprom_set = set()

warmstart = swsscommon.WarmStart()
warmstart.initialize("xcvrd", "pmon")
warmstart.checkWarmStart("xcvrd", "pmon", False)
is_warm_start = warmstart.isWarmStart()

is_warm_start = is_warm_reboot_enabled()
# Post all the current interface sfp/dom threshold info to STATE_DB
logical_port_list = port_mapping.logical_port_list
for logical_port_name in logical_port_list:
Expand Down Expand Up @@ -2425,6 +2429,8 @@ def init(self):
def deinit(self):
self.log_info("Start daemon deinit...")

is_warm_fast_reboot = is_warm_reboot_enabled() or is_fast_reboot_enabled()

# Delete all the information from DB and then exit
port_mapping_data = port_event_helper.get_port_mapping(self.namespaces)
logical_port_list = port_mapping_data.logical_port_list
Expand All @@ -2435,15 +2441,18 @@ def deinit(self):
helper_logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name))
continue

intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index) if not is_warm_fast_reboot else None

del_port_sfp_dom_info_from_db(logical_port_name, port_mapping_data,
self.xcvr_table_helper.get_intf_tbl(asic_index),
intf_tbl,
self.xcvr_table_helper.get_dom_tbl(asic_index),
self.xcvr_table_helper.get_dom_threshold_tbl(asic_index),
self.xcvr_table_helper.get_pm_tbl(asic_index),
self.xcvr_table_helper.get_firmware_info_tbl(asic_index))
delete_port_from_status_table_sw(logical_port_name, self.xcvr_table_helper.get_status_tbl(asic_index))
delete_port_from_status_table_hw(logical_port_name, port_mapping_data, self.xcvr_table_helper.get_status_tbl(asic_index))

if not is_warm_fast_reboot:
delete_port_from_status_table_sw(logical_port_name, self.xcvr_table_helper.get_status_tbl(asic_index))
delete_port_from_status_table_hw(logical_port_name, port_mapping_data, self.xcvr_table_helper.get_status_tbl(asic_index))

del globals()['platform_chassis']

Expand Down

0 comments on commit d0fd1e1

Please sign in to comment.