Skip to content

Commit 7b81a5d

Browse files
dgsudharsanmdanish-kh
authored andcommitted
[VxLAN]Fix Vxlan delete command to throw error when there are references (sonic-net#2404)
*Check for VNET references for vxlan before deleting vxlan object
1 parent a517bfa commit 7b81a5d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

config/vxlan.py

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def del_vxlan(db, vxlan_name):
3838
"""Del VXLAN"""
3939
ctx = click.get_current_context()
4040

41+
vxlan_keys = db.cfgdb.get_keys('VXLAN_TUNNEL')
42+
if vxlan_name not in vxlan_keys:
43+
ctx.fail("Vxlan tunnel {} does not exist".format(vxlan_name))
44+
4145
vxlan_keys = db.cfgdb.get_keys('VXLAN_EVPN_NVO')
4246
if not vxlan_keys:
4347
vxlan_count = 0
@@ -56,6 +60,12 @@ def del_vxlan(db, vxlan_name):
5660
if(vxlan_count > 0):
5761
ctx.fail("Please delete all VLAN VNI mappings.")
5862

63+
vnet_table = db.cfgdb.get_table('VNET')
64+
vnet_keys = vnet_table.keys()
65+
for vnet_key in vnet_keys:
66+
if ('vxlan_tunnel' in vnet_table[vnet_key] and vnet_table[vnet_key]['vxlan_tunnel'] == vxlan_name):
67+
ctx.fail("Please delete all VNET configuration referencing the tunnel " + vxlan_name)
68+
5969
db.cfgdb.set_entry('VXLAN_TUNNEL', vxlan_name, None)
6070

6171
@vxlan.group('evpn_nvo')

tests/vnet_input/config_db.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"VNET|Vnet_2000": {
3+
"peer_list": "",
4+
"vni": "2000",
5+
"vxlan_tunnel": "tunnel1"
6+
},
7+
"VXLAN_TUNNEL|tunnel1": {
8+
"src_ip": "10.10.10.10"
9+
}
10+
}

tests/vxlan_test.py

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import config.main as config
88
import show.main as show
99
from utilities_common.db import Db
10+
from .mock_tables import dbconnector
11+
12+
test_path = os.path.dirname(os.path.abspath(__file__))
13+
mock_db_path = os.path.join(test_path, "vnet_input")
1014

1115
show_vxlan_interface_output="""\
1216
VTEP Information:
@@ -247,6 +251,24 @@ def test_config_vxlan_add(self):
247251
assert result.exit_code == 0
248252
assert result.output == show_vxlan_vlanvnimap_output
249253

254+
def test_config_vxlan_del(self):
255+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db')
256+
db = Db()
257+
runner = CliRunner()
258+
259+
result = runner.invoke(config.config.commands["vxlan"].commands["del"], ["tunnel_invalid"], obj=db)
260+
print(result.exit_code)
261+
print(result.output)
262+
assert result.exit_code != 0
263+
assert "Error: Vxlan tunnel tunnel_invalid does not exist" in result.output
264+
265+
result = runner.invoke(config.config.commands["vxlan"].commands["del"], ["tunnel1"], obj=db)
266+
dbconnector.dedicated_dbs = {}
267+
print(result.exit_code)
268+
print(result.output)
269+
assert result.exit_code != 0
270+
assert "Please delete all VNET configuration referencing the tunnel" in result.output
271+
250272
@classmethod
251273
def teardown_class(cls):
252274
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)