Skip to content

Commit

Permalink
[db_migrator] add required "protocol" field in ROUTE_TABLE (sonic-net…
Browse files Browse the repository at this point in the history
…#2766)

- What I did
I added requires "protocol" field due to fpmsyncd reconcile logic (WarmRestartHelper class) requires old fvs keys to match new fvs.

- How I did it
Add "protocol" field in db migration.

- How to verify it
Upgrade from older branch to new image with supported FIB pending.

The field was added by sonic-net/sonic-swss#2551.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored and pdhruv-marvell committed Aug 23, 2023
1 parent f45cff7 commit 0d7fc5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
18 changes: 12 additions & 6 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,18 +594,24 @@ 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
2. 'protocol' attr in ROUTE introduced in 202305 onwards.
WarmRestartHelper reconcile logic requires to have "protocol" field in the old dumped ROUTE_TABLE.
"""
route_table = self.appDB.get_table("ROUTE_TABLE")
for route_prefix, route_attr in route_table.items():
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)

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','')

if 'protocol' not in route_attr:
self.appDB.set(self.appDB.APPL_DB, route_key, 'protocol', '')

def update_edgezone_aggregator_config(self):
"""
Update cable length configuration in ConfigDB for T0 neighbor interfaces
Expand Down
10 changes: 6 additions & 4 deletions tests/db_migrator_input/appl_db/routes_migrate_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"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": ""
"weight": "",
"protocol": ""
},
"ROUTE_TABLE:20c0:fe28:0:80::/64": {
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
"weight": ""
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104",
"weight": "",
"protocol": ""
}
}
4 changes: 2 additions & 2 deletions tests/db_migrator_input/appl_db/routes_migrate_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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"
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e",
"ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104"
}
}
4 changes: 2 additions & 2 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def test_migrate_loopback_int(self):
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
assert not diff

class TestWarmUpgrade_without_route_weights(object):
class TestWarmUpgrade_without_required_attributes(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"
Expand All @@ -562,7 +562,7 @@ def teardown_class(cls):
dbconnector.dedicated_dbs['CONFIG_DB'] = None
dbconnector.dedicated_dbs['APPL_DB'] = None

def test_migrate_weights_for_nexthops(self):
def test_migrate_weights_protocol_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')

Expand Down

0 comments on commit 0d7fc5b

Please sign in to comment.