Skip to content

Commit 6f05f7e

Browse files
authored
[202205] Remove timer from FAST_REBOOT STATE_DB entry and use finalizer (#2724)
Dedicated PR for 202205 branch similar to #2621 as part of fast-reboot finalizer implementation. This should come along with sonic-buildimage PR 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-sairedis#1217 sonic-net/sonic-platform-daemons#343 sonic-net/sonic-buildimage#14143 This set of PRs solves the issue sonic-net/sonic-buildimage#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: true/false" 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 b8072ea commit 6f05f7e

7 files changed

Lines changed: 67 additions & 7 deletions

File tree

scripts/db_migrator.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, namespace, socket=None):
4646
none-zero values.
4747
build: sequentially increase within a minor version domain.
4848
"""
49-
self.CURRENT_VERSION = 'version_3_0_5'
49+
self.CURRENT_VERSION = 'version_3_0_6'
5050

5151
self.TABLE_NAME = 'VERSIONS'
5252
self.TABLE_KEY = 'DATABASE'
@@ -823,9 +823,28 @@ def version_3_0_4(self):
823823

824824
def version_3_0_5(self):
825825
"""
826-
Current latest version. Nothing to do here.
826+
Version 3_0_5
827827
"""
828828
log.log_info('Handling version_3_0_5')
829+
# Update state-db fast-reboot entry to enable if set to enable fast-reboot finalizer when using upgrade with fast-reboot
830+
# since upgrading from previous version FAST_REBOOT table will be deleted when the timer will expire.
831+
# reading FAST_REBOOT table can't be done with stateDB.get as it uses hget behind the scenes and the table structure is
832+
# not using hash and won't work.
833+
# FAST_REBOOT table exists only if fast-reboot was triggered.
834+
keys = self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT")
835+
if keys is not None:
836+
enable_state = 'true'
837+
else:
838+
enable_state = 'false'
839+
self.stateDB.set(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable', enable_state)
840+
self.set_version('version_3_0_6')
841+
return 'version_3_0_6'
842+
843+
def version_3_0_6(self):
844+
"""
845+
Current latest version. Nothing to do here.
846+
"""
847+
log.log_info('Handling version_3_0_6')
829848
return None
830849

831850
def get_version(self):

scripts/fast-reboot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function clear_boot()
144144
145145
#clear_fast_boot
146146
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
147-
sonic-db-cli STATE_DB DEL "FAST_REBOOT|system" &>/dev/null || /bin/true
147+
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null || /bin/true
148148
fi
149149
}
150150
@@ -265,7 +265,7 @@ function backup_database()
265265
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') \
266266
and not string.match(k, 'VXLAN_TUNNEL_TABLE|') \
267267
and not string.match(k, 'BUFFER_MAX_PARAM_TABLE|') \
268-
and not string.match(k, 'FAST_REBOOT|') then
268+
and not string.match(k, 'FAST_RESTART_ENABLE_TABLE|') then
269269
redis.call('del', k)
270270
end
271271
end
@@ -524,7 +524,7 @@ case "$REBOOT_TYPE" in
524524
check_warm_restart_in_progress
525525
BOOT_TYPE_ARG=$REBOOT_TYPE
526526
trap clear_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
527-
sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "210" &>/dev/null
527+
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "true" &>/dev/null
528528
config warm_restart enable system
529529
;;
530530
"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"

tests/db_migrator_input/config_db/reclaiming-buffer-warmreboot-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,6 @@
20442044
"admin_status": "up"
20452045
},
20462046
"VERSIONS|DATABASE": {
2047-
"VERSION": "version_3_0_5"
2047+
"VERSION": "version_3_0_3"
20482048
}
20492049
}
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,39 @@ def test_global_dscp_to_tc_map_migrator(self):
411411
assert resulting_table == {}
412412

413413

414+
class TestFastRebootTableModification(object):
415+
@classmethod
416+
def setup_class(cls):
417+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
418+
419+
@classmethod
420+
def teardown_class(cls):
421+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
422+
dbconnector.dedicated_dbs['STATE_DB'] = None
423+
424+
def mock_dedicated_state_db(self):
425+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db')
426+
427+
def test_rename_fast_reboot_table_check_enable(self):
428+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
429+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_input')
430+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'empty-config-input')
431+
432+
import db_migrator
433+
dbmgtr = db_migrator.DBMigrator(None)
434+
dbmgtr.migrate()
435+
436+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_expected')
437+
expected_db = SonicV2Connector(host='127.0.0.1')
438+
expected_db.connect(expected_db.STATE_DB)
439+
440+
resulting_table = dbmgtr.stateDB.get_all(dbmgtr.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')
441+
expected_table = expected_db.get_all(expected_db.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')
442+
443+
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
444+
assert not diff
445+
446+
414447
class TestWarmUpgrade_to_2_0_2(object):
415448
@classmethod
416449
def setup_class(cls):

0 commit comments

Comments
 (0)