From d1203efa544c9c13337bf2739c4c285bc3b69dce Mon Sep 17 00:00:00 2001 From: Aryeh Feigin <101218333+arfeigin@users.noreply.github.com> Date: Mon, 10 Apr 2023 19:56:50 +0300 Subject: [PATCH] Update xcvrd to use new STATE_DB FAST_REBOOT entry (#335) Update xcvrd to check if fast-reboot is enabled according to the new value for FAST_REBOOT entry in STATE_DB. This PR should come along with the following PRs: sonic-net/sonic-utilities#2621 sonic-net/sonic-buildimage#13484 sonic-net/sonic-swss-common#742 sonic-net/sonic-sairedis#1196 This set of PRs solves the issue sonic-net/sonic-buildimage#13251 Description Update xcvrd to check the updated form of fast-reboot entry in state-db as it was changed. Motivation and Context Introducing fast-reboot finalizer on top of warmboot-finalizer, fast-reboot entry in STATE_DB is now changed from "1"/None to "enable"/"disable". How Has This Been Tested? Existing tests, and fast-reboot. --- sonic-xcvrd/tests/test_xcvrd.py | 9 ++++++--- sonic-xcvrd/xcvrd/xcvrd.py | 13 ++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 46638453c..94a30bdf1 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -1518,10 +1518,13 @@ def test_get_media_val_str(self): @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()) - def test_DaemonXcvrd_init_deinit(self): + def test_DaemonXcvrd_init_deinit_fastboot_enabled(self): xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER) - xcvrd.init() - xcvrd.deinit() + with patch("subprocess.check_output") as mock_run: + mock_run.return_value = "true" + + xcvrd.init() + xcvrd.deinit() def wait_until(total_wait_time, interval, call_back, *args, **kwargs): diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index f9a06b08b..e0e7cd746 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -921,17 +921,8 @@ def init_port_sfp_status_tbl(port_mapping, xcvr_table_helper, stop_event=threadi update_port_transceiver_status_table_sw(logical_port_name, xcvr_table_helper.get_status_tbl(asic_index), sfp_status_helper.SFP_STATUS_INSERTED) def is_fast_reboot_enabled(): - fastboot_enabled = False - state_db_host = daemon_base.db_connect("STATE_DB") - fastboot_tbl = swsscommon.Table(state_db_host, 'FAST_REBOOT') - keys = fastboot_tbl.getKeys() - - if "system" in keys: - output = subprocess.check_output(['sonic-db-cli', 'STATE_DB', 'get', "FAST_REBOOT|system"], universal_newlines=True) - if "1" in output: - fastboot_enabled = True - - return fastboot_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 # # Helper classes ===============================================================