Skip to content

Commit a015834

Browse files
authored
[db_migrator] Add missing attribute 'weight' to route entries in APPL 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.
1 parent cd519aa commit a015834

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

scripts/db_migrator.py

+19
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,23 @@ def migrate_port_qos_map_global(self):
579579
self.configDB.set_entry('PORT_QOS_MAP', 'global', {"dscp_to_tc_map": dscp_to_tc_map_table_names[0]})
580580
log.log_info("Created entry for global DSCP_TO_TC_MAP {}".format(dscp_to_tc_map_table_names[0]))
581581

582+
def migrate_route_table(self):
583+
"""
584+
Handle route table migration. Migrations handled:
585+
1. 'weight' attr in ROUTE object was introduced 202205 onwards.
586+
Upgrade from older branch to 202205 will require this 'weight' attr to be added explicitly
587+
"""
588+
route_table = self.appDB.get_table("ROUTE_TABLE")
589+
for route_prefix, route_attr in route_table.items():
590+
if 'weight' not in route_attr:
591+
if type(route_prefix) == tuple:
592+
# IPv6 route_prefix is returned from db as tuple
593+
route_key = "ROUTE_TABLE:" + ":".join(route_prefix)
594+
else:
595+
# IPv4 route_prefix is returned from db as str
596+
route_key = "ROUTE_TABLE:{}".format(route_prefix)
597+
self.appDB.set(self.appDB.APPL_DB, route_key, 'weight','')
598+
582599
def version_unknown(self):
583600
"""
584601
version_unknown tracks all SONiC versions that doesn't have a version
@@ -899,6 +916,8 @@ def common_migration_ops(self):
899916
else:
900917
log.log_notice("Asic Type: {}, Hwsku: {}".format(self.asic_type, self.hwsku))
901918

919+
self.migrate_route_table()
920+
902921
def migrate(self):
903922
version = self.get_version()
904923
log.log_info('Upgrading from version ' + version)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ROUTE_TABLE:192.168.104.0/25": {
3+
"nexthop": "10.0.0.57,10.0.0.59,10.0.0.61,10.0.0.63",
4+
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
5+
"weight": ""
6+
},
7+
"ROUTE_TABLE:20c0:fe28:0:80::/64": {
8+
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
9+
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
10+
"weight": ""
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ROUTE_TABLE:192.168.104.0/25": {
3+
"nexthop": "10.0.0.57,10.0.0.59,10.0.0.61,10.0.0.63",
4+
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104"
5+
},
6+
"ROUTE_TABLE:20c0:fe28:0:80::/64": {
7+
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
8+
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104"
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"VERSIONS|DATABASE": {"VERSION": "version_1_0_1"}
3+
}

tests/db_migrator_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,38 @@ def test_migrate_loopback_int(self):
518518
expected_keys = expected_appl_db.get_all(expected_appl_db.APPL_DB, key)
519519
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
520520
assert not diff
521+
522+
class TestWarmUpgrade_without_route_weights(object):
523+
@classmethod
524+
def setup_class(cls):
525+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
526+
527+
@classmethod
528+
def teardown_class(cls):
529+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
530+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
531+
dbconnector.dedicated_dbs['APPL_DB'] = None
532+
533+
def test_migrate_weights_for_nexthops(self):
534+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'routes_migrate_input')
535+
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'routes_migrate_input')
536+
537+
import db_migrator
538+
dbmgtr = db_migrator.DBMigrator(None)
539+
dbmgtr.migrate()
540+
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'routes_migrate_expected')
541+
expected_db = Db()
542+
543+
# verify migrated appDB
544+
expected_appl_db = SonicV2Connector(host='127.0.0.1')
545+
expected_appl_db.connect(expected_appl_db.APPL_DB)
546+
expected_keys = expected_appl_db.keys(expected_appl_db.APPL_DB, "ROUTE_TABLE:*")
547+
expected_keys.sort()
548+
resulting_keys = dbmgtr.appDB.keys(dbmgtr.appDB.APPL_DB, "ROUTE_TABLE:*")
549+
resulting_keys.sort()
550+
assert expected_keys == resulting_keys
551+
for key in expected_keys:
552+
resulting_keys = dbmgtr.appDB.get_all(dbmgtr.appDB.APPL_DB, key)
553+
expected_keys = expected_appl_db.get_all(expected_appl_db.APPL_DB, key)
554+
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
555+
assert not diff

0 commit comments

Comments
 (0)