Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update db_migrator to support PORT_QOS_MAP|global #2205

Merged
merged 6 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,20 @@ def migrate_qos_fieldval_reference_format(self):
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
return True

def migrate_port_qos_map_global(self):
"""
Generate dscp_to_tc_map for switch.
"""
dscp_to_tc_map_table_names = self.configDB.get_keys('DSCP_TO_TC_MAP')
if len(dscp_to_tc_map_table_names) == 0:
return True
neethajohn marked this conversation as resolved.
Show resolved Hide resolved

qos_maps = self.configDB.get_table('PORT_QOS_MAP')
if 'global' not in qos_maps.keys():
bingwang-ms marked this conversation as resolved.
Show resolved Hide resolved
# We are unlikely to have more than 1 DSCP_TO_TC_MAP in previous versions
self.configDB.set_entry('PORT_QOS_MAP', 'global', dscp_to_tc_map_table_names[0])
self.log_info("Created entry for global DSCP_TO_TC_MAP {}".format(dscp_to_tc_map_table_names[0]))

def version_unknown(self):
"""
version_unknown tracks all SONiC versions that doesn't have a version
Expand Down Expand Up @@ -725,6 +739,8 @@ def common_migration_ops(self):
self.migrate_mgmt_ports_on_s6100()
else:
log.log_notice("Asic Type: {}, Hwsku: {}".format(self.asic_type, self.hwsku))

self.migrate_port_qos_map_global()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this in the common migration path? I thought it should be based on a version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Please take a look. Thanks


def migrate(self):
version = self.get_version()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_5"
},
"DSCP_TO_TC_MAP": {
"AZURE": {
"0": "0",
"1": "1"
}
},
"PORT_QOS_MAP": {
"global": {
"dscp_to_tc_map": "AZURE"
},
"Ethernet0": {
"dscp_to_tc_map": "AZURE",
"pfc_enable": "3,4",
"pfc_to_queue_map": "AZURE",
"tc_to_pg_map": "AZURE",
"tc_to_queue_map": "AZURE"
}
}
}
21 changes: 21 additions & 0 deletions tests/db_migrator_input/config_db/qos_map_table_global_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_2_0_5"
},
"DSCP_TO_TC_MAP": {
"AZURE": {
"0": "0",
"1": "1"
}
},
"PORT_QOS_MAP": {
"Ethernet0": {
"dscp_to_tc_map": "AZURE",
"pfc_enable": "3,4",
"pfc_to_queue_map": "AZURE",
"tc_to_pg_map": "AZURE",
"tc_to_queue_map": "AZURE"
}
}
}

25 changes: 25 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,28 @@ def test_pfc_enable_migrator(self):

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

class TestGlobalDscpToTcMapMigrator(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_global_dscp_to_tc_map_migrator(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'qos_map_table_global_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_global_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