Skip to content

Commit abef6e5

Browse files
ITJamiedgsudharsan
authored andcommitted
check for vxlan mapping before removing vlan (sonic-net#2388)
* [Vxlan] check for vxlan mapping before removing vlan
1 parent e111ad4 commit abef6e5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

config/vlan.py

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def del_vlan(db, vid):
6060

6161
if keys:
6262
ctx.fail("VLAN ID {} can not be removed. First remove all members assigned to this VLAN.".format(vid))
63+
vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP')
64+
for vxmap_key, vxmap_data in vxlan_table.items():
65+
if vxmap_data['vlan'] == 'Vlan{}'.format(vid):
66+
ctx.fail("vlan: {} can not be removed. First remove vxlan mapping '{}' assigned to VLAN".format(vid, '|'.join(vxmap_key)) )
6367

6468
db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None)
6569

tests/vlan_test.py

+24
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,30 @@ def test_config_vlan_add_rif_portchannel_member(self):
311311
assert result.exit_code != 0
312312
assert "Error: PortChannel0001 is a router interface!" in result.output
313313

314+
def test_config_vlan_with_vxlanmap_del_vlan(self):
315+
runner = CliRunner()
316+
db = Db()
317+
obj = {'config_db': db.cfgdb}
318+
319+
# create vlan
320+
result = runner.invoke(config.config.commands["vlan"].commands["add"], ["1027"], obj=db)
321+
print(result.exit_code)
322+
print(result.output)
323+
assert result.exit_code == 0
324+
325+
# create vxlan map
326+
result = runner.invoke(config.config.commands["vxlan"].commands["map"].commands["add"], ["vtep1", "1027", "11027"], obj=db)
327+
print(result.exit_code)
328+
print(result.output)
329+
assert result.exit_code == 0
330+
331+
# attempt to del vlan with vxlan map, should fail
332+
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1027"], obj=db)
333+
print(result.exit_code)
334+
print(result.output)
335+
assert result.exit_code != 0
336+
assert "Error: vlan: 1027 can not be removed. First remove vxlan mapping" in result.output
337+
314338
def test_config_vlan_del_vlan(self):
315339
runner = CliRunner()
316340
db = Db()

0 commit comments

Comments
 (0)