From 7f7f057c0033d27ec77940187f0d8d574622b59d Mon Sep 17 00:00:00 2001 From: anilkpan <47642449+anilkpan@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:28:17 -0700 Subject: [PATCH] Add check to not allow deleting PO if its member of vlan --- config/main.py | 5 +++++ tests/portchannel_test.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/config/main.py b/config/main.py index 7772bd4c2f..24082499fc 100644 --- a/config/main.py +++ b/config/main.py @@ -1851,6 +1851,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: diff --git a/tests/portchannel_test.py b/tests/portchannel_test.py index ebf77e86b5..0878f7f9aa 100644 --- a/tests/portchannel_test.py +++ b/tests/portchannel_test.py @@ -157,6 +157,18 @@ def test_delete_portchannel_member_which_is_member_of_another_po(self): assert result.exit_code != 0 assert "Error: Ethernet116 is not a member of portchannel PortChannel1001" 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"