From abef6e5fb20438cacb3b69c41230f79c31ec8471 Mon Sep 17 00:00:00 2001 From: "Jamie (Bear) Murphy" <1613241+ITJamie@users.noreply.github.com> Date: Fri, 30 Sep 2022 16:54:11 +0100 Subject: [PATCH] check for vxlan mapping before removing vlan (#2388) * [Vxlan] check for vxlan mapping before removing vlan --- config/vlan.py | 4 ++++ tests/vlan_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/config/vlan.py b/config/vlan.py index 80b4ff4984..60b0d7ea0b 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -60,6 +60,10 @@ def del_vlan(db, vid): if keys: ctx.fail("VLAN ID {} can not be removed. First remove all members assigned to this VLAN.".format(vid)) + vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP') + for vxmap_key, vxmap_data in vxlan_table.items(): + if vxmap_data['vlan'] == 'Vlan{}'.format(vid): + ctx.fail("vlan: {} can not be removed. First remove vxlan mapping '{}' assigned to VLAN".format(vid, '|'.join(vxmap_key)) ) db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None) diff --git a/tests/vlan_test.py b/tests/vlan_test.py index a7f533a824..241cab0c0e 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -311,6 +311,30 @@ def test_config_vlan_add_rif_portchannel_member(self): assert result.exit_code != 0 assert "Error: PortChannel0001 is a router interface!" in result.output + def test_config_vlan_with_vxlanmap_del_vlan(self): + runner = CliRunner() + db = Db() + obj = {'config_db': db.cfgdb} + + # create vlan + result = runner.invoke(config.config.commands["vlan"].commands["add"], ["1027"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + # create vxlan map + result = runner.invoke(config.config.commands["vxlan"].commands["map"].commands["add"], ["vtep1", "1027", "11027"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + # attempt to del vlan with vxlan map, should fail + result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1027"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code != 0 + assert "Error: vlan: 1027 can not be removed. First remove vxlan mapping" in result.output + def test_config_vlan_del_vlan(self): runner = CliRunner() db = Db()