Skip to content

Commit db70036

Browse files
This commit addresses below issues:
1. Short Format Subinterface getting deleted after vrf binding . Issue 10802:sonic-net/sonic-buildimage#10802 2. Do not allow short format subinterface to be created without encap vlan configuration. Issue 10878: sonic-net/sonic-buildimage#10878
1 parent 21dfe1e commit db70036

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

config/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,6 +4919,11 @@ def bind(ctx, interface_name, vrf_name):
49194919
interface_addresses = get_interface_ipaddresses(config_db, interface_name)
49204920
for ipaddress in interface_addresses:
49214921
remove_router_interface_ip_address(config_db, interface_name, ipaddress)
4922+
if interface_type == "VLAN_SUB_INTERFACE":
4923+
subintf = config_db.get_entry(interface_type, alias)
4924+
if 'vrf_name' in subintf_entry:
4925+
subintf_entry.pop('vrf')
4926+
49224927
config_db.set_entry(table_name, interface_name, None)
49234928
# When config_db del entry and then add entry with same key, the DEL will lost.
49244929
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
@@ -4930,6 +4935,10 @@ def bind(ctx, interface_name, vrf_name):
49304935
while state_db.exists(state_db.STATE_DB, _hash):
49314936
time.sleep(0.01)
49324937
state_db.close(state_db.STATE_DB)
4938+
if interface_type == "VLAN_SUB_INTERFACE":
4939+
subintf['vrf_name'] = vrfname
4940+
config_db.set_entry(interface_type, alias, subintf)
4941+
else:
49334942
config_db.set_entry(table_name, interface_name, {"vrf_name": vrf_name})
49344943

49354944
#
@@ -6682,6 +6691,18 @@ def subintf_vlan_check(config_db, parent_intf, vlan):
66826691
return True
66836692
return False
66846693

6694+
def is_subintf_shortname(intf):
6695+
if VLAN_SUB_INTERFACE_SEPARATOR in intf:
6696+
if intf.startswith("Eth"):
6697+
if intf.startswith("Ethernet"):
6698+
return False
6699+
return True
6700+
elif intf.startswith("Po"):
6701+
if intf.startswith("PortChannel"):
6702+
return False
6703+
return True
6704+
return False
6705+
66856706
@subinterface.command('add')
66866707
@click.argument('subinterface_name', metavar='<subinterface_name>', required=True)
66876708
@click.argument('vid', metavar='<vid>', required=False, type=click.IntRange(1,4094))
@@ -6727,6 +6748,8 @@ def add_subinterface(ctx, subinterface_name, vid):
67276748
subintf_dict = {}
67286749
if vid is not None:
67296750
subintf_dict.update({"vlan" : vid})
6751+
elif is_subintf_shortname(subinterface_name):
6752+
ctx.fail("{} Encap vlan is mandatory for short name subinterfaces".format(subinterface_name))
67306753

67316754
if subintf_vlan_check(config_db, get_intf_longname(interface_alias), vid) is True:
67326755
ctx.fail("Vlan {} encap already configured on other subinterface on {}".format(vid, interface_alias))

0 commit comments

Comments
 (0)