Skip to content

Commit 987dd91

Browse files
bingwang-mspreetham-singh
authored andcommitted
Update db_migrator to support PORT_QOS_MAP|global (sonic-net#2205)
Signed-off-by: bingwang <[email protected]> What I did This PR is to update the db_migrator to support generation of PORT_QOS_MAP|global. After PR sonic-net/sonic-buildimage#10565, there will be two DSCP_TO_TC_MAP DSCP_TO_TC_MAP|AZURE is the default map, which is used at port level and switch level DSCP_TO_TC_MAP|AZURE_TUNNEL is used to remap the priority of tunnel traffic in dualtor deployment To address the issue, an entry PORT_QOS_MAP|global will be added into config_db "PORT_QOS_MAP": { "global": { "dscp_to_tc_map": "AZURE" } } To handle the upgrade from older image, db_migrator is updated to generate the entry. There is no way to check if PORT_QOS_MAP|global is supported, so the migration is ran on all platforms. There is check in sonic-swss to check the switch capability code, so it will not cause issue. How I did it Update db_migrator to add a common migration step. How to verify it Verified by vstest
1 parent e523615 commit 987dd91

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

scripts/db_migrator.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, namespace, socket=None):
4444
none-zero values.
4545
build: sequentially increase within a minor version domain.
4646
"""
47-
self.CURRENT_VERSION = 'version_3_0_5'
47+
self.CURRENT_VERSION = 'version_3_0_6'
4848

4949
self.TABLE_NAME = 'VERSIONS'
5050
self.TABLE_KEY = 'DATABASE'
@@ -485,6 +485,23 @@ def migrate_qos_fieldval_reference_format(self):
485485
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
486486
return True
487487

488+
def migrate_port_qos_map_global(self):
489+
"""
490+
Generate dscp_to_tc_map for switch.
491+
"""
492+
asics_require_global_dscp_to_tc_map = ["broadcom"]
493+
if self.asic_type not in asics_require_global_dscp_to_tc_map:
494+
return
495+
dscp_to_tc_map_table_names = self.configDB.get_keys('DSCP_TO_TC_MAP')
496+
if len(dscp_to_tc_map_table_names) == 0:
497+
return
498+
499+
qos_maps = self.configDB.get_table('PORT_QOS_MAP')
500+
if 'global' not in qos_maps.keys():
501+
# We are unlikely to have more than 1 DSCP_TO_TC_MAP in previous versions
502+
self.configDB.set_entry('PORT_QOS_MAP', 'global', {"dscp_to_tc_map": dscp_to_tc_map_table_names[0]})
503+
log.log_info("Created entry for global DSCP_TO_TC_MAP {}".format(dscp_to_tc_map_table_names[0]))
504+
488505
def version_unknown(self):
489506
"""
490507
version_unknown tracks all SONiC versions that doesn't have a version
@@ -681,9 +698,17 @@ def version_3_0_4(self):
681698

682699
def version_3_0_5(self):
683700
"""
684-
Current latest version. Nothing to do here.
701+
Version 3_0_5
685702
"""
686703
log.log_info('Handling version_3_0_5')
704+
self.migrate_port_qos_map_global()
705+
return 'version_3_0_6'
706+
707+
def version_3_0_6(self):
708+
"""
709+
Current latest version. Nothing to do here.
710+
"""
711+
log.log_info('Handling version_3_0_6')
687712
return None
688713

689714
def get_version(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_3_0_6"
4+
},
5+
"DSCP_TO_TC_MAP|AZURE": {
6+
"0": "0",
7+
"1": "1"
8+
},
9+
"PORT_QOS_MAP|global": {
10+
"dscp_to_tc_map": "AZURE"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_3_0_5"
4+
},
5+
"DSCP_TO_TC_MAP|AZURE": {
6+
"0": "0",
7+
"1": "1"
8+
}
9+
}
10+

tests/db_migrator_test.py

+36
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,39 @@ def test_pfc_enable_migrator(self):
374374

375375
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
376376
assert not diff
377+
378+
class TestGlobalDscpToTcMapMigrator(object):
379+
@classmethod
380+
def setup_class(cls):
381+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
382+
383+
@classmethod
384+
def teardown_class(cls):
385+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
386+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
387+
388+
def test_global_dscp_to_tc_map_migrator(self):
389+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_global_input')
390+
import db_migrator
391+
dbmgtr = db_migrator.DBMigrator(None)
392+
dbmgtr.asic_type = "broadcom"
393+
dbmgtr.hwsku = "vs"
394+
dbmgtr.migrate()
395+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_global_expected')
396+
expected_db = Db()
397+
398+
resulting_table = dbmgtr.configDB.get_table('PORT_QOS_MAP')
399+
expected_table = expected_db.cfgdb.get_table('PORT_QOS_MAP')
400+
401+
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
402+
assert not diff
403+
404+
# Check port_qos_map|global is not generated on mellanox asic
405+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_global_input')
406+
dbmgtr_mlnx = db_migrator.DBMigrator(None)
407+
dbmgtr_mlnx.asic_type = "mellanox"
408+
dbmgtr_mlnx.hwsku = "vs"
409+
dbmgtr_mlnx.migrate()
410+
resulting_table = dbmgtr_mlnx.configDB.get_table('PORT_QOS_MAP')
411+
assert resulting_table == {}
412+

0 commit comments

Comments
 (0)