Skip to content

Commit 349a101

Browse files
authored
[db_migrator] Migrate tunnel table (sonic-net#3704)
* [db_migrator] Migrate tunnel table Signed-off-by: Longxiang Lyu <[email protected]>
1 parent 0e327c5 commit 349a101

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

scripts/db_migrator.py

+29
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,26 @@ def migrate_device_metadata(self):
664664
metadata['synchronous_mode'] = device_metadata_data.get("synchronous_mode")
665665
self.configDB.set_entry('DEVICE_METADATA', 'localhost', metadata)
666666

667+
def migrate_ipinip_tunnel(self):
668+
"""Migrate TUNNEL_DECAP_TABLE to add decap terms with TUNNEL_DECAP_TERM_TABLE."""
669+
tunnel_decap_table = self.appDB.get_table('TUNNEL_DECAP_TABLE')
670+
app_db_separator = self.appDB.get_db_separator(self.appDB.APPL_DB)
671+
for key, attrs in tunnel_decap_table.items():
672+
dst_ip = attrs.pop("dst_ip", None)
673+
src_ip = attrs.pop("src_ip", None)
674+
if dst_ip:
675+
dst_ips = dst_ip.split(",")
676+
for dip in dst_ips:
677+
decap_term_table_key = app_db_separator.join(["TUNNEL_DECAP_TERM_TABLE", key, dip])
678+
if src_ip:
679+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "src_ip", src_ip)
680+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2P")
681+
else:
682+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2MP")
683+
684+
if dst_ip or src_ip:
685+
self.appDB.set_entry("TUNNEL_DECAP_TABLE", key, attrs)
686+
667687
def migrate_port_qos_map_global(self):
668688
"""
669689
Generate dscp_to_tc_map for switch.
@@ -1232,6 +1252,15 @@ def version_202405_01(self):
12321252
Version 202405_01.
12331253
"""
12341254
log.log_info('Handling version_202405_01')
1255+
self.set_version('version_202405_02')
1256+
return 'version_202405_02'
1257+
1258+
def version_202405_02(self):
1259+
"""
1260+
Version 202405_02.
1261+
"""
1262+
log.log_info('Handling version_202405_02')
1263+
self.migrate_ipinip_tunnel()
12351264
self.set_version('version_202411_01')
12361265
return 'version_202411_01'
12371266

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"TUNNEL_DECAP_TABLE:IPINIP_TUNNEL": {
3+
"dscp_mode": "uniform",
4+
"ecn_mode": "copy_from_outer",
5+
"ttl_mode": "pipe",
6+
"tunnel_type": "IPINIP"
7+
},
8+
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL": {
9+
"dscp_mode": "uniform",
10+
"ecn_mode": "copy_from_outer",
11+
"ttl_mode": "pipe",
12+
"tunnel_type": "IPINIP"
13+
},
14+
"TUNNEL_DECAP_TABLE:MuxTunnel0": {
15+
"dscp_mode": "uniform",
16+
"ecn_mode": "copy_from_outer",
17+
"encap_ecn_mode": "standard",
18+
"ttl_mode": "pipe",
19+
"tunnel_type": "IPINIP"
20+
},
21+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.56": {
22+
"term_type": "P2MP"
23+
},
24+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.58": {
25+
"term_type": "P2MP"
26+
},
27+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.60": {
28+
"term_type": "P2MP"
29+
},
30+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.0.0.62": {
31+
"term_type": "P2MP"
32+
},
33+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:10.1.0.32": {
34+
"term_type": "P2MP"
35+
},
36+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_TUNNEL:192.168.0.1": {
37+
"term_type": "P2MP"
38+
},
39+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00:1::32": {
40+
"term_type": "P2MP"
41+
},
42+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::71": {
43+
"term_type": "P2MP"
44+
},
45+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::75": {
46+
"term_type": "P2MP"
47+
},
48+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::79": {
49+
"term_type": "P2MP"
50+
},
51+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc00::7d": {
52+
"term_type": "P2MP"
53+
},
54+
"TUNNEL_DECAP_TERM_TABLE:IPINIP_V6_TUNNEL:fc02:1000::1": {
55+
"term_type": "P2MP"
56+
},
57+
"TUNNEL_DECAP_TERM_TABLE:MuxTunnel0:10.1.0.32": {
58+
"term_type": "P2P",
59+
"src_ip": "10.1.0.33"
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"TUNNEL_DECAP_TABLE:IPINIP_TUNNEL": {
3+
"dscp_mode": "uniform",
4+
"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",
5+
"ecn_mode": "copy_from_outer",
6+
"ttl_mode": "pipe",
7+
"tunnel_type": "IPINIP"
8+
},
9+
"TUNNEL_DECAP_TABLE:IPINIP_V6_TUNNEL": {
10+
"dscp_mode": "uniform",
11+
"dst_ip": "fc00:1::32,fc00::71,fc00::75,fc00::79,fc00::7d,fc02:1000::1",
12+
"ecn_mode": "copy_from_outer",
13+
"ttl_mode": "pipe",
14+
"tunnel_type": "IPINIP"
15+
},
16+
"TUNNEL_DECAP_TABLE:MuxTunnel0": {
17+
"dscp_mode": "uniform",
18+
"dst_ip": "10.1.0.32",
19+
"ecn_mode": "copy_from_outer",
20+
"encap_ecn_mode": "standard",
21+
"ttl_mode": "pipe",
22+
"tunnel_type": "IPINIP",
23+
"src_ip": "10.1.0.33"
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"VERSIONS|DATABASE": {"VERSION": "version_202311_03"}
3+
}

tests/db_migrator_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -1020,3 +1020,37 @@ def test_per_command_aaa(self, test_json):
10201020

10211021
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
10221022
assert not diff
1023+
1024+
1025+
class TestIPinIPTunnelMigrator(object):
1026+
@classmethod
1027+
def setup_class(cls):
1028+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
1029+
1030+
@classmethod
1031+
def teardown_class(cls):
1032+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
1033+
dbconnector.dedicated_dbs['APPL_DB'] = None
1034+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
1035+
1036+
def test_tunnel_migrator(self):
1037+
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'tunnel_table_input')
1038+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'tunnel_table_input')
1039+
1040+
import db_migrator
1041+
dbmgtr = db_migrator.DBMigrator(None)
1042+
dbmgtr.migrate()
1043+
1044+
dbconnector.dedicated_dbs['APPL_DB'] = os.path.join(mock_db_path, 'appl_db', 'tunnel_table_expected')
1045+
expected_appl_db = SonicV2Connector(host='127.0.0.1')
1046+
expected_appl_db.connect(expected_appl_db.APPL_DB)
1047+
expected_keys = expected_appl_db.keys(expected_appl_db.APPL_DB, "*")
1048+
resulting_keys = dbmgtr.appDB.keys(dbmgtr.appDB.APPL_DB, "*")
1049+
expected_keys.sort()
1050+
resulting_keys.sort()
1051+
assert expected_keys == resulting_keys
1052+
for key in expected_keys:
1053+
resulting_keys = dbmgtr.appDB.get_all(dbmgtr.appDB.APPL_DB, key)
1054+
expected_keys = expected_appl_db.get_all(expected_appl_db.APPL_DB, key)
1055+
diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
1056+
assert not diff

0 commit comments

Comments
 (0)