From 200dd7c3e78782d0ae7a5d76548658cf402bc8de Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Tue, 28 Mar 2023 18:17:26 +0300 Subject: [PATCH 1/2] [db_migrator] add required "protocol" field in ROUTE_TABLE Signed-off-by: Stepan Blyschak --- scripts/db_migrator.py | 21 +++++++++++++------ .../appl_db/routes_migrate_expected.json | 10 +++++---- .../appl_db/routes_migrate_input.json | 4 ++-- tests/db_migrator_test.py | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 64fddea290..c7f65d45a0 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -584,18 +584,27 @@ 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. + Since an empty value is invalid and we can't know which protocol routes have originated from from + the old dump we assume it is "bgp". Later fpmsyncd will correct this during reconciliation. """ 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', 'bgp') + + def version_unknown(self): """ version_unknown tracks all SONiC versions that doesn't have a version diff --git a/tests/db_migrator_input/appl_db/routes_migrate_expected.json b/tests/db_migrator_input/appl_db/routes_migrate_expected.json index 5cad371c31..861b75c381 100644 --- a/tests/db_migrator_input/appl_db/routes_migrate_expected.json +++ b/tests/db_migrator_input/appl_db/routes_migrate_expected.json @@ -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": "bgp" }, "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": "bgp" } } diff --git a/tests/db_migrator_input/appl_db/routes_migrate_input.json b/tests/db_migrator_input/appl_db/routes_migrate_input.json index 7249488cd6..3b93a36cf6 100644 --- a/tests/db_migrator_input/appl_db/routes_migrate_input.json +++ b/tests/db_migrator_input/appl_db/routes_migrate_input.json @@ -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" } } diff --git a/tests/db_migrator_test.py b/tests/db_migrator_test.py index e9c184d160..2bb8dfbb64 100644 --- a/tests/db_migrator_test.py +++ b/tests/db_migrator_test.py @@ -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" @@ -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') From c39cf6221563a1bed8586cb3bab631ee54c81d05 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Tue, 30 May 2023 17:44:10 +0300 Subject: [PATCH 2/2] put empty protocol value in DB Signed-off-by: Stepan Blyschak --- scripts/db_migrator.py | 4 +--- tests/db_migrator_input/appl_db/routes_migrate_expected.json | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/db_migrator.py b/scripts/db_migrator.py index 2e92a4738e..35241bd75d 100755 --- a/scripts/db_migrator.py +++ b/scripts/db_migrator.py @@ -593,8 +593,6 @@ def migrate_route_table(self): 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. - Since an empty value is invalid and we can't know which protocol routes have originated from from - the old dump we assume it is "bgp". Later fpmsyncd will correct this during reconciliation. """ route_table = self.appDB.get_table("ROUTE_TABLE") for route_prefix, route_attr in route_table.items(): @@ -609,7 +607,7 @@ def migrate_route_table(self): 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', 'bgp') + self.appDB.set(self.appDB.APPL_DB, route_key, 'protocol', '') def update_edgezone_aggregator_config(self): """ diff --git a/tests/db_migrator_input/appl_db/routes_migrate_expected.json b/tests/db_migrator_input/appl_db/routes_migrate_expected.json index 861b75c381..7f48e64e40 100644 --- a/tests/db_migrator_input/appl_db/routes_migrate_expected.json +++ b/tests/db_migrator_input/appl_db/routes_migrate_expected.json @@ -3,12 +3,12 @@ "nexthop": "10.0.0.57,10.0.0.59,10.0.0.61,10.0.0.63", "ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104", "weight": "", - "protocol": "bgp" + "protocol": "" }, "ROUTE_TABLE:20c0:fe28:0:80::/64": { "nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e", "ifname" : "PortChannel101,PortChannel102,PortChannel103,PortChannel104", "weight": "", - "protocol": "bgp" + "protocol": "" } }