Skip to content

Commit

Permalink
Update db_migrator to support pfcwd_sw_enable (#2087)
Browse files Browse the repository at this point in the history
Signed-off-by: bingwang bingwang@microsoft.com

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
  • Loading branch information
bingwang-ms authored Apr 5, 2022
1 parent 4010bd0 commit 9e2fbf4
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
21 changes: 19 additions & 2 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, namespace, socket=None):
none-zero values.
build: sequentially increase within a minor version domain.
"""
self.CURRENT_VERSION = 'version_2_0_4'
self.CURRENT_VERSION = 'version_2_0_5'

self.TABLE_NAME = 'VERSIONS'
self.TABLE_KEY = 'DATABASE'
Expand Down Expand Up @@ -665,9 +665,26 @@ def version_2_0_3(self):

def version_2_0_4(self):
"""
Current latest version. Nothing to do here.
Version 2_0_4
"""
log.log_info('Handling version_2_0_4')
# Migrate "pfc_enable" to "pfc_enable" and "pfcwd_sw_enable"
# 1. pfc_enable means enable pfc on certain queues
# 2. pfcwd_sw_enable means enable PFC software watchdog on certain queues
# By default, PFC software watchdog is enabled on all pfc enabled queues.
qos_maps = self.configDB.get_table('PORT_QOS_MAP')
for k, v in qos_maps.items():
if 'pfc_enable' in v:
v['pfcwd_sw_enable'] = v['pfc_enable']
self.configDB.set_entry('PORT_QOS_MAP', k, v)

return 'version_2_0_5'

def version_2_0_5(self):
"""
Current latest version. Nothing to do here.
"""
log.log_info('Handling version_2_0_5')
return None

def get_version(self):
Expand Down
36 changes: 36 additions & 0 deletions tests/db_migrator_input/config_db/qos_map_table_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_5"
},
"PORT_QOS_MAP": {
"Ethernet0": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_enable": "3,4",
"pfcwd_sw_enable": "3,4",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet100": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_enable": "3,4",
"pfcwd_sw_enable": "3,4",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet92": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet96": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
}
}
}

34 changes: 34 additions & 0 deletions tests/db_migrator_input/config_db/qos_map_table_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_4"
},
"PORT_QOS_MAP": {
"Ethernet0": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_enable": "3,4",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet100": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_enable": "3,4",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet92": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
},
"Ethernet96": {
"dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]",
"pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]",
"tc_to_pg_map": "[TC_TO_PRIORITY_GROUP_MAP|AZURE]",
"tc_to_queue_map": "[TC_TO_QUEUE_MAP|AZURE]"
}
}
}

27 changes: 26 additions & 1 deletion tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def setup_class(cls):
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
dbconnector.dedicated_dbs['CONFIG_DB'] = None

def test_lacp_key_migrator(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-input')
import db_migrator
Expand Down Expand Up @@ -348,3 +348,28 @@ def test_qos_buffer_migrator_for_cold_reboot(self):
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
self.check_appl_db(dbmgtr.appDB, expected_appl_db)
self.clear_dedicated_mock_dbs()


class TestPfcEnableMigrator(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
dbconnector.dedicated_dbs['CONFIG_DB'] = None

def test_pfc_enable_migrator(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_input')
import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_expected')
expected_db = Db()

resulting_table = dbmgtr.configDB.get_table('PORT_QOS_MAP')
expected_table = expected_db.cfgdb.get_table('PORT_QOS_MAP')

diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
assert not diff

0 comments on commit 9e2fbf4

Please sign in to comment.