Skip to content

Commit

Permalink
Add unit test to cover migration of routes w/o weight attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavhd committed Feb 27, 2023
1 parent 4a065b4 commit e825097
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
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"
}
}
7 changes: 7 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,7 @@
{
"LOOPBACK_INTERFACE|Loopback0|10.1.0.32/32" : {"NULL": "NULL"},
"LOOPBACK_INTERFACE|Loopback0|FC00:1::32/128" : {"NULL": "NULL"},
"LOOPBACK_INTERFACE|Loopback1|10.20.8.199/32" : {"NULL": "NULL"},
"LOOPBACK_INTERFACE|Loopback1|2001:506:28:500::1/128" : {"NULL": "NULL"},
"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

0 comments on commit e825097

Please sign in to comment.