From bf4663868275bcae91d385b5d030500aa04705ec Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Mon, 22 Mar 2021 20:08:13 -0700 Subject: [PATCH] Handling error scenario of adding port to Vlan which is part of LAG (#1516) *Handled error scenario when adding a port to Vlan which is already part of a LAG. Added unit test to cover the scenario. This is fix for the bug Azure/sonic-buildimage#4456 Signed-off-by: Sudharsan Dhamal Gopalarathnam --- config/vlan.py | 5 +++++ tests/vlan_test.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/config/vlan.py b/config/vlan.py index a10db74d0904..36ef3da0ac96 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)) diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 438f3acbbbae..f0559560daa6 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -674,6 +674,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):