Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,26 @@ def migrate_device_metadata(self):
metadata['synchronous_mode'] = device_metadata_data.get("synchronous_mode")
self.configDB.set_entry('DEVICE_METADATA', 'localhost', metadata)

def migrate_ipinip_tunnel(self):
"""Migrate TUNNEL_DECAP_TABLE to add decap terms with TUNNEL_DECAP_TERM_TABLE."""
tunnel_decap_table = self.appDB.get_table('TUNNEL_DECAP_TABLE')
app_db_separator = self.appDB.get_db_separator(self.appDB.APPL_DB)
for key, attrs in tunnel_decap_table.items():
dst_ip = attrs.pop("dst_ip", None)
src_ip = attrs.pop("src_ip", None)
if dst_ip:
dst_ips = dst_ip.split(",")
for dip in dst_ips:
decap_term_table_key = app_db_separator.join(["TUNNEL_DECAP_TERM_TABLE", key, dip])
if src_ip:
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "src_ip", src_ip)
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2P")
else:
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2MP")

if dst_ip or src_ip:
self.appDB.set_entry("TUNNEL_DECAP_TABLE", key, attrs)

def migrate_port_qos_map_global(self):
"""
Generate dscp_to_tc_map for switch.
Expand Down Expand Up @@ -1242,6 +1262,15 @@ def version_202405_01(self):
Version 202405_01.
"""
log.log_info('Handling version_202405_01')
self.set_version('version_202405_02')
return 'version_202405_02'

def version_202405_02(self):
"""
Version 202405_02.
"""
log.log_info('Handling version_202405_02')
self.migrate_ipinip_tunnel()
self.set_version('version_202411_01')
return 'version_202411_01'

Expand Down
61 changes: 61 additions & 0 deletions tests/db_migrator_input/appl_db/tunnel_table_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"TUNNEL_DECAP_TABLE:IPINIP_TUNNEL": {
"dscp_mode": "uniform",
"ecn_mode": "copy_from_outer",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
},
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL": {
"dscp_mode": "uniform",
"ecn_mode": "copy_from_outer",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
},
"TUNNEL_DECAP_TABLE:MuxTunnel0": {
"dscp_mode": "uniform",
"ecn_mode": "copy_from_outer",
"encap_ecn_mode": "standard",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.56": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.58": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.60": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.62": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.1.0.32": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:192.168.0.1": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00:1::32": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::71": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::75": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::79": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::7d": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc02:1000::1": {
"term_type": "P2MP"
},
"TUNNEL_DECAP_TERM_TABLE:MuxTunnel0:10.1.0.32": {
"term_type": "P2P",
"src_ip": "10.1.0.33"
}
}
25 changes: 25 additions & 0 deletions tests/db_migrator_input/appl_db/tunnel_table_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"TUNNEL_DECAP_TABLE:IPINIP_TUNNEL": {
"dscp_mode": "uniform",
"dst_ip": "10.0.0.56,10.0.0.58,10.0.0.60,10.0.0.62,10.1.0.32,192.168.0.1",
"ecn_mode": "copy_from_outer",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
},
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL": {
"dscp_mode": "uniform",
"dst_ip": "fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d,fc02:1000::1",
"ecn_mode": "copy_from_outer",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP"
},
"TUNNEL_DECAP_TABLE:MuxTunnel0": {
"dscp_mode": "uniform",
"dst_ip": "10.1.0.32",
"ecn_mode": "copy_from_outer",
"encap_ecn_mode": "standard",
"ttl_mode": "pipe",
"tunnel_type": "IPINIP",
"src_ip": "10.1.0.33"
}
}
3 changes: 3 additions & 0 deletions tests/db_migrator_input/config_db/tunnel_table_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"VERSIONS|DATABASE": {"VERSION": "version_202311_03"}
}
34 changes: 34 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,37 @@ def test_per_command_aaa(self, test_json):

diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
assert not diff


class TestIPinIPTunnelMigrator(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['APPL_DB'] = None
dbconnector.dedicated_dbs['CONFIG_DB'] = None

def test_tunnel_migrator(self):
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'tunnel_table_input')
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'tunnel_table_input')

import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()

dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'tunnel_table_expected')
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, "*")
resulting_keys = dbmgtr.appDB.keys(dbmgtr.appDB.APPL_DB, "*")
expected_keys.sort()
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
Loading