Skip to content

Commit 1787410

Browse files
[202205][db_migrator] Add migration of FLEX_COUNTER_DELAY_STATUS during 1911->2211 upgrade + fast-reboot. Add UT. (#2870)
What I did Add migration of FLEX_COUNTER_DELAY_STATUS attribute of config_db FLEX_COUNTER_TABLE during the SONiC to SONiC upgrade + fast-reboot from older versions 201911 -> 202205. This change is required for the fast-reboot procedure because without it the counters will be created during the init flow which will waste a lot of resources and cause data plane degradation of more than 30 seconds. How I did it Modify the db_migrator.py. How to verify it Add UT. Signed-off-by: vadymhlushko-mlnx <[email protected]>
1 parent 43c85ef commit 1787410

5 files changed

Lines changed: 105 additions & 1 deletion

File tree

scripts/db_migrator.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,20 @@ def update_edgezone_aggregator_config(self):
636636
# Set new cable length values
637637
self.configDB.set(self.configDB.CONFIG_DB, "CABLE_LENGTH|AZURE", intf, EDGEZONE_AGG_CABLE_LENGTH)
638638

639+
def migrate_config_db_flex_counter_delay_status(self):
640+
"""
641+
Migrate "FLEX_COUNTER_TABLE|*": { "value": { "FLEX_COUNTER_DELAY_STATUS": "false" } }
642+
Set FLEX_COUNTER_DELAY_STATUS true in case of fast-reboot
643+
"""
644+
645+
flex_counter_objects = self.configDB.get_keys('FLEX_COUNTER_TABLE')
646+
for obj in flex_counter_objects:
647+
flex_counter = self.configDB.get_entry('FLEX_COUNTER_TABLE', obj)
648+
delay_status = flex_counter.get('FLEX_COUNTER_DELAY_STATUS')
649+
if delay_status is None or delay_status == 'false':
650+
flex_counter['FLEX_COUNTER_DELAY_STATUS'] = 'true'
651+
self.configDB.mod_entry('FLEX_COUNTER_TABLE', obj, flex_counter)
652+
639653
def version_unknown(self):
640654
"""
641655
version_unknown tracks all SONiC versions that doesn't have a version
@@ -885,9 +899,22 @@ def version_3_0_5(self):
885899

886900
def version_3_0_6(self):
887901
"""
888-
Current latest version. Nothing to do here.
902+
Version 3_0_6
889903
"""
890904
log.log_info('Handling version_3_0_6')
905+
906+
if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"):
907+
self.migrate_config_db_flex_counter_delay_status()
908+
909+
self.set_version('version_3_0_7')
910+
return 'version_3_0_7'
911+
912+
def version_3_0_7(self):
913+
"""
914+
Version 3_0_7
915+
Current latest version. Nothing to do here.
916+
"""
917+
log.log_info('Handling version_3_0_7')
891918
return None
892919

893920
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_3_0_7"
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+
}
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
@@ -584,3 +584,38 @@ def test_warm_upgrade_t0_edgezone_aggregator_same_cable_length(self):
584584

585585
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
586586
assert not diff
587+
588+
589+
class TestFastUpgrade_to_3_0_7(object):
590+
@classmethod
591+
def setup_class(cls):
592+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
593+
cls.config_db_tables_to_verify = ['FLEX_COUNTER_TABLE']
594+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_upgrade')
595+
596+
@classmethod
597+
def teardown_class(cls):
598+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
599+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
600+
dbconnector.dedicated_dbs['STATE_DB'] = None
601+
602+
def mock_dedicated_config_db(self, filename):
603+
jsonfile = os.path.join(mock_db_path, 'config_db', filename)
604+
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile
605+
db = Db()
606+
return db
607+
608+
def check_config_db(self, result, expected):
609+
for table in self.config_db_tables_to_verify:
610+
assert result.get_table(table) == expected.get_table(table)
611+
612+
def test_fast_reboot_upgrade_to_3_0_7(self):
613+
db_before_migrate = 'cross_branch_upgrade_to_3_0_7_input'
614+
db_after_migrate = 'cross_branch_upgrade_to_3_0_7_expected'
615+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
616+
db = self.mock_dedicated_config_db(db_before_migrate)
617+
import db_migrator
618+
dbmgtr = db_migrator.DBMigrator(None)
619+
dbmgtr.migrate()
620+
expected_db = self.mock_dedicated_config_db(db_after_migrate)
621+
assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)

0 commit comments

Comments
 (0)