Skip to content

Commit 4b51e41

Browse files
dgsudharsanyxieca
authored andcommitted
[config] Add check in config interface ip command to block if the interface is portchannel member (#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.
1 parent e53b32e commit 4b51e41

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

config/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -4223,6 +4223,12 @@ def add(ctx, interface_name, ip_addr, gw):
42234223
click.echo("Interface {} is a member of vlan\nAborting!".format(interface_name))
42244224
return
42254225

4226+
portchannel_member_table = config_db.get_table('PORTCHANNEL_MEMBER')
4227+
4228+
if interface_is_in_portchannel(portchannel_member_table, interface_name):
4229+
ctx.fail("{} is configured as a member of portchannel."
4230+
.format(interface_name))
4231+
42264232
try:
42274233
ip_address = ipaddress.ip_interface(ip_addr)
42284234
except ValueError as err:

tests/ip_config_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ def test_add_interface_ipv4_with_leading_zeros(self):
111111
assert result.exit_code != 0
112112
assert ERROR_MSG in result.output
113113

114+
def test_ip_add_on_interface_which_is_member_of_portchannel(self):
115+
runner = CliRunner()
116+
db = Db()
117+
obj = {'config_db':db.cfgdb}
118+
119+
# config int ip add Ethernet32 100.10.10.1/24
120+
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["add"], ["Ethernet32", "100.10.10.1/24"], obj=obj)
121+
assert result.exit_code != 0
122+
print(result.output)
123+
print(result.exit_code)
124+
assert 'Error: Ethernet32 is configured as a member of portchannel.' in result.output
125+
114126
''' Tests for IPv6 '''
115127

116128
def test_add_del_interface_valid_ipv6(self):

0 commit comments

Comments
 (0)