diff --git a/config/vxlan.py b/config/vxlan.py index bfda1f4effb..be0a9610013 100644 --- a/config/vxlan.py +++ b/config/vxlan.py @@ -38,6 +38,10 @@ def del_vxlan(db, vxlan_name): """Del VXLAN""" ctx = click.get_current_context() + vxlan_keys = db.cfgdb.get_keys('VXLAN_TUNNEL') + if vxlan_name not in vxlan_keys: + ctx.fail("Vxlan tunnel {} does not exist".format(vxlan_name)) + vxlan_keys = db.cfgdb.get_keys('VXLAN_EVPN_NVO') if not vxlan_keys: vxlan_count = 0 @@ -56,6 +60,12 @@ def del_vxlan(db, vxlan_name): if(vxlan_count > 0): ctx.fail("Please delete all VLAN VNI mappings.") + vnet_table = db.cfgdb.get_table('VNET') + vnet_keys = vnet_table.keys() + for vnet_key in vnet_keys: + if ('vxlan_tunnel' in vnet_table[vnet_key] and vnet_table[vnet_key]['vxlan_tunnel'] == vxlan_name): + ctx.fail("Please delete all VNET configuration referencing the tunnel " + vxlan_name) + db.cfgdb.set_entry('VXLAN_TUNNEL', vxlan_name, None) @vxlan.group('evpn_nvo') diff --git a/tests/vnet_input/config_db.json b/tests/vnet_input/config_db.json new file mode 100644 index 00000000000..51a75b39c90 --- /dev/null +++ b/tests/vnet_input/config_db.json @@ -0,0 +1,10 @@ +{ + "VNET|Vnet_2000": { + "peer_list": "", + "vni": "2000", + "vxlan_tunnel": "tunnel1" + }, + "VXLAN_TUNNEL|tunnel1": { + "src_ip": "10.10.10.10" + } +} diff --git a/tests/vxlan_test.py b/tests/vxlan_test.py index 5541a6e84a6..b0e50f2e32b 100644 --- a/tests/vxlan_test.py +++ b/tests/vxlan_test.py @@ -7,6 +7,10 @@ import config.main as config import show.main as show from utilities_common.db import Db +from .mock_tables import dbconnector + +test_path = os.path.dirname(os.path.abspath(__file__)) +mock_db_path = os.path.join(test_path, "vnet_input") show_vxlan_interface_output="""\ VTEP Information: @@ -247,6 +251,24 @@ def test_config_vxlan_add(self): assert result.exit_code == 0 assert result.output == show_vxlan_vlanvnimap_output + def test_config_vxlan_del(self): + dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db') + db = Db() + runner = CliRunner() + + result = runner.invoke(config.config.commands["vxlan"].commands["del"], ["tunnel_invalid"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code != 0 + assert "Error: Vxlan tunnel tunnel_invalid does not exist" in result.output + + result = runner.invoke(config.config.commands["vxlan"].commands["del"], ["tunnel1"], obj=db) + dbconnector.dedicated_dbs = {} + print(result.exit_code) + print(result.output) + assert result.exit_code != 0 + assert "Please delete all VNET configuration referencing the tunnel" in result.output + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0"