Skip to content

Commit 3ba8241

Browse files
[db_migtrator] Add migration of FLEX_COUNTER_DELAY_STATUS during 1911->master upgrade + fast-reboot. Add UT. (sonic-net#2839)
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 -> master. 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 fceef2e commit 3ba8241

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

scripts/db_migrator.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,20 @@ def update_edgezone_aggregator_config(self):
656656
# Set new cable length values
657657
self.configDB.set(self.configDB.CONFIG_DB, "CABLE_LENGTH|AZURE", intf, EDGEZONE_AGG_CABLE_LENGTH)
658658

659+
def migrate_config_db_flex_counter_delay_status(self):
660+
"""
661+
Migrate "FLEX_COUNTER_TABLE|*": { "value": { "FLEX_COUNTER_DELAY_STATUS": "false" } }
662+
Set FLEX_COUNTER_DELAY_STATUS true in case of fast-reboot
663+
"""
664+
665+
flex_counter_objects = self.configDB.get_keys('FLEX_COUNTER_TABLE')
666+
for obj in flex_counter_objects:
667+
flex_counter = self.configDB.get_entry('FLEX_COUNTER_TABLE', obj)
668+
delay_status = flex_counter.get('FLEX_COUNTER_DELAY_STATUS')
669+
if delay_status is None or delay_status == 'false':
670+
flex_counter['FLEX_COUNTER_DELAY_STATUS'] = 'true'
671+
self.configDB.mod_entry('FLEX_COUNTER_TABLE', obj, flex_counter)
672+
659673
def version_unknown(self):
660674
"""
661675
version_unknown tracks all SONiC versions that doesn't have a version
@@ -954,9 +968,21 @@ def version_4_0_1(self):
954968
def version_4_0_2(self):
955969
"""
956970
Version 4_0_2.
957-
This is the latest version for master branch
958971
"""
959972
log.log_info('Handling version_4_0_2')
973+
974+
if self.stateDB.keys(self.stateDB.STATE_DB, "FAST_REBOOT|system"):
975+
self.migrate_config_db_flex_counter_delay_status()
976+
977+
self.set_version('version_4_0_3')
978+
return 'version_4_0_3'
979+
980+
def version_4_0_3(self):
981+
"""
982+
Version 4_0_3.
983+
This is the latest version for master branch
984+
"""
985+
log.log_info('Handling version_4_0_3')
960986
return None
961987

962988
def get_version(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_4_0_3"
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+
}
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+
}
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

+35
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,38 @@ def test_warm_upgrade_t0_edgezone_aggregator_same_cable_length(self):
623623

624624
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
625625
assert not diff
626+
627+
628+
class TestFastUpgrade_to_4_0_3(object):
629+
@classmethod
630+
def setup_class(cls):
631+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
632+
cls.config_db_tables_to_verify = ['FLEX_COUNTER_TABLE']
633+
dbconnector.dedicated_dbs['STATE_DB'] = os.path.join(mock_db_path, 'state_db', 'fast_reboot_upgrade')
634+
635+
@classmethod
636+
def teardown_class(cls):
637+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
638+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
639+
dbconnector.dedicated_dbs['STATE_DB'] = None
640+
641+
def mock_dedicated_config_db(self, filename):
642+
jsonfile = os.path.join(mock_db_path, 'config_db', filename)
643+
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile
644+
db = Db()
645+
return db
646+
647+
def check_config_db(self, result, expected):
648+
for table in self.config_db_tables_to_verify:
649+
assert result.get_table(table) == expected.get_table(table)
650+
651+
def test_fast_reboot_upgrade_to_4_0_3(self):
652+
db_before_migrate = 'cross_branch_upgrade_to_4_0_3_input'
653+
db_after_migrate = 'cross_branch_upgrade_to_4_0_3_expected'
654+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
655+
db = self.mock_dedicated_config_db(db_before_migrate)
656+
import db_migrator
657+
dbmgtr = db_migrator.DBMigrator(None)
658+
dbmgtr.migrate()
659+
expected_db = self.mock_dedicated_config_db(db_after_migrate)
660+
assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)

0 commit comments

Comments
 (0)