Skip to content

Commit

Permalink
[db_migrator] Add missing attribute 'weight' to route entries in APPL…
Browse files Browse the repository at this point in the history
… DB (#2691)

Fixes: 201911 to 202205 warm upgrade failure in fpmsyncd reconciliation due to missing weight attr in routes. (sonic-net/sonic-buildimage#12625)

How I did it
Check for missing attribute weight in APPLDB route entries. If found missing this attribute is added with empty value.

How to verify it
Verified on physical device. 201911 to 202205 upgrade worked fine.
  • Loading branch information
vaibhavhd authored and yxieca committed Mar 7, 2023
1 parent 69a6039 commit 4bd7d4f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@ 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(self):
"""
Handle route table migration. Migrations handled:
1. 'weight' attr in ROUTE object was introduced 202205 onwards.
Upgrade from older branch to 202205 will require this 'weight' attr to be added explicitly
"""
route_table = self.appDB.get_table("ROUTE_TABLE")
for route_prefix, route_attr in route_table.items():
if 'weight' not in route_attr:
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 @@ -851,6 +868,8 @@ def common_migration_ops(self):
else:
log.log_notice("Asic Type: {}, Hwsku: {}".format(self.asic_type, self.hwsku))

self.migrate_route_table()

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 @@ -478,3 +478,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

0 comments on commit 4bd7d4f

Please sign in to comment.