Skip to content

Commit

Permalink
[subinterface]Avoid removing the subinterface when last configured ip…
Browse files Browse the repository at this point in the history
… is removed (#2181)

* Avoid removing the subinterface when last configured ip is removed
Signed-off-by: Sudharsan Dhamal Gopalarathnam <[email protected]>
  • Loading branch information
dgsudharsan authored and yxieca committed Jun 15, 2022
1 parent ed97c6f commit ce96543
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,8 @@ def remove(ctx, interface_name, ip_addr):
remove_router_interface_ip_address(config_db, interface_name, ip_address)
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
if len(interface_addresses) == 0 and is_interface_bind_to_vrf(config_db, interface_name) is False and get_intf_ipv6_link_local_mode(ctx, interface_name, table_name) != "enable":
config_db.set_entry(table_name, interface_name, None)
if table_name != "VLAN_SUB_INTERFACE":
config_db.set_entry(table_name, interface_name, None)

if multi_asic.is_multi_asic():
command = "sudo ip netns exec {} ip neigh flush dev {} {}".format(ctx.obj['namespace'], interface_name, str(ip_address))
Expand Down
30 changes: 30 additions & 0 deletions tests/config_int_ip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ def test_config_int_ip_rem_static(
assert result.exit_code == 0
assert mock_run_command.call_count == 1

@pytest.mark.parametrize('setup_single_bgp_instance',
['ip_route_for_int_ip'], indirect=['setup_single_bgp_instance'])
def test_config_int_ip_rem_sub_intf(
self,
get_cmd_module,
setup_single_bgp_instance):
(config, _) = get_cmd_module
jsonfile_config = os.path.join(mock_db_path, "config_db")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

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

# remove vlan IP`s
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
print(db.cfgdb.get_table('INTERFACE'))
assert ('Ethernet16.16', '16.1.1.1/16') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
assert 'Ethernet16.16' in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"],
["Ethernet16.16", "16.1.1.1/16"], obj=obj)
print(result.exit_code, result.output)
assert result.exit_code == 0
assert mock_run_command.call_count == 1
# removing IP should only remove the INTERFACE,IP key. The regular INTERFACE key should still exists for sub interface
assert ('Ethernet16.16', '16.1.1.1/16') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
assert 'Ethernet16.16' in db.cfgdb.get_table('VLAN_SUB_INTERFACE')


class TestIntIpMultiasic(object):
@pytest.fixture(scope="class", autouse=True)
def setup_class(cls):
Expand Down
6 changes: 6 additions & 0 deletions tests/int_ip_input/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@
},
"VLAN_INTERFACE|Vlan2|192.168.1.1/21": {
"NULL": "NULL"
},
"VLAN_SUB_INTERFACE|Ethernet16.16": {
"admin_status": "up"
},
"VLAN_SUB_INTERFACE|Ethernet16.16|16.1.1.1/16": {
"NULL": "NULL"
}
}

0 comments on commit ce96543

Please sign in to comment.