Skip to content

Commit eb64ecf

Browse files
authored
[vlan] Vlan deletion is not allowed when there are members assigned to this VLAN. (#1420)
- What I did In vlan.py , function del_vlan added validation if there is no members assigned to this VLAN. If there are members - the execution of this command is failed with error on the screen. - How I did it Added validation of the VLAN_MEMBER_CFG_TABLE with the key VLAN_ID. If there are entries with this VLAN_ID - print error: VLAN ID {} can not be removed. First remove all members assigned to this VLAN. User should remove all members assigned to this VLAN, and after that he can delete vlan. - How to verify it sudo config vlan add 200 sudo config vlan member add 200 Ethernet0 sudo config vlan del 200 In this case - you will see error as there are members assigned to this VLAN sudo config vlan member del 200 Ethernet0 sudo config vlan del 200 Will pass. Signed-off-by: allas <[email protected]>
1 parent 4e27ad7 commit eb64ecf

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)