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

check for vxlan mapping before removing vlan #2388

Merged
merged 10 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to set this restriction? will there be any ASIC failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is leaving behind vxtunnel maps in the configdb to vlans that have been removed. its messy

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)

Expand Down
26 changes: 25 additions & 1 deletion tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,35 @@ 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"], ["vtep", "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: 200 can not be removed. First remove vxlan mapping 'vtep1|map_200_Vlan200' assigned to VLAN" in result.output

def test_config_vlan_del_vlan(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb}

# del vlan with IP
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db)
print(result.exit_code)
Expand Down