Skip to content

Commit 6a959e6

Browse files
authored
[202405][db_migrator] Migrate tunnel table (#3705)
* [db_migrator] Migrate tunnel table Signed-off-by: Longxiang Lyu <[email protected]>
1 parent e0a268a commit 6a959e6

File tree

5 files changed

+154
-3
lines changed

5 files changed

+154
-3
lines changed

scripts/db_migrator.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, namespace, socket=None):
5858
none-zero values.
5959
build: sequentially increase within a minor version domain.
6060
"""
61-
self.CURRENT_VERSION = 'version_202405_01'
61+
self.CURRENT_VERSION = 'version_202405_02'
6262

6363
self.TABLE_NAME = 'VERSIONS'
6464
self.TABLE_KEY = 'DATABASE'
@@ -663,6 +663,26 @@ def migrate_device_metadata(self):
663663
metadata['synchronous_mode'] = device_metadata_data.get("synchronous_mode")
664664
self.configDB.set_entry('DEVICE_METADATA', 'localhost', metadata)
665665

666+
def migrate_ipinip_tunnel(self):
667+
"""Migrate TUNNEL_DECAP_TABLE to add decap terms with TUNNEL_DECAP_TERM_TABLE."""
668+
tunnel_decap_table = self.appDB.get_table('TUNNEL_DECAP_TABLE')
669+
app_db_separator = self.appDB.get_db_separator(self.appDB.APPL_DB)
670+
for key, attrs in tunnel_decap_table.items():
671+
dst_ip = attrs.pop("dst_ip", None)
672+
src_ip = attrs.pop("src_ip", None)
673+
if dst_ip:
674+
dst_ips = dst_ip.split(",")
675+
for dip in dst_ips:
676+
decap_term_table_key = app_db_separator.join(["TUNNEL_DECAP_TERM_TABLE", key, dip])
677+
if src_ip:
678+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "src_ip", src_ip)
679+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2P")
680+
else:
681+
self.appDB.set(self.appDB.APPL_DB, decap_term_table_key, "term_type", "P2MP")
682+
683+
if dst_ip or src_ip:
684+
self.appDB.set_entry("TUNNEL_DECAP_TABLE", key, attrs)
685+
666686
def migrate_port_qos_map_global(self):
667687
"""
668688
Generate dscp_to_tc_map for switch.
@@ -1228,10 +1248,18 @@ def version_202311_03(self):
12281248

12291249
def version_202405_01(self):
12301250
"""
1231-
Version 202405_01, this version should be the final version for
1232-
master branch until 202405 branch is created.
1251+
Version 202405_01.
12331252
"""
12341253
log.log_info('Handling version_202405_01')
1254+
self.set_version('version_202405_02')
1255+
return 'version_202405_02'
1256+
1257+
def version_202405_02(self):
1258+
"""
1259+
Version 202405_02.
1260+
"""
1261+
log.log_info('Handling version_202405_02')
1262+
self.migrate_ipinip_tunnel()
12351263
return None
12361264

12371265
def get_version(self):
Lines changed: 61 additions & 0 deletions
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+
}
Lines changed: 25 additions & 0 deletions
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+
}
Lines changed: 3 additions & 0 deletions
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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,3 +1017,37 @@ def test_per_command_aaa(self, test_json):
10171017

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

0 commit comments

Comments
 (0)