From 256594bcc8ec489aa9605192a59b206d77c85a94 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Fri, 18 Aug 2023 11:08:43 +0800 Subject: [PATCH 1/2] [db_migrator.py] Fix issue while upgrading from 202205 to 202211 via fast reboot Conflicts: scripts/db_migrator.py tests/db_migrator_test.py --- scripts/db_migrator.py | 17 ++++++++++------- .../fast_reboot_upgrade_from_202205.json | 5 +++++ tests/db_migrator_test.py | 8 ++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 tests/db_migrator_input/state_db/fast_reboot_upgrade_from_202205.json diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index a6b2c9c891..5e8bad8686 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -922,12 +922,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' @@ -944,7 +946,8 @@ def version_4_0_2(self): Version 4_0_2. """ log.log_info('Handling version_4_0_2') - if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"): + enable_state = self.stateDB.get(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable') + if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system") or enable_state == 'true': self.migrate_config_db_flex_counter_delay_status() self.set_version('version_4_0_3') return 'version_4_0_3' diff --git a/tests/db_migrator_input/state_db/fast_reboot_upgrade_from_202205.json b/tests/db_migrator_input/state_db/fast_reboot_upgrade_from_202205.json new file mode 100644 index 0000000000..b2e3169d4b --- /dev/null +++ b/tests/db_migrator_input/state_db/fast_reboot_upgrade_from_202205.json @@ -0,0 +1,5 @@ +{ + "FAST_RESTART_ENABLE_TABLE|system": { + "enable": "true" + } +} \ No newline at end of file diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index 3db5be4155..d8f948af63 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -624,3 +624,11 @@ def test_fast_reboot_upgrade_to_4_0_3(self): expected_db = self.mock_dedicated_config_db(db_after_migrate) assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb) assert dbmgtr.CURRENT_VERSION == expected_db.cfgdb.get_entry('VERSIONS', 'DATABASE')['VERSION'] + + +class TestFastUpgrade_to_4_0_3_from_202205(TestFastUpgrade_to_4_0_3): + @classmethod + def setup_class(cls): + os.environ['UTILITIES_UNIT_TESTING'] = "2" + cls.config_db_tables_to_verify = ['FLEX_COUNTER_TABLE'] + dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_upgrade_from_202205') From c59484436a82f8aeaa1566f50aff59a9c608a7d5 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Thu, 24 Aug 2023 08:49:19 +0800 Subject: [PATCH 2/2] Fix review comment Conflicts: tests/db_migrator_test.py --- scripts/db_migrator.py | 3 +-- tests/db_migrator_test.py | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 5e8bad8686..e7153053b0 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -946,8 +946,7 @@ def version_4_0_2(self): Version 4_0_2. """ log.log_info('Handling version_4_0_2') - enable_state = self.stateDB.get(self.stateDB.STATE_DB, 'FAST_RESTART_ENABLE_TABLE|system', 'enable') - if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system") or enable_state == 'true': + if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"): self.migrate_config_db_flex_counter_delay_status() self.set_version('version_4_0_3') return 'version_4_0_3' diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index d8f948af63..7d7065cf04 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -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): @@ -624,11 +643,3 @@ def test_fast_reboot_upgrade_to_4_0_3(self): expected_db = self.mock_dedicated_config_db(db_after_migrate) assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb) assert dbmgtr.CURRENT_VERSION == expected_db.cfgdb.get_entry('VERSIONS', 'DATABASE')['VERSION'] - - -class TestFastUpgrade_to_4_0_3_from_202205(TestFastUpgrade_to_4_0_3): - @classmethod - def setup_class(cls): - os.environ['UTILITIES_UNIT_TESTING'] = "2" - cls.config_db_tables_to_verify = ['FLEX_COUNTER_TABLE'] - dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_upgrade_from_202205')