Skip to content

Commit e6179af

Browse files
authored
Remove timer from FAST_REBOOT STATE_DB entry and use finalizer (sonic-net#2621)
This should come along with sonic-buildimage PR (sonic-net#13484) implementing fast-reboot finalizing logic in finalize-warmboot script and other submodules PRs utilizing the change. This PR should come along with the following PRs as well: sonic-net/sonic-swss-common#742 sonic-net/sonic-platform-daemons#335 sonic-net/sonic-sairedis#1196 This set of PRs solves the issue sonic-net#13251 What I did Remove the timer used to clear fast-reboot entry from state-db, instead it will be cleared by fast-reboot finalize function implemented inside finalize-warmboot script (which will be invoked since fast-reboot is using warm-reboot infrastructure). As well instead of having "1" as the value for fast-reboot entry in state-db and deleting it when done it is now modified to set enable/disable according to the context. As well all scripts reading this entry should be modified to the new value options. How I did it Removed the timer usage in the fast-reboot script and adding fast-reboot finalize logic to warm-reboot in the linked PR. Use "enable/disable" instead of "1" as the entry value. How to verify it Run fast-reboot and check that the state-db entry for fast-reboot is being deleted after finalizing fast-reboot and not by an expiring timer.
1 parent ff68832 commit e6179af

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

scripts/db_migrator.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, namespace, socket=None):
4545
none-zero values.
4646
build: sequentially increase within a minor version domain.
4747
"""
48-
self.CURRENT_VERSION = 'version_4_0_0'
48+
self.CURRENT_VERSION = 'version_4_0_1'
4949

5050
self.TABLE_NAME = 'VERSIONS'
5151
self.TABLE_KEY = 'DATABASE'
@@ -867,9 +867,28 @@ def version_3_0_6(self):
867867
def version_4_0_0(self):
868868
"""
869869
Version 4_0_0.
870-
This is the latest version for master branch
871870
"""
872871
log.log_info('Handling version_4_0_0')
872+
# Update state-db fast-reboot entry to enable if set to enable fast-reboot finalizer when using upgrade with fast-reboot
873+
# since upgrading from previous version FAST_REBOOT table will be deleted when the timer will expire.
874+
# reading FAST_REBOOT table can't be done with stateDB.get as it uses hget behind the scenes and the table structure is
875+
# not using hash and won't work.
876+
# FAST_REBOOT table exists only if fast-reboot was triggered.
877+
keys = self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT")
878+
if keys is not None:
879+
enable_state = 'true'
880+
else:
881+
enable_state = 'false'
882+
self.stateDB.set(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable', enable_state)
883+
self.set_version('version_4_0_1')
884+
return 'version_4_0_1'
885+
886+
def version_4_0_1(self):
887+
"""
888+
Version 4_0_1.
889+
This is the latest version for master branch
890+
"""
891+
log.log_info('Handling version_4_0_1')
873892
return None
874893

875894
def get_version(self):

scripts/fast-reboot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function clear_boot()
149149
150150
#clear_fast_boot
151151
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
152-
sonic-db-cli STATE_DB DEL "FAST_REBOOT|system" &>/dev/null || /bin/true
152+
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null || /bin/true
153153
fi
154154
}
155155
@@ -270,7 +270,7 @@ function backup_database()
270270
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') \
271271
and not string.match(k, 'VXLAN_TUNNEL_TABLE|') \
272272
and not string.match(k, 'BUFFER_MAX_PARAM_TABLE|') \
273-
and not string.match(k, 'FAST_REBOOT|') then
273+
and not string.match(k, 'FAST_RESTART_ENABLE_TABLE|') then
274274
redis.call('del', k)
275275
end
276276
end
@@ -549,7 +549,7 @@ case "$REBOOT_TYPE" in
549549
check_warm_restart_in_progress
550550
BOOT_TYPE_ARG=$REBOOT_TYPE
551551
trap clear_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
552-
sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "210" &>/dev/null
552+
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "true" &>/dev/null
553553
config warm_restart enable system
554554
;;
555555
"warm-reboot")

sonic-utilities-data/templates/service_mgmt.sh.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function check_warm_boot()
5151

5252
function check_fast_boot()
5353
{
54-
if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then
54+
SYSTEM_FAST_REBOOT=`$SONIC_DB_CLI STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable`
55+
if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then
5556
FAST_BOOT="true"
5657
else
5758
FAST_BOOT="false"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FAST_RESTART_ENABLE_TABLE|system": {
3+
"enable": "false"
4+
}
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

tests/db_migrator_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,38 @@ def test_move_logger_tables_in_warm_upgrade(self):
451451
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
452452
assert not diff
453453

454+
class TestFastRebootTableModification(object):
455+
@classmethod
456+
def setup_class(cls):
457+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
458+
459+
@classmethod
460+
def teardown_class(cls):
461+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
462+
dbconnector.dedicated_dbs['STATE_DB'] = None
463+
464+
def mock_dedicated_state_db(self):
465+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db')
466+
467+
def test_rename_fast_reboot_table_check_enable(self):
468+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
469+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_input')
470+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'empty-config-input')
471+
472+
import db_migrator
473+
dbmgtr = db_migrator.DBMigrator(None)
474+
dbmgtr.migrate()
475+
476+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_expected')
477+
expected_db = SonicV2Connector(host='127.0.0.1')
478+
expected_db.connect(expected_db.STATE_DB)
479+
480+
resulting_table = dbmgtr.stateDB.get_all(dbmgtr.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')
481+
expected_table = expected_db.get_all(expected_db.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')
482+
483+
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
484+
assert not diff
485+
454486
class TestWarmUpgrade_to_2_0_2(object):
455487
@classmethod
456488
def setup_class(cls):

0 commit comments

Comments
 (0)