Skip to content

Commit 9e2fbf4

Browse files
authored
Update db_migrator to support pfcwd_sw_enable (#2087)
Signed-off-by: bingwang [email protected] What I did This PR is to update db_migrator to support pfcwd_sw_enable. Currently, table pfc_enable is to specify on which queue to enable PFC and pfc watchdog. As we are going to add two extra lossless queues on which on watchdog is enable(HLD sonic-net/SONiC#950), a new field is required to specify on which queue to enable PFC watchdog. That is pfcwd_sw_enable. Field Description pfc_enable Specify on which queues to enable PFC pfcwd_sw_enable Specify on which queues to enable software PFC watchdog HLD DSCP remapping Change in orchagent Update orchagent to support new field pfcwd_sw_enable How I did it Update db_migrator. How to verify it Verified by UT Verified by copying the updated db_migrator.py to a SONiC box and run db_migrator.py -o migrate
1 parent 4010bd0 commit 9e2fbf4

File tree

4 files changed

+115
-3
lines changed

4 files changed

+115
-3
lines changed

scripts/db_migrator.py

+19-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_2_0_4'
47+
self.CURRENT_VERSION = 'version_2_0_5'
4848

4949
self.TABLE_NAME = 'VERSIONS'
5050
self.TABLE_KEY = 'DATABASE'
@@ -665,9 +665,26 @@ def version_2_0_3(self):
665665

666666
def version_2_0_4(self):
667667
"""
668-
Current latest version. Nothing to do here.
668+
Version 2_0_4
669669
"""
670670
log.log_info('Handling version_2_0_4')
671+
# Migrate "pfc_enable" to "pfc_enable" and "pfcwd_sw_enable"
672+
# 1. pfc_enable means enable pfc on certain queues
673+
# 2. pfcwd_sw_enable means enable PFC software watchdog on certain queues
674+
# By default, PFC software watchdog is enabled on all pfc enabled queues.
675+
qos_maps = self.configDB.get_table('PORT_QOS_MAP')
676+
for k, v in qos_maps.items():
677+
if 'pfc_enable' in v:
678+
v['pfcwd_sw_enable'] = v['pfc_enable']
679+
self.configDB.set_entry('PORT_QOS_MAP', k, v)
680+
681+
return 'version_2_0_5'
682+
683+
def version_2_0_5(self):
684+
"""
685+
Current latest version. Nothing to do here.
686+
"""
687+
log.log_info('Handling version_2_0_5')
671688
return None
672689

673690
def get_version(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_2_0_5"
4+
},
5+
"PORT_QOS_MAP": {
6+
"Ethernet0": {
7+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
8+
"pfc_enable": "3,4",
9+
"pfcwd_sw_enable": "3,4",
10+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
11+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
12+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
13+
},
14+
"Ethernet100": {
15+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
16+
"pfc_enable": "3,4",
17+
"pfcwd_sw_enable": "3,4",
18+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
19+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
20+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
21+
},
22+
"Ethernet92": {
23+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
24+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
25+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
26+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
27+
},
28+
"Ethernet96": {
29+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
30+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
31+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
32+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
33+
}
34+
}
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_2_0_4"
4+
},
5+
"PORT_QOS_MAP": {
6+
"Ethernet0": {
7+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
8+
"pfc_enable": "3,4",
9+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
10+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
11+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
12+
},
13+
"Ethernet100": {
14+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
15+
"pfc_enable": "3,4",
16+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
17+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
18+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
19+
},
20+
"Ethernet92": {
21+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
22+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
23+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
24+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
25+
},
26+
"Ethernet96": {
27+
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
28+
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
29+
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
30+
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
31+
}
32+
}
33+
}
34+

tests/db_migrator_test.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def setup_class(cls):
281281
def teardown_class(cls):
282282
os.environ['UTILITIES_UNIT_TESTING'] = "0"
283283
dbconnector.dedicated_dbs['CONFIG_DB'] = None
284-
284+
285285
def test_lacp_key_migrator(self):
286286
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-input')
287287
import db_migrator
@@ -348,3 +348,28 @@ 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 TestPfcEnableMigrator(object):
354+
@classmethod
355+
def setup_class(cls):
356+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
357+
358+
@classmethod
359+
def teardown_class(cls):
360+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
361+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
362+
363+
def test_pfc_enable_migrator(self):
364+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_input')
365+
import db_migrator
366+
dbmgtr = db_migrator.DBMigrator(None)
367+
dbmgtr.migrate()
368+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_expected')
369+
expected_db = Db()
370+
371+
resulting_table = dbmgtr.configDB.get_table('PORT_QOS_MAP')
372+
expected_table = expected_db.cfgdb.get_table('PORT_QOS_MAP')
373+
374+
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
375+
assert not diff

0 commit comments

Comments
 (0)