Skip to content

Commit

Permalink
[202205] Fast reboot finalizer 202205 (#14143)
Browse files Browse the repository at this point in the history
* Finalize fast-reboot in warmboot finalizer

* update fast/warm-reboot finalizer

* support compatibility for fast-reboot from previous versions (prior 202205)

* advance pointers: sairedis, utilities
  • Loading branch information
arfeigin authored Mar 15, 2023
1 parent 95047bd commit 4a3c5e4
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 27 deletions.
4 changes: 2 additions & 2 deletions files/image_config/ntp/ntp-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
41 changes: 36 additions & 5 deletions files/image_config/warmboot-finalizer/finalize-warmboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand All @@ -118,14 +135,20 @@ function restore_counters_folder()

wait_for_database_service

check_fast_reboot
check_warm_boot

if [[ x"${WARM_BOOT}" != x"true" ]]; then
debug "warmboot is not enabled ..."
exit 0
if [[ x"${FAST_REBOOT}" != x"true" ]]; then
debug "fastboot is not enabled ..."
exit 0
fi
fi

restore_counters_folder
if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != x"true") ]]; then
restore_counters_folder
fi

get_component_list

Expand All @@ -142,14 +165,22 @@ for i in `seq 60`; do
sleep 5
done

stop_control_plane_assistant
if [[ (x"${WARM_BOOT}" == x"true") && (x"${FAST_REBOOT}" != 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
debug "Some components didn't finish reconcile: ${list} ..."
fi

finalize_warm_boot
if [ x"${FAST_REBOOT}" == x"true" ]; then
finalize_fast_reboot
fi

if [ x"${WARM_BOOT}" == x"true" ]; then
finalize_warm_boot
fi
3 changes: 2 additions & 1 deletion files/scripts/bgp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" == x"true" ]]; then
FAST_BOOT="true"
else
FAST_BOOT="false"
Expand Down
3 changes: 2 additions & 1 deletion files/scripts/service_mgmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions files/scripts/syncd_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion files/scripts/teamd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 12 additions & 10 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,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, shell=True, 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')
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

return fb_system_state
state_db.close(state_db.STATE_DB)
return fb_enable_state
2 changes: 1 addition & 1 deletion src/sonic-sairedis

0 comments on commit 4a3c5e4

Please sign in to comment.