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

Add check to not allow deleting PO if its member of vlan. #2141

Merged
merged 9 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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