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

[db_migrator] Add missing attribute 'weight' to route entries in APPL DB #2691

Merged
merged 5 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,18 @@ def migrate_port_qos_map_global(self):
self.configDB.set_entry('PORT_QOS_MAP', 'global', {"dscp_to_tc_map": dscp_to_tc_map_table_names[0]})
log.log_info("Created entry for global DSCP_TO_TC_MAP {}".format(dscp_to_tc_map_table_names[0]))

def migrate_route_table_weights(self):
route_table = self.appDB.get_table("ROUTE_TABLE")
for route_prefix, route_attr in route_table.items():
if 'weight' not in route_attr:
Copy link
Contributor

@prsunny prsunny Mar 2, 2023

Choose a reason for hiding this comment

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

Can you also check how the subnet routes looks like? IIRC, it may not have weights today. The ones without nexthop but just ifname

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic will still add the weight attr to these routes.
It did not create an issue though, as the bootup path took two diff directions: For all other routes which do not have nexthops - weight attribute added by my logic will be removed after reconciliation.

if type(route_prefix) == tuple:
# IPv6 route_prefix is returned from db as tuple
route_key = "ROUTE_TABLE:" + ":".join(route_prefix)
else:
# IPv4 route_prefix is returned from db as str
route_key = "ROUTE_TABLE:{}".format(route_prefix)
self.appDB.set(self.appDB.APPL_DB, route_key, 'weight','')

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

self.migrate_route_table_weights()
Copy link
Contributor

Choose a reason for hiding this comment

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

since we have other functions as "migrate_copp_table", can we have a generic function like migrate_route_table so that a future changes can also be contained within this. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's a good idea. Updated now.


def migrate(self):
version = self.get_version()
log.log_info('Upgrading from version ' + version)
Expand Down
12 changes: 12 additions & 0 deletions tests/db_migrator_input/appl_db/routes_migrate_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ROUTE_TABLE:192.168.104.0/25": {
"nexthop": "10.0.0.57,10.0.0.59,10.0.0.61,10.0.0.63",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
"weight": ""
},
"ROUTE_TABLE:20c0:fe28:0:80::/64": {
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
"weight": ""
}
}
10 changes: 10 additions & 0 deletions tests/db_migrator_input/appl_db/routes_migrate_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ROUTE_TABLE:192.168.104.0/25": {
"nexthop": "10.0.0.57,10.0.0.59,10.0.0.61,10.0.0.63",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104"
},
"ROUTE_TABLE:20c0:fe28:0:80::/64": {
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104"
}
}
3 changes: 3 additions & 0 deletions tests/db_migrator_input/config_db/routes_migrate_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"VERSIONS|DATABASE": {"VERSION": "version_1_0_1"}
}
35 changes: 35 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,38 @@ def test_migrate_loopback_int(self):
expected_keys = expected_appl_db.get_all(expected_appl_db.APPL_DB, key)
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
assert not diff

class TestWarmUpgrade_without_route_weights(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
dbconnector.dedicated_dbs['APPL_DB'] = None

def test_migrate_weights_for_nexthops(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'routes_migrate_input')
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'routes_migrate_input')

import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'routes_migrate_expected')
expected_db = Db()

# verify migrated appDB
expected_appl_db = SonicV2Connector(host='127.0.0.1')
expected_appl_db.connect(expected_appl_db.APPL_DB)
expected_keys = expected_appl_db.keys(expected_appl_db.APPL_DB, "ROUTE_TABLE:*")
expected_keys.sort()
resulting_keys = dbmgtr.appDB.keys(dbmgtr.appDB.APPL_DB, "ROUTE_TABLE:*")
resulting_keys.sort()
assert expected_keys == resulting_keys
for key in expected_keys:
resulting_keys = dbmgtr.appDB.get_all(dbmgtr.appDB.APPL_DB, key)
expected_keys = expected_appl_db.get_all(expected_appl_db.APPL_DB, key)
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
assert not diff