Skip to content

Commit

Permalink
Handling error scenario of adding port to Vlan which is part of LAG (s…
Browse files Browse the repository at this point in the history
…onic-net#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 sonic-net#4456

Signed-off-by: Sudharsan Dhamal Gopalarathnam <[email protected]>
  • Loading branch information
dgsudharsan authored Mar 23, 2021
1 parent ae39883 commit bf46638
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
10 changes: 10 additions & 0 deletions tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit bf46638

Please sign in to comment.