From 5c51e7bc63f926b007d5578fb100bfdfe817d460 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 12 Mar 2021 00:07:08 +0000 Subject: [PATCH 1/2] Handling error scenario of adding port to Vlan which is part of LAG Signed-off-by: Sudharsan Dhamal Gopalarathnam Handled error scenario when adding a port to Vlan which is already part of a LAG Fixed the config vlan script to check if port is a port channel member before setting config_db config vlan add 10 config portchannel add PortChannel0 config portchannel member add PortChannel0 Ethernet0 config vlan member add 10 Ethernet0 Usage: config vlan member add [OPTIONS] port Try "config vlan member add -h" for help. Error: Ethernet0 is part of portchannel! --- config/vlan.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/vlan.py b/config/vlan.py index a10db74d09..36ef3da0ac 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -145,6 +145,11 @@ def add_vlan_member(db, vid, port, untagged): (not is_port and clicommon.is_pc_router_interface(db.cfgdb, port)): ctx.fail("{} is a router interface!".format(port)) + portchannel_member_table = db.cfgdb.get_table('PORTCHANNEL_MEMBER') + + if (is_port and clicommon.interface_is_in_portchannel(portchannel_member_table, port)): + ctx.fail("{} is part of portchannel!".format(port)) + if (clicommon.interface_is_untagged_member(db.cfgdb, port) and untagged): ctx.fail("{} is already untagged member!".format(port)) From 1ddc287b8fca88eb6148a4768d506ea044de5827 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 16 Mar 2021 07:28:32 +0000 Subject: [PATCH 2/2] Added test case --- tests/vlan_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 8be9db1e2e..8578ac0e53 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -672,6 +672,16 @@ def test_config_set_router_port_on_member_interface(self): assert result.exit_code == 0 assert 'Interface Ethernet4 is a member of vlan' in result.output + def test_config_vlan_add_member_of_portchannel(self): + runner = CliRunner() + db = Db() + + result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["add"], \ + ["1000", "Ethernet32", "--untagged"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code != 0 + assert "Error: Ethernet32 is part of portchannel!" in result.output @classmethod def teardown_class(cls):