Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VxLAN]Fix Vxlan delete command to throw error when there are references #2404

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
prsunny marked this conversation as resolved.
Show resolved Hide resolved
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')
Expand Down
10 changes: 10 additions & 0 deletions tests/vnet_input/config_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"VNET|Vnet_2000": {
"peer_list": "",
"vni": "2000",
"vxlan_tunnel": "tunnel1"
},
"VXLAN_TUNNEL|tunnel1": {
"src_ip": "10.10.10.10"
}
}
22 changes: 22 additions & 0 deletions tests/vxlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down