From 74bf9513e7d27b771004bb94526d8070a9158f40 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Thu, 2 Jun 2022 09:22:40 +0800 Subject: [PATCH] [cherry-pick][202012] Update db_migrator to support pfcwd_sw_enable (#2160) [cherry-pick][202012] Update db_migrator to support pfcwd_sw_enable (#2160) * Update db_migrator to support pfcwd_sw_enable Signed-off-by: bingwang --- scripts/db_migrator.py | 15 ++++++++ .../config_db/qos_map_table_expected.json | 36 +++++++++++++++++++ .../config_db/qos_map_table_input.json | 34 ++++++++++++++++++ tests/db_migrator_test.py | 24 +++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 tests/db_migrator_input/config_db/qos_map_table_expected.json create mode 100644 tests/db_migrator_input/config_db/qos_map_table_input.json diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 0f8c4ada9c..fc7dbf4a10 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -409,6 +409,18 @@ def prepare_dynamic_buffer_for_warm_reboot(self, buffer_pools=None, buffer_profi return True + def migrate_pfcwd_sw_enable_table(self): + """ + 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 + """ + 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) + def version_unknown(self): """ version_unknown tracks all SONiC versions that doesn't have a version @@ -598,6 +610,9 @@ def common_migration_ops(self): # version 2_0_1 has been occupied by 202106 if self.asic_type == "mellanox": self.mellanox_buffer_migrator.mlnx_reclaiming_unused_buffer() + + # Migrate pfcwd_sw_enable table + self.migrate_pfcwd_sw_enable_table() def migrate(self): version = self.get_version() diff --git a/tests/db_migrator_input/config_db/qos_map_table_expected.json b/tests/db_migrator_input/config_db/qos_map_table_expected.json new file mode 100644 index 0000000000..0a74fb5a7d --- /dev/null +++ b/tests/db_migrator_input/config_db/qos_map_table_expected.json @@ -0,0 +1,36 @@ +{ + "VERSIONS|DATABASE": { + "VERSION": "version_2_0_0" + }, + "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]" + } + } +} + diff --git a/tests/db_migrator_input/config_db/qos_map_table_input.json b/tests/db_migrator_input/config_db/qos_map_table_input.json new file mode 100644 index 0000000000..fb4edffe1d --- /dev/null +++ b/tests/db_migrator_input/config_db/qos_map_table_input.json @@ -0,0 +1,34 @@ +{ + "VERSIONS|DATABASE": { + "VERSION": "version_2_0_0" + }, + "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]" + } + } +} + diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index 887062619b..4c6e7a2526 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -249,3 +249,27 @@ def test_init_config_feature_migration(self): assert not diff assert not expected_db.cfgdb.get_table('CONTAINER_FEATURE') + +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