From e43563bf6038ab38cbcb1203a4d126b6f4b6691a Mon Sep 17 00:00:00 2001 From: afeigin Date: Mon, 23 Jan 2023 11:20:13 +0000 Subject: [PATCH 1/7] Finalize fast-reboot in warmboot-finalizer, update fast-reboot active checks --- files/build_templates/docker_image_ctl.j2 | 3 +-- files/image_config/ntp/ntp-config.sh | 4 ++-- .../warmboot-finalizer/finalize-warmboot.sh | 20 +++++++++++++++++++ files/scripts/bgp.sh | 3 ++- files/scripts/service_mgmt.sh | 3 ++- files/scripts/swss.sh | 5 +++-- files/scripts/syncd_common.sh | 6 ++++-- files/scripts/teamd.sh | 3 ++- .../sonic_py_common/device_info.py | 19 +++++++++--------- 9 files changed, 46 insertions(+), 20 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 6ba11ce65082..3fa4a33703a1 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -244,8 +244,7 @@ function postStartAction() fi if [[ "$BOOT_TYPE" == "fast" ]]; then - # set the key to expire in 3 minutes - $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" + $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "enable" fi $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 9b982d8707b6..a4ec60c9ee66 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -8,11 +8,11 @@ reboot_type='cold' function get_database_reboot_type() { SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SYSTEM_FAST_START=`sonic-db-cli STATE_DB get "FAST_REBOOT|system"` + SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then reboot_type='warm' - elif [[ x"${SYSTEM_FAST_START}" == x"1" ]]; then + elif [[ x"${SYSTEM_FAST_START}" == x"enable" ]]; then reboot_type='fast' fi } diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 412559289026..2e219f83b120 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -52,6 +52,16 @@ function check_warm_boot() WARM_BOOT=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` } +function check_fast_reboot() +{ + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + FAST_REBOOT='true' + else + FAST_REBOOT='false' + fi +} + function wait_for_database_service() { @@ -97,6 +107,12 @@ function finalize_warm_boot() sudo config warm_restart disable } +function finalize_fast_reboot() +{ + debug "Finalizing fast-reboot..." + sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" &>/dev/null +} + function stop_control_plane_assistant() { if [[ -x ${ASSISTANT_SCRIPT} ]]; then @@ -118,6 +134,7 @@ function restore_counters_folder() wait_for_database_service +check_fast_reboot check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then @@ -152,4 +169,7 @@ if [[ -n "${list}" ]]; then debug "Some components didn't finish reconcile: ${list} ..." fi +if [ ${FAST_REBOOT} == "true" ]; then + finalize_fast_reboot +fi finalize_warm_boot diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh index b7a383ebbdd7..ff5ca7e7be06 100755 --- a/files/scripts/bgp.sh +++ b/files/scripts/bgp.sh @@ -30,7 +30,8 @@ function validate_restore_count() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/service_mgmt.sh b/files/scripts/service_mgmt.sh index c1916aefa088..84be757ac16d 100755 --- a/files/scripts/service_mgmt.sh +++ b/files/scripts/service_mgmt.sh @@ -19,7 +19,8 @@ function check_warm_boot() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index e875f50a11db..27b0423aade4 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -60,7 +60,8 @@ function check_warm_boot() function check_fast_boot() { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -285,7 +286,7 @@ stop() { # be restarted. if [[ x"$FAST_BOOT" != x"true" ]]; then debug "Clearing FAST_REBOOT flag..." - clean_up_tables STATE_DB "'FAST_REBOOT*'" + sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" fi # Unlock has to happen before reaching out to peer service unlock_service_state_change diff --git a/files/scripts/syncd_common.sh b/files/scripts/syncd_common.sh index 3d03c8b9e4e5..7f0d825b636f 100755 --- a/files/scripts/syncd_common.sh +++ b/files/scripts/syncd_common.sh @@ -50,7 +50,8 @@ function check_warm_boot() function check_fast_boot() { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -82,7 +83,8 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then TYPE='fast' else TYPE='cold' diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 4de3f25c4dbd..b58b38230d97 100755 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -32,7 +32,8 @@ function validate_restore_count() function check_fast_boot () { - if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 5fc7f13c3082..4632f42a0fb4 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -699,14 +699,15 @@ def is_warm_restart_enabled(container_name): # Check if System fast reboot is enabled. def is_fast_reboot_enabled(): - fb_system_state = 0 - cmd = ['sonic-db-cli', 'STATE_DB', 'get', "FAST_REBOOT|system"] - proc = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE) - (stdout, stderr) = proc.communicate() + state_db = SonicV2Connector(host='127.0.0.1') + state_db.connect(state_db.STATE_DB, False) - if proc.returncode != 0: - log.log_error("Error running command '{}'".format(cmd)) - elif stdout: - fb_system_state = stdout.rstrip('\n') + TABLE_NAME_SEPARATOR = '|' + prefix = 'FAST_REBOOT' + TABLE_NAME_SEPARATOR - return fb_system_state + _hash = '{}{}'.format(prefix, 'system') + fb_system_state = state_db.get(state_db.STATE_DB, _hash, "enable") + fb_enable_state = True if fb_system_state == "true" else False + + state_db.close(state_db.STATE_DB) + return fb_enable_state From bd49567fa75a869d3e55f26b103f9f765e7321e2 Mon Sep 17 00:00:00 2001 From: afeigin Date: Tue, 14 Feb 2023 14:25:50 +0000 Subject: [PATCH 2/7] Rename FAST_REBOOT table --- files/build_templates/docker_image_ctl.j2 | 2 +- files/image_config/ntp/ntp-config.sh | 2 +- files/image_config/warmboot-finalizer/finalize-warmboot.sh | 7 +++++-- files/scripts/bgp.sh | 2 +- files/scripts/service_mgmt.sh | 2 +- files/scripts/swss.sh | 6 +++--- files/scripts/syncd_common.sh | 4 ++-- files/scripts/teamd.sh | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 3fa4a33703a1..b6d4f634d31b 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -244,7 +244,7 @@ function postStartAction() fi if [[ "$BOOT_TYPE" == "fast" ]]; then - $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "enable" + $SONIC_DB_CLI STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "enable" fi $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index a4ec60c9ee66..5de3030abdfc 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -8,7 +8,7 @@ reboot_type='cold' function get_database_reboot_type() { SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then reboot_type='warm' diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 2e219f83b120..a5af403b9a24 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -54,10 +54,13 @@ function check_warm_boot() function check_fast_reboot() { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + debug "Checking if fast-reboot is enabled..." + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + debug "Fast-reboot is enabled..." FAST_REBOOT='true' else + debug "Fast-reboot is disabled..." FAST_REBOOT='false' fi } @@ -110,7 +113,7 @@ function finalize_warm_boot() function finalize_fast_reboot() { debug "Finalizing fast-reboot..." - sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" &>/dev/null + sonic-db-cli STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "disable" &>/dev/null } function stop_control_plane_assistant() diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh index ff5ca7e7be06..87b987098335 100755 --- a/files/scripts/bgp.sh +++ b/files/scripts/bgp.sh @@ -30,7 +30,7 @@ function validate_restore_count() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else diff --git a/files/scripts/service_mgmt.sh b/files/scripts/service_mgmt.sh index 84be757ac16d..c6feec426bc4 100755 --- a/files/scripts/service_mgmt.sh +++ b/files/scripts/service_mgmt.sh @@ -19,7 +19,7 @@ function check_warm_boot() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 27b0423aade4..e58d85148aea 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -60,7 +60,7 @@ function check_warm_boot() function check_fast_boot() { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else @@ -285,8 +285,8 @@ stop() { # encountered error, e.g. syncd crashed. And swss needs to # be restarted. if [[ x"$FAST_BOOT" != x"true" ]]; then - debug "Clearing FAST_REBOOT flag..." - sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "disable" + debug "Clearing FAST_RESTART_ENABLE_TABLE flag..." + sonic-db-cli STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "disable" fi # Unlock has to happen before reaching out to peer service unlock_service_state_change diff --git a/files/scripts/syncd_common.sh b/files/scripts/syncd_common.sh index 7f0d825b636f..6677cc78449c 100755 --- a/files/scripts/syncd_common.sh +++ b/files/scripts/syncd_common.sh @@ -50,7 +50,7 @@ function check_warm_boot() function check_fast_boot() { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else @@ -83,7 +83,7 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then TYPE='fast' else diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index b58b38230d97..634fb3fd2fb2 100755 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -32,7 +32,7 @@ function validate_restore_count() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_REBOOT|system"` + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then FAST_BOOT="true" else From a82cc2520ef2c4d66f55075af9c6d404e1aed2e6 Mon Sep 17 00:00:00 2001 From: Aryeh Feigin <101218333+arfeigin@users.noreply.github.com> Date: Mon, 20 Feb 2023 15:24:35 +0200 Subject: [PATCH 3/7] fix is_fast_reboot_enabled --- .../sonic_py_common/device_info.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 4632f42a0fb4..7455b99921e0 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -699,15 +699,15 @@ def is_warm_restart_enabled(container_name): # Check if System fast reboot is enabled. def is_fast_reboot_enabled(): - state_db = SonicV2Connector(host='127.0.0.1') - state_db.connect(state_db.STATE_DB, False) + fb_system_state = 0 + cmd = ['sonic-db-cli', 'STATE_DB', 'get', "FAST_REBOOT|system"] + proc = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE) + (stdout, stderr) = proc.communicate() - TABLE_NAME_SEPARATOR = '|' - prefix = 'FAST_REBOOT' + TABLE_NAME_SEPARATOR + if proc.returncode != 0: + log.log_error("Error running command '{}'".format(cmd)) + elif stdout: + fb_system_state = stdout.rstrip('\n') - _hash = '{}{}'.format(prefix, 'system') - fb_system_state = state_db.get(state_db.STATE_DB, _hash, "enable") - fb_enable_state = True if fb_system_state == "true" else False - - state_db.close(state_db.STATE_DB) + fb_system_state = True if fb_system_state == "enable" else False return fb_enable_state From d07710ed6e6152aa2e54ce175f486de8fd0672d5 Mon Sep 17 00:00:00 2001 From: Aryeh Feigin <101218333+arfeigin@users.noreply.github.com> Date: Mon, 20 Feb 2023 15:25:23 +0200 Subject: [PATCH 4/7] Update device_info.py --- src/sonic-py-common/sonic_py_common/device_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 7455b99921e0..c56b99c11468 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -710,4 +710,4 @@ def is_fast_reboot_enabled(): fb_system_state = stdout.rstrip('\n') fb_system_state = True if fb_system_state == "enable" else False - return fb_enable_state + return fb_system_state From 166349dbb707aeaab5a10a957c4814d120edaf50 Mon Sep 17 00:00:00 2001 From: afeigin Date: Tue, 28 Feb 2023 19:45:27 +0000 Subject: [PATCH 5/7] update fast-reboot check --- files/build_templates/docker_image_ctl.j2 | 2 +- files/image_config/ntp/ntp-config.sh | 4 +-- .../warmboot-finalizer/finalize-warmboot.sh | 10 +++----- files/scripts/bgp.sh | 4 +-- files/scripts/service_mgmt.sh | 4 +-- files/scripts/swss.sh | 6 ++--- files/scripts/syncd_common.sh | 8 +++--- files/scripts/teamd.sh | 4 +-- .../sonic_py_common/device_info.py | 25 ++++++++++--------- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index b6d4f634d31b..c0a94275587d 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -244,7 +244,7 @@ function postStartAction() fi if [[ "$BOOT_TYPE" == "fast" ]]; then - $SONIC_DB_CLI STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "enable" + $SONIC_DB_CLI STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "true" fi $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 5de3030abdfc..6bb2b2ed3cc9 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -8,11 +8,11 @@ reboot_type='cold' function get_database_reboot_type() { SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` + SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system" enable` if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then reboot_type='warm' - elif [[ x"${SYSTEM_FAST_START}" == x"enable" ]]; then + elif [[ x"${SYSTEM_FAST_START}" == x"true" ]]; then reboot_type='fast' fi } diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index a5af403b9a24..7994539b0a87 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -55,13 +55,11 @@ function check_warm_boot() function check_fast_reboot() { debug "Checking if fast-reboot is enabled..." - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${FAST_REBOOT}" == x"true" ]]; then debug "Fast-reboot is enabled..." - FAST_REBOOT='true' else debug "Fast-reboot is disabled..." - FAST_REBOOT='false' fi } @@ -113,7 +111,7 @@ function finalize_warm_boot() function finalize_fast_reboot() { debug "Finalizing fast-reboot..." - sonic-db-cli STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "disable" &>/dev/null + sonic-db-cli STATE_DB hset "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null } function stop_control_plane_assistant() @@ -172,7 +170,7 @@ if [[ -n "${list}" ]]; then debug "Some components didn't finish reconcile: ${list} ..." fi -if [ ${FAST_REBOOT} == "true" ]; then +if [ x"${FAST_REBOOT}" == x"true" ]; then finalize_fast_reboot fi finalize_warm_boot diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh index 87b987098335..1a5d8fdd85d0 100755 --- a/files/scripts/bgp.sh +++ b/files/scripts/bgp.sh @@ -30,8 +30,8 @@ function validate_restore_count() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == "true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/service_mgmt.sh b/files/scripts/service_mgmt.sh index c6feec426bc4..6377acac695a 100755 --- a/files/scripts/service_mgmt.sh +++ b/files/scripts/service_mgmt.sh @@ -19,8 +19,8 @@ function check_warm_boot() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index e58d85148aea..0e9b029dcd26 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -60,8 +60,8 @@ function check_warm_boot() function check_fast_boot() { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -286,7 +286,7 @@ stop() { # be restarted. if [[ x"$FAST_BOOT" != x"true" ]]; then debug "Clearing FAST_RESTART_ENABLE_TABLE flag..." - sonic-db-cli STATE_DB SET "FAST_RESTART_ENABLE_TABLE|system" "disable" + sonic-db-cli STATE_DB hset "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" fi # Unlock has to happen before reaching out to peer service unlock_service_state_change diff --git a/files/scripts/syncd_common.sh b/files/scripts/syncd_common.sh index 6677cc78449c..a850e31b207d 100755 --- a/files/scripts/syncd_common.sh +++ b/files/scripts/syncd_common.sh @@ -50,8 +50,8 @@ function check_warm_boot() function check_fast_boot() { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -83,8 +83,8 @@ function getBootType() ;; *SONIC_BOOT_TYPE=fast*|*fast-reboot*) # check that the key exists - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then TYPE='fast' else TYPE='cold' diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 634fb3fd2fb2..dd6b05caa4c2 100755 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -32,8 +32,8 @@ function validate_restore_count() function check_fast_boot () { - SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system"` - if [[ ${SYSTEM_FAST_REBOOT} == "enable" ]]; then + SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index c56b99c11468..3f95e75f70cc 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -699,15 +699,16 @@ def is_warm_restart_enabled(container_name): # Check if System fast reboot is enabled. def is_fast_reboot_enabled(): - fb_system_state = 0 - cmd = ['sonic-db-cli', 'STATE_DB', 'get', "FAST_REBOOT|system"] - proc = subprocess.Popen(cmd, universal_newlines=True, stdout=subprocess.PIPE) - (stdout, stderr) = proc.communicate() - - if proc.returncode != 0: - log.log_error("Error running command '{}'".format(cmd)) - elif stdout: - fb_system_state = stdout.rstrip('\n') - - fb_system_state = True if fb_system_state == "enable" else False - return fb_system_state + state_db = SonicV2Connector(host='127.0.0.1') + state_db.connect(state_db.STATE_DB, False) + + TABLE_NAME_SEPARATOR = '|' + prefix = 'FAST_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR + + # Get the system warm reboot enable state + _hash = '{}{}'.format(prefix, 'system') + fb_system_state = state_db.get(state_db.STATE_DB, _hash, "enable") + fb_enable_state = True if fb_system_state == "true" else False + + state_db.close(state_db.STATE_DB) + return fb_enable_state From 6d28baee53f9b521fe30ed1d36d06d2c9d25d1e6 Mon Sep 17 00:00:00 2001 From: Aryeh Feigin <101218333+arfeigin@users.noreply.github.com> Date: Mon, 6 Mar 2023 11:39:54 +0200 Subject: [PATCH 6/7] Update ntp-config.sh --- files/image_config/ntp/ntp-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 6bb2b2ed3cc9..ace9ad1c8a42 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -8,7 +8,7 @@ reboot_type='cold' function get_database_reboot_type() { SYSTEM_WARM_START=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SYSTEM_FAST_START=`sonic-db-cli STATE_DB GET "FAST_RESTART_ENABLE_TABLE|system" enable` + SYSTEM_FAST_START=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` if [[ x"${SYSTEM_WARM_START}" == x"true" ]]; then reboot_type='warm' From 17e6657d95d57f622ffe6e9fdf5a99e47162dbba Mon Sep 17 00:00:00 2001 From: Aryeh Feigin <101218333+arfeigin@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:33:07 +0200 Subject: [PATCH 7/7] revert change in docker_image_ctl,j2 to support compatibility --- files/build_templates/docker_image_ctl.j2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index c0a94275587d..7cf26aa26453 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -244,7 +244,8 @@ function postStartAction() fi if [[ "$BOOT_TYPE" == "fast" ]]; then - $SONIC_DB_CLI STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "true" + # set the key to expire in 3 minutes + $SONIC_DB_CLI STATE_DB SET "FAST_REBOOT|system" "1" "EX" "180" fi $SONIC_DB_CLI CONFIG_DB SET "CONFIG_DB_INITIALIZED" "1" @@ -649,4 +650,4 @@ case "$1" in echo "Usage: $0 {start namespace(optional)|wait namespace(optional)|stop namespace(optional)}" exit 1 ;; -esac \ No newline at end of file +esac