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

[202211] [db_migrator.py] Fix issue while upgrading from 202205 to 202211 via fast reboot #2962

Merged
merged 5 commits into from
Nov 13, 2023
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
14 changes: 8 additions & 6 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,14 @@ def version_4_0_0(self):
# 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|system")
if keys:
enable_state = 'true'
else:
enable_state = 'false'
self.stateDB.set(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable', enable_state)
keys = self.stateDB.keys(self.stateDB.STATE_DB, "FAST_RESTART_ENABLE_TABLE|system")
if not keys:
keys = self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system")
if keys:
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_4_0_1')
return 'version_4_0_1'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FAST_RESTART_ENABLE_TABLE|system": {
"enable": "true"
}
}
19 changes: 19 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ def test_rename_fast_reboot_table_check_enable(self):
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
assert not diff

def test_ignore_rename_fast_reboot_table(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_upgrade_from_202205')
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_upgrade_from_202205')
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
Loading