Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202205] Remove timer from FAST_REBOOT STATE_DB entry and use finalizer #2724

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, namespace, socket=None):
none-zero values.
build: sequentially increase within a minor version domain.
"""
self.CURRENT_VERSION = 'version_3_0_5'
self.CURRENT_VERSION = 'version_3_0_6'

self.TABLE_NAME = 'VERSIONS'
self.TABLE_KEY = 'DATABASE'
Expand Down Expand Up @@ -806,9 +806,28 @@ def version_3_0_4(self):

def version_3_0_5(self):
"""
Current latest version. Nothing to do here.
Version 3_0_5
"""
log.log_info('Handling version_3_0_5')
# Update state-db fast-reboot entry to enable if set to enable fast-reboot finalizer when using upgrade with fast-reboot
# since upgrading from previous version FAST_REBOOT table will be deleted when the timer will expire.
# reading FAST_REBOOT table can't be done with stateDB.get as it uses hget behind the scenes and the table structure is
# not using hash and won't work.
# FAST_REBOOT table exists only if fast-reboot was triggered.
keys = self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT")
arfeigin marked this conversation as resolved.
Show resolved Hide resolved
if keys is not None:
enable_state = 'true'
else:
enable_state = 'false'
self.stateDB.set(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable', enable_state)
self.set_version('version_3_0_6')
return 'version_3_0_6'

def version_3_0_6(self):
"""
Current latest version. Nothing to do here.
"""
log.log_info('Handling version_3_0_6')
return None

def get_version(self):
Expand Down
6 changes: 3 additions & 3 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function clear_boot()

#clear_fast_boot
if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
sonic-db-cli STATE_DB DEL "FAST_REBOOT|system" &>/dev/null || /bin/true
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null || /bin/true
fi
}

Expand Down Expand Up @@ -260,7 +260,7 @@ function backup_database()
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') \
and not string.match(k, 'VXLAN_TUNNEL_TABLE|') \
and not string.match(k, 'BUFFER_MAX_PARAM_TABLE|') \
and not string.match(k, 'FAST_REBOOT|') then
and not string.match(k, 'FAST_RESTART_ENABLE_TABLE|') then
redis.call('del', k)
end
end
Expand Down Expand Up @@ -519,7 +519,7 @@ case "$REBOOT_TYPE" in
check_warm_restart_in_progress
BOOT_TYPE_ARG=$REBOOT_TYPE
trap clear_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
sonic-db-cli STATE_DB SET "FAST_REBOOT|system" "1" "EX" "210" &>/dev/null
sonic-db-cli STATE_DB HSET "FAST_RESTART_ENABLE_TABLE|system" "enable" "true" &>/dev/null
config warm_restart enable system
;;
"warm-reboot")
Expand Down
3 changes: 2 additions & 1 deletion sonic-utilities-data/templates/service_mgmt.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,6 @@
"admin_status": "up"
},
"VERSIONS|DATABASE": {
"VERSION": "version_3_0_5"
"VERSION": "version_3_0_3"
arfeigin marked this conversation as resolved.
Show resolved Hide resolved
arfeigin marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 5 additions & 0 deletions tests/db_migrator_input/state_db/fast_reboot_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FAST_RESTART_ENABLE_TABLE|system": {
"enable": "false"
}
}
2 changes: 2 additions & 0 deletions tests/db_migrator_input/state_db/fast_reboot_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
33 changes: 33 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,39 @@ def test_global_dscp_to_tc_map_migrator(self):
assert resulting_table == {}


class TestFastRebootTableModification(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
dbconnector.dedicated_dbs['STATE_DB'] = None

def mock_dedicated_state_db(self):
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db')

def test_rename_fast_reboot_table_check_enable(self):
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_input')
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'empty-config-input')

import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()

dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_expected')
expected_db = SonicV2Connector(host='127.0.0.1')
expected_db.connect(expected_db.STATE_DB)

resulting_table = dbmgtr.stateDB.get_all(dbmgtr.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')
expected_table = expected_db.get_all(expected_db.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system')

diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
assert not diff


class TestWarmUpgrade_to_2_0_2(object):
@classmethod
def setup_class(cls):
Expand Down