Skip to content

Commit

Permalink
Add check to not allow deleting PO if its member of vlan. (#2141)
Browse files Browse the repository at this point in the history
* Added check to not allow deleting PO if its member of vlan.
  • Loading branch information
anilkpan committed Jun 2, 2022
1 parent 2513da1 commit 3197f39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,11 @@ def remove_portchannel(ctx, portchannel_name):
if is_portchannel_present_in_db(db, portchannel_name) is False:
ctx.fail("{} is not present.".format(portchannel_name))

# Dont let to remove port channel if vlan membership exists
for k,v in db.get_table('VLAN_MEMBER'):
if v == portchannel_name:
ctx.fail("{} has vlan {} configured, remove vlan membership to proceed".format(portchannel_name, str(k)))

if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
click.echo("Error: Portchannel {} contains members. Remove members before deleting Portchannel!".format(portchannel_name))
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/portchannel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ def test_add_portchannel_member_with_pbh_bindngs(self):
assert result.exit_code != 0
assert "Error: Port Ethernet60 is already bound to following PBH_TABLES:" in result.output

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

# try to delete the portchannel when its member of a vlan
result = runner.invoke(config.config.commands["portchannel"].commands["del"], ["PortChannel1001"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert "PortChannel1001 has vlan Vlan4000 configured, remove vlan membership to proceed" in result.output

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down

0 comments on commit 3197f39

Please sign in to comment.