From e3081533acefe245d870ea8948da75ef9b5813cf Mon Sep 17 00:00:00 2001 From: dprital Date: Tue, 7 Mar 2023 13:49:32 +0000 Subject: [PATCH 1/5] Finalize fast-reboot in warmboot finalizer --- files/build_templates/docker_image_ctl.j2 | 3 +-- files/image_config/ntp/ntp-config.sh | 4 ++-- .../warmboot-finalizer/finalize-warmboot.sh | 21 +++++++++++++++++++ files/scripts/bgp.sh | 3 ++- files/scripts/service_mgmt.sh | 3 ++- files/scripts/swss.sh | 7 ++++--- files/scripts/syncd_common.sh | 6 ++++-- files/scripts/teamd.sh | 3 ++- .../sonic_py_common/device_info.py | 20 ++++++++++-------- 9 files changed, 49 insertions(+), 21 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index cb48e6b5f924..83385db8425b 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -250,8 +250,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 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 9b982d8707b6..ace9ad1c8a42 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 hget "FAST_RESTART_ENABLE_TABLE|system" enable` 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"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 412559289026..7994539b0a87 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -52,6 +52,17 @@ function check_warm_boot() WARM_BOOT=`sonic-db-cli STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` } +function check_fast_reboot() +{ + debug "Checking if fast-reboot is enabled..." + 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..." + else + debug "Fast-reboot is disabled..." + fi +} + function wait_for_database_service() { @@ -97,6 +108,12 @@ function finalize_warm_boot() sudo config warm_restart disable } +function finalize_fast_reboot() +{ + debug "Finalizing fast-reboot..." + sonic-db-cli STATE_DB hset "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null +} + function stop_control_plane_assistant() { if [[ -x ${ASSISTANT_SCRIPT} ]]; then @@ -118,6 +135,7 @@ function restore_counters_folder() wait_for_database_service +check_fast_reboot check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then @@ -152,4 +170,7 @@ if [[ -n "${list}" ]]; then debug "Some components didn't finish reconcile: ${list} ..." fi +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 b7a383ebbdd7..1a5d8fdd85d0 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 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 c529ef92ce5e..a3709bf2bf8b 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 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 e875f50a11db..0e9b029dcd26 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 hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then FAST_BOOT="true" else FAST_BOOT="false" @@ -284,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..." - clean_up_tables STATE_DB "'FAST_REBOOT*'" + debug "Clearing FAST_RESTART_ENABLE_TABLE flag..." + 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 3d03c8b9e4e5..a850e31b207d 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 hget "FAST_RESTART_ENABLE_TABLE|system" enable` + if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; 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 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 4de3f25c4dbd..dd6b05caa4c2 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 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 5fc7f13c3082..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,14 +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() + 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_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR - return fb_system_state + # 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 5d821a71d80f1295c15b8ca5da31623d36395f87 Mon Sep 17 00:00:00 2001 From: dprital Date: Tue, 7 Mar 2023 14:35:23 +0000 Subject: [PATCH 2/5] fix bug on finalize-warmboot.sh script --- .../warmboot-finalizer/finalize-warmboot.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 7994539b0a87..1aa9cbda2b7f 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -140,10 +140,15 @@ check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then debug "warmboot is not enabled ..." - exit 0 + if [[ x"${FAST_BOOT}" != x"true" ]]; then + debug "fastboot is not enabled ..." + exit(0) + fi fi -restore_counters_folder +if [[ x"${WARM_BOOT}" == x"true" ]]; then + restore_counters_folder +fi get_component_list @@ -160,10 +165,12 @@ for i in `seq 60`; do sleep 5 done -stop_control_plane_assistant +if [[ x"${WARM_BOOT}" == x"true" ]]; then + stop_control_plane_assistant +fi # Save DB after stopped control plane assistant to avoid extra entries -debug "Save in-memory database after warm reboot ..." +debug "Save in-memory database after warm/fast reboot ..." config save -y if [[ -n "${list}" ]]; then @@ -172,5 +179,6 @@ fi if [ x"${FAST_REBOOT}" == x"true" ]; then finalize_fast_reboot +else + finalize_warm_boot fi -finalize_warm_boot From b88f2b61e55bb03d0e9c3c3728434e3835f8e7b7 Mon Sep 17 00:00:00 2001 From: dprital Date: Tue, 7 Mar 2023 16:25:41 +0000 Subject: [PATCH 3/5] fixes after review --- files/image_config/warmboot-finalizer/finalize-warmboot.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 1aa9cbda2b7f..ecd8f3f41956 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -141,8 +141,8 @@ check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then debug "warmboot is not enabled ..." if [[ x"${FAST_BOOT}" != x"true" ]]; then - debug "fastboot is not enabled ..." - exit(0) + debug "fastboot is not enabled ..." + exit 0 fi fi From 81f86c529bb7dd7add4ab1e23ace6db17d1a02f4 Mon Sep 17 00:00:00 2001 From: dprital Date: Tue, 7 Mar 2023 19:03:23 +0000 Subject: [PATCH 4/5] Isolate actions relevant only for warmboot --- .../image_config/warmboot-finalizer/finalize-warmboot.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index ecd8f3f41956..8e3f8047513b 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -146,7 +146,7 @@ if [[ x"${WARM_BOOT}" != x"true" ]]; then fi fi -if [[ x"${WARM_BOOT}" == x"true" ]]; then +if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_BOOT}" != x"true") ]]; then restore_counters_folder fi @@ -165,7 +165,7 @@ for i in `seq 60`; do sleep 5 done -if [[ x"${WARM_BOOT}" == x"true" ]]; then +if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_BOOT}" != x"true") ]]; then stop_control_plane_assistant fi @@ -179,6 +179,8 @@ fi if [ x"${FAST_REBOOT}" == x"true" ]; then finalize_fast_reboot -else +fi + +if [ x"${WARM_REBOOT}" == x"true" ]; then finalize_warm_boot fi From 8387193966b57c61549148d771284a8645f5957b Mon Sep 17 00:00:00 2001 From: dprital Date: Tue, 7 Mar 2023 22:44:50 +0000 Subject: [PATCH 5/5] Fix typo in FAST_BOOT flag --- .../image_config/warmboot-finalizer/finalize-warmboot.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 8e3f8047513b..761c77b1bdce 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -140,13 +140,13 @@ check_warm_boot if [[ x"${WARM_BOOT}" != x"true" ]]; then debug "warmboot is not enabled ..." - if [[ x"${FAST_BOOT}" != x"true" ]]; then + if [[ x"${FAST_REBOOT}" != x"true" ]]; then debug "fastboot is not enabled ..." exit 0 fi fi -if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_BOOT}" != x"true") ]]; then +if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != x"true") ]]; then restore_counters_folder fi @@ -165,7 +165,7 @@ for i in `seq 60`; do sleep 5 done -if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_BOOT}" != x"true") ]]; then +if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != x"true") ]]; then stop_control_plane_assistant fi @@ -181,6 +181,6 @@ if [ x"${FAST_REBOOT}" == x"true" ]; then finalize_fast_reboot fi -if [ x"${WARM_REBOOT}" == x"true" ]; then +if [ x"${WARM_BOOT}" == x"true" ]; then finalize_warm_boot fi