Skip to content

Commit 5383e92

Browse files
authored
[subinterface]Avoid removing the subinterface when last configured ip is removed (sonic-net#2181)
* Avoid removing the subinterface when last configured ip is removed Signed-off-by: Sudharsan Dhamal Gopalarathnam <[email protected]>
1 parent f5af780 commit 5383e92

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

config/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4277,7 +4277,8 @@ def remove(ctx, interface_name, ip_addr):
42774277
remove_router_interface_ip_address(config_db, interface_name, ip_address)
42784278
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
42794279
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":
4280-
config_db.set_entry(table_name, interface_name, None)
4280+
if table_name != "VLAN_SUB_INTERFACE":
4281+
config_db.set_entry(table_name, interface_name, None)
42814282

42824283
if multi_asic.is_multi_asic():
42834284
command = "sudo ip netns exec {} ip neigh flush dev {} {}".format(ctx.obj['namespace'], interface_name, str(ip_address))

tests/config_int_ip_test.py

+30
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,36 @@ def test_config_int_ip_rem_static(
105105
assert result.exit_code == 0
106106
assert mock_run_command.call_count == 1
107107

108+
@pytest.mark.parametrize('setup_single_bgp_instance',
109+
['ip_route_for_int_ip'], indirect=['setup_single_bgp_instance'])
110+
def test_config_int_ip_rem_sub_intf(
111+
self,
112+
get_cmd_module,
113+
setup_single_bgp_instance):
114+
(config, _) = get_cmd_module
115+
jsonfile_config = os.path.join(mock_db_path, "config_db")
116+
from .mock_tables import dbconnector
117+
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config
118+
119+
runner = CliRunner()
120+
db = Db()
121+
obj = {'config_db': db.cfgdb}
122+
123+
# remove vlan IP`s
124+
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
125+
print(db.cfgdb.get_table('INTERFACE'))
126+
assert ('Ethernet16.16', '16.1.1.1/16') in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
127+
assert 'Ethernet16.16' in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
128+
result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"],
129+
["Ethernet16.16", "16.1.1.1/16"], obj=obj)
130+
print(result.exit_code, result.output)
131+
assert result.exit_code == 0
132+
assert mock_run_command.call_count == 1
133+
# removing IP should only remove the INTERFACE,IP key. The regular INTERFACE key should still exists for sub interface
134+
assert ('Ethernet16.16', '16.1.1.1/16') not in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
135+
assert 'Ethernet16.16' in db.cfgdb.get_table('VLAN_SUB_INTERFACE')
136+
137+
108138
class TestIntIpMultiasic(object):
109139
@pytest.fixture(scope="class", autouse=True)
110140
def setup_class(cls):

tests/int_ip_input/config_db.json

+6
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,11 @@
3737
},
3838
"VLAN_INTERFACE|Vlan2|192.168.1.1/21": {
3939
"NULL": "NULL"
40+
},
41+
"VLAN_SUB_INTERFACE|Ethernet16.16": {
42+
"admin_status": "up"
43+
},
44+
"VLAN_SUB_INTERFACE|Ethernet16.16|16.1.1.1/16": {
45+
"NULL": "NULL"
4046
}
4147
}

0 commit comments

Comments
 (0)