Skip to content

Commit d4ade57

Browse files
[202111][db_migrator] Add migration of FLEX_COUNTER_DELAY_STATUS during 1911->master upgrade + fast-reboot. Add UT.
Signed-off-by: vadymhlushko-mlnx <[email protected]>
1 parent 77bf177 commit d4ade57

6 files changed

Lines changed: 105 additions & 2 deletions

File tree

scripts/db_migrator.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,20 @@ def migrate_qos_fieldval_reference_format(self):
447447
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
448448
return True
449449

450+
def migrate_config_db_flex_counter_delay_status(self):
451+
"""
452+
Migrate "FLEX_COUNTER_TABLE|*": { "value": { "FLEX_COUNTER_DELAY_STATUS": "false" } }
453+
Set FLEX_COUNTER_DELAY_STATUS true in case of fast-reboot
454+
"""
455+
456+
flex_counter_objects = self.configDB.get_keys('FLEX_COUNTER_TABLE')
457+
for obj in flex_counter_objects:
458+
flex_counter = self.configDB.get_entry('FLEX_COUNTER_TABLE', obj)
459+
delay_status = flex_counter.get('FLEX_COUNTER_DELAY_STATUS')
460+
if delay_status is None or delay_status == 'false':
461+
flex_counter['FLEX_COUNTER_DELAY_STATUS'] = 'true'
462+
self.configDB.mod_entry('FLEX_COUNTER_TABLE', obj, flex_counter)
463+
450464
def version_unknown(self):
451465
"""
452466
version_unknown tracks all SONiC versions that doesn't have a version
@@ -627,9 +641,21 @@ def version_2_0_3(self):
627641

628642
def version_2_0_4(self):
629643
"""
630-
Current latest version. Nothing to do here.
644+
Version 2_0_4
631645
"""
632646
log.log_info('Handling version_2_0_4')
647+
648+
if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"):
649+
self.migrate_config_db_flex_counter_delay_status()
650+
651+
self.set_version('version_2_0_5')
652+
return 'version_2_0_5'
653+
654+
def version_2_0_5(self):
655+
"""
656+
Current latest version. Nothing to do here.
657+
"""
658+
log.log_info('Handling version_2_0_5')
633659
return None
634660

635661
def get_version(self):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_2_0_5"
4+
},
5+
"FLEX_COUNTER_TABLE|ACL": {
6+
"FLEX_COUNTER_STATUS": "true",
7+
"FLEX_COUNTER_DELAY_STATUS": "true",
8+
"POLL_INTERVAL": "10000"
9+
},
10+
"FLEX_COUNTER_TABLE|QUEUE": {
11+
"FLEX_COUNTER_STATUS": "true",
12+
"FLEX_COUNTER_DELAY_STATUS": "true",
13+
"POLL_INTERVAL": "10000"
14+
},
15+
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
16+
"FLEX_COUNTER_STATUS": "false",
17+
"FLEX_COUNTER_DELAY_STATUS": "true"
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_1_0_1"
4+
},
5+
"FLEX_COUNTER_TABLE|ACL": {
6+
"FLEX_COUNTER_STATUS": "true",
7+
"FLEX_COUNTER_DELAY_STATUS": "true",
8+
"POLL_INTERVAL": "10000"
9+
},
10+
"FLEX_COUNTER_TABLE|QUEUE": {
11+
"FLEX_COUNTER_STATUS": "true",
12+
"FLEX_COUNTER_DELAY_STATUS": "false",
13+
"POLL_INTERVAL": "10000"
14+
},
15+
"FLEX_COUNTER_TABLE|PG_WATERMARK": {
16+
"FLEX_COUNTER_STATUS": "false"
17+
}
18+
}

tests/db_migrator_input/config_db/reclaiming-buffer-warmreboot-expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,6 @@
20432043
"admin_status": "up"
20442044
},
20452045
"VERSIONS|DATABASE": {
2046-
"VERSION": "version_2_0_4"
2046+
"VERSION": "version_2_0_5"
20472047
}
20482048
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FAST_REBOOT|system": {
3+
"enable": "true"
4+
}
5+
}

tests/db_migrator_test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,38 @@ def test_qos_buffer_migrator_for_cold_reboot(self):
348348
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
349349
self.check_appl_db(dbmgtr.appDB, expected_appl_db)
350350
self.clear_dedicated_mock_dbs()
351+
352+
353+
class TestFastUpgrade_to_2_0_5(object):
354+
@classmethod
355+
def setup_class(cls):
356+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
357+
cls.config_db_tables_to_verify = ['FLEX_COUNTER_TABLE']
358+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_upgrade')
359+
360+
@classmethod
361+
def teardown_class(cls):
362+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
363+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
364+
dbconnector.dedicated_dbs['STATE_DB'] = None
365+
366+
def mock_dedicated_config_db(self, filename):
367+
jsonfile = os.path.join(mock_db_path, 'config_db', filename)
368+
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile
369+
db = Db()
370+
return db
371+
372+
def check_config_db(self, result, expected):
373+
for table in self.config_db_tables_to_verify:
374+
assert result.get_table(table) == expected.get_table(table)
375+
376+
def test_fast_reboot_upgrade_to_2_0_5(self):
377+
db_before_migrate = 'cross_branch_upgrade_to_2_0_5_input'
378+
db_after_migrate = 'cross_branch_upgrade_to_2_0_5_expected'
379+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
380+
db = self.mock_dedicated_config_db(db_before_migrate)
381+
import db_migrator
382+
dbmgtr = db_migrator.DBMigrator(None)
383+
dbmgtr.migrate()
384+
expected_db = self.mock_dedicated_config_db(db_after_migrate)
385+
assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)

0 commit comments

Comments
 (0)