Skip to content

Commit

Permalink
[202111][db_migrator] Add migration of FLEX_COUNTER_DELAY_STATUS duri…
Browse files Browse the repository at this point in the history
…ng 1911->master upgrade + fast-reboot. Add UT.

Signed-off-by: vadymhlushko-mlnx <vadymh@nvidia.com>
  • Loading branch information
vadymhlushko-mlnx committed Jun 14, 2023
1 parent 77bf177 commit 4fd2e3c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
28 changes: 27 additions & 1 deletion scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ def migrate_qos_fieldval_reference_format(self):
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
return True

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
Expand Down Expand Up @@ -627,9 +641,21 @@ def version_2_0_3(self):

def version_2_0_4(self):
"""
Current latest version. Nothing to do here.
Version 2_0_4
"""
log.log_info('Handling version_2_0_4')

if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"):
self.migrate_config_db_flex_counter_delay_status()

self.set_version('version_2_0_5')
return 'version_2_0_5'

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

def get_version(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_5"
},
"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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,6 @@
"admin_status": "up"
},
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_4"
"VERSION": "version_2_0_5"
}
}
5 changes: 5 additions & 0 deletions tests/db_migrator_input/state_db/fast_reboot_upgrade.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FAST_REBOOT|system": {
"enable": "true"
}
}
35 changes: 35 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,38 @@ def test_qos_buffer_migrator_for_cold_reboot(self):
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
self.check_appl_db(dbmgtr.appDB, expected_appl_db)
self.clear_dedicated_mock_dbs()


class TestFastUpgrade_to_2_0_5(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_2_0_5(self):
db_before_migrate = 'cross_branch_upgrade_to_2_0_5_input'
db_after_migrate = 'cross_branch_upgrade_to_2_0_5_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)

0 comments on commit 4fd2e3c

Please sign in to comment.