diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..086dfbd517 Binary files /dev/null and b/.DS_Store differ diff --git a/config/main.py b/config/main.py index 3166f6f7bf..caae8ba91b 100644 --- a/config/main.py +++ b/config/main.py @@ -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: diff --git a/tests/portchannel_test.py b/tests/portchannel_test.py index 11e0e89e52..7c9a7b601c 100644 --- a/tests/portchannel_test.py +++ b/tests/portchannel_test.py @@ -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"