From 4b51e419e5bbfc48a4ee865de0fddc8cd50ca284 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Tue, 6 Dec 2022 01:32:17 -0800 Subject: [PATCH] [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. --- config/main.py | 6 ++++++ tests/ip_config_test.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/config/main.py b/config/main.py index bd89639bca..24d87a3737 100644 --- a/config/main.py +++ b/config/main.py @@ -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: diff --git a/tests/ip_config_test.py b/tests/ip_config_test.py index fd6b4feb9f..24d09c86e3 100644 --- a/tests/ip_config_test.py +++ b/tests/ip_config_test.py @@ -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):