Skip to content

Commit aa77492

Browse files
committed
[vlan] Vlan deletion is not allowed when there are members assigned to this VLAN.
Signed-off-by: allas <[email protected]>
1 parent 9332b8e commit aa77492

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

config/vlan.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ def del_vlan(db, vid):
5353
ctx.fail("{} can not be removed. First remove IP addresses assigned to this VLAN".format(vlan))
5454

5555
keys = [ (k, v) for k, v in db.cfgdb.get_table('VLAN_MEMBER') if k == 'Vlan{}'.format(vid) ]
56-
for k in keys:
57-
db.cfgdb.set_entry('VLAN_MEMBER', k, None)
56+
57+
if keys:
58+
ctx.fail("VLAN ID {} can not be removed. First remove all members assigned to this VLAN.".format(vid))
59+
5860
db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None)
5961

6062
def restart_ndppd():

tests/vlan_test.py

+15
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,21 @@ def test_config_vlan_del_vlan(self):
337337
print(result.exit_code, result.output)
338338
assert result.exit_code != 0
339339

340+
# del vlan with IP
341+
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db)
342+
print(result.exit_code)
343+
print(result.output)
344+
assert result.exit_code != 0
345+
assert "Error: VLAN ID 1000 can not be removed. First remove all members assigned to this VLAN." in result.output
346+
347+
vlan_member = db.cfgdb.get_table('VLAN_MEMBER')
348+
keys = [ (k, v) for k, v in vlan_member if k == 'Vlan{}'.format(1000) ]
349+
for k,v in keys:
350+
result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["del"], ["1000", v], obj=db)
351+
print(result.exit_code)
352+
print(result.output)
353+
assert result.exit_code == 0
354+
340355
result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db)
341356
print(result.exit_code)
342357
print(result.output)

0 commit comments

Comments
 (0)