Skip to content

Commit

Permalink
check for vxlan mapping before removing vlan (#2388)
Browse files Browse the repository at this point in the history
* [Vxlan] check for vxlan mapping before removing vlan
  • Loading branch information
ITJamie authored Sep 30, 2022
1 parent cb0edd3 commit 156257e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def del_vlan(db, vid):

if keys: # TODO: MISSING CONSTRAINT IN YANG MODEL
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)) )
else:
config_db = ValidatedConfigDBConnector(db.cfgdb)

Expand Down
24 changes: 24 additions & 0 deletions tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 156257e

Please sign in to comment.