From 90863c1773a765ee3b571d80a6549593eb012313 Mon Sep 17 00:00:00 2001 From: vadymhlushko-mlnx Date: Fri, 9 Jun 2023 15:35:12 +0300 Subject: [PATCH] [db_migtrator] Add migration of FLEX_COUNTER_DELAY_STATUS during 1911->master upgrade + fast-reboot. Add UT. Signed-off-by: vadymhlushko-mlnx --- scripts/db_migrator.py | 18 ++++++++++ ...ross_branch_upgrade_to_4_0_2_expected.json | 19 ++++++++++ .../cross_branch_upgrade_to_4_0_2_input.json | 18 ++++++++++ .../state_db/fast_reboot_upgrade.json | 5 +++ tests/db_migrator_test.py | 35 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_expected.json create mode 100644 tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_input.json create mode 100644 tests/db_migrator_input/state_db/fast_reboot_upgrade.json diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index cc9506f606..76678bc979 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -650,6 +650,20 @@ def update_edgezone_aggregator_config(self): # Set new cable length values self.configDB.set(self.configDB.CONFIG_DB, "CABLE_LENGTH|AZURE", intf, EDGEZONE_AGG_CABLE_LENGTH) + def migrate_config_db_flex_counter_delay_status(self): + """ + Migrate "FLEX_COUNTER_TABLE|*": { "value": { "FLEX_COUNTER_DELAY_STATUS": "false" } } + Set FLEX_COUNTER_DELAY_STATUS true in case of fast-reboot + """ + + flex_counter_objects = self.configDB.get_keys('FLEX_COUNTER_TABLE') + for obj in flex_counter_objects: + flex_counter = self.configDB.get_entry('FLEX_COUNTER_TABLE', obj) + delay_status = flex_counter.get('FLEX_COUNTER_DELAY_STATUS') + if delay_status is None or delay_status == 'false': + flex_counter['FLEX_COUNTER_DELAY_STATUS'] = 'true' + self.configDB.mod_entry('FLEX_COUNTER_TABLE', obj, flex_counter) + def version_unknown(self): """ version_unknown tracks all SONiC versions that doesn't have a version @@ -951,6 +965,10 @@ def version_4_0_2(self): This is the latest version for master branch """ log.log_info('Handling version_4_0_2') + + if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"): + self.migrate_config_db_flex_counter_delay_status() + return None def get_version(self): diff --git a/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_expected.json b/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_expected.json new file mode 100644 index 0000000000..9fb54d1e8a --- /dev/null +++ b/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_expected.json @@ -0,0 +1,19 @@ +{ + "VERSIONS|DATABASE": { + "VERSION": "version_4_0_2" + }, + "FLEX_COUNTER_TABLE|ACL": { + "FLEX_COUNTER_STATUS": "true", + "FLEX_COUNTER_DELAY_STATUS": "true", + "POLL_INTERVAL": "10000" + }, + "FLEX_COUNTER_TABLE|QUEUE": { + "FLEX_COUNTER_STATUS": "true", + "FLEX_COUNTER_DELAY_STATUS": "true", + "POLL_INTERVAL": "10000" + }, + "FLEX_COUNTER_TABLE|PG_WATERMARK": { + "FLEX_COUNTER_STATUS": "false", + "FLEX_COUNTER_DELAY_STATUS": "true" + } +} diff --git a/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_input.json b/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_input.json new file mode 100644 index 0000000000..07ce763683 --- /dev/null +++ b/tests/db_migrator_input/config_db/cross_branch_upgrade_to_4_0_2_input.json @@ -0,0 +1,18 @@ +{ + "VERSIONS|DATABASE": { + "VERSION": "version_1_0_1" + }, + "FLEX_COUNTER_TABLE|ACL": { + "FLEX_COUNTER_STATUS": "true", + "FLEX_COUNTER_DELAY_STATUS": "true", + "POLL_INTERVAL": "10000" + }, + "FLEX_COUNTER_TABLE|QUEUE": { + "FLEX_COUNTER_STATUS": "true", + "FLEX_COUNTER_DELAY_STATUS": "false", + "POLL_INTERVAL": "10000" + }, + "FLEX_COUNTER_TABLE|PG_WATERMARK": { + "FLEX_COUNTER_STATUS": "false" + } +} diff --git a/tests/db_migrator_input/state_db/fast_reboot_upgrade.json b/tests/db_migrator_input/state_db/fast_reboot_upgrade.json new file mode 100644 index 0000000000..c4539271d4 --- /dev/null +++ b/tests/db_migrator_input/state_db/fast_reboot_upgrade.json @@ -0,0 +1,5 @@ +{ + "FAST_REBOOT|system": { + "enable": "true" + } +} diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index c06bb11d11..6c99380c6c 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -623,3 +623,38 @@ def test_warm_upgrade_t0_edgezone_aggregator_same_cable_length(self): diff = DeepDiff(resulting_table, expected_table, ignore_order=True) assert not diff + + +class TestFastUpgrade_to_4_0_2(object): + @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') + + @classmethod + def teardown_class(cls): + os.environ['UTILITIES_UNIT_TESTING'] = "0" + dbconnector.dedicated_dbs['CONFIG_DB'] = None + dbconnector.dedicated_dbs['STATE_DB'] = None + + def mock_dedicated_config_db(self, filename): + jsonfile = os.path.join(mock_db_path, 'config_db', filename) + dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile + db = Db() + return db + + def check_config_db(self, result, expected): + for table in self.config_db_tables_to_verify: + assert result.get_table(table) == expected.get_table(table) + + def test_fast_reboot_upgrade_to_4_0_2(self): + db_before_migrate = 'cross_branch_upgrade_to_4_0_2_input' + db_after_migrate = 'cross_branch_upgrade_to_4_0_2_expected' + device_info.get_sonic_version_info = get_sonic_version_info_mlnx + db = self.mock_dedicated_config_db(db_before_migrate) + import db_migrator + dbmgtr = db_migrator.DBMigrator(None) + dbmgtr.migrate() + expected_db = self.mock_dedicated_config_db(db_after_migrate) + assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb) \ No newline at end of file