Skip to content

Commit

Permalink
[config] Add check in config interface ip command to block if the int…
Browse files Browse the repository at this point in the history
…erface is portchannel member (sonic-net#2539)

- What I did
Added a check in config interface ip command to block if the interface is portchannel member

- How I did it
Added check in config handling

- How to verify it
Added UT to verify.
  • Loading branch information
dgsudharsan authored and yxieca committed Dec 7, 2022
1 parent e53b32e commit 4b51e41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,12 @@ def add(ctx, interface_name, ip_addr, gw):
click.echo("Interface {} is a member of vlan\nAborting!".format(interface_name))
return

portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')

if interface_is_in_portchannel(portchannel_member_table, interface_name):
ctx.fail("{} is configured as a member of portchannel."
.format(interface_name))

try:
ip_address = ipaddress.ip_interface(ip_addr)
except ValueError as err:
Expand Down
12 changes: 12 additions & 0 deletions tests/ip_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ def test_add_interface_ipv4_with_leading_zeros(self):
assert result.exit_code != 0
assert ERROR_MSG in result.output

def test_ip_add_on_interface_which_is_member_of_portchannel(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb}

# config int ip add Ethernet32 100.10.10.1/24
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["add"], ["Ethernet32", "100.10.10.1/24"], obj=obj)
assert result.exit_code != 0
print(result.output)
print(result.exit_code)
assert 'Error: Ethernet32 is configured as a member of portchannel.' in result.output

''' Tests for IPv6 '''

def test_add_del_interface_valid_ipv6(self):
Expand Down

0 comments on commit 4b51e41

Please sign in to comment.