Skip to content

Commit

Permalink
[202205] Update xcvrd to use new STATE_DB FAST_REBOOT entry (#343)
Browse files Browse the repository at this point in the history
This PR is similar to #335, dedicated to 202205 branch.

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-buildimage#14143
sonic-net/sonic-sairedis#1217
sonic-net/sonic-utilities#2724

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: true/false".

How Has This Been Tested?
Existing tests, and fast-reboot.
  • Loading branch information
arfeigin authored Mar 16, 2023
1 parent 10bc119 commit f6ce56e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 8 additions & 5 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,12 +1423,15 @@ 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()
# TODO: fow now we only simply call xcvrd.init/deinit without any further check, it only makes sure that
# xcvrd.init/deinit will not raise unexpected exception. In future, probably more check will be added
with patch("subprocess.check_output") as mock_run:
mock_run.return_value = "true"

xcvrd.init()
xcvrd.deinit()
# TODO: fow now we only simply call xcvrd.init/deinit without any further check, it only makes sure that
# xcvrd.init/deinit will not raise unexpected exception. In future, probably more check will be added


def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
Expand Down
12 changes: 2 additions & 10 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,17 +921,9 @@ 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()
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

if "system" in keys:
output = subprocess.check_output('sonic-db-cli STATE_DB get "FAST_REBOOT|system"', shell=True, universal_newlines=True)
if "1" in output:
fastboot_enabled = True

return fastboot_enabled

#
# Helper classes ===============================================================
Expand Down

0 comments on commit f6ce56e

Please sign in to comment.