Skip to content

Commit fe3559d

Browse files
neethajohnCarl Keene
authored and
Carl Keene
committed
[minigraph] Update parsing logic for Storage backend devices (sonic-net#7944)
Signed-off-by: Neetha John <[email protected]> Why I did it The current logic generates 'VLAN_SUB_INTERFACE' table if the device type is backend and cluster name contains 'str'. This is not a reliable method to determine a storage backend device How I did it Updated the logic to generate 'VLAN_SUB_INTERFACE' table if any of the following conditions hold true - device is of type backend and ResourceType attribute is None - device is of type backend and ResourceType attribute contains "Storage" - device is of type backend and graph contains "Subinterface" section Also updated the logic to set "is_storage_device" to True - For Backend, if any of the above conditions hold true - For Frontend, if ResourceType attribute contains "Storage" How to verify it Added new tests to verify the code changes and built sonic_config_engine-1.0-py3-none-any.whl successfully
1 parent 675b97c commit fe3559d

File tree

6 files changed

+1104
-60
lines changed

6 files changed

+1104
-60
lines changed

src/sonic-config-engine/minigraph.py

+36-12
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ def parse_png(png, hname, dpg_ecmp_content = None):
180180
port_speeds = {}
181181
console_ports = {}
182182
mux_cable_ports = {}
183-
is_storage_device = False
184183
port_device_map = {}
185184
png_ecmp_content = {}
186185
FG_NHG_MEMBER = {}
@@ -253,10 +252,6 @@ def parse_png(png, hname, dpg_ecmp_content = None):
253252
device_data['lo_addr_v6'] = lo_prefix_v6
254253
devices[name] = device_data
255254

256-
if name == hname:
257-
if cluster and "str" in cluster.lower():
258-
is_storage_device = True
259-
260255
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
261256
for if_link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
262257
if str(QName(ns3, "type")) in if_link.attrib:
@@ -293,7 +288,7 @@ def parse_png(png, hname, dpg_ecmp_content = None):
293288

294289
png_ecmp_content = {"FG_NHG_MEMBER": FG_NHG_MEMBER, "FG_NHG": FG_NHG, "NEIGH": NEIGH}
295290

296-
return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, is_storage_device, png_ecmp_content)
291+
return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content)
297292

298293

299294
def parse_asic_external_link(link, asic_name, hostname):
@@ -402,6 +397,7 @@ def parse_loopback_intf(child):
402397
def parse_dpg(dpg, hname):
403398
aclintfs = None
404399
mgmtintfs = None
400+
subintfs = None
405401
tunnelintfs = defaultdict(dict)
406402
for child in dpg:
407403
"""
@@ -441,6 +437,16 @@ def parse_dpg(dpg, hname):
441437
ip_intfs_map[ipprefix] = intfalias
442438
lo_intfs = parse_loopback_intf(child)
443439

440+
subintfs = child.find(str(QName(ns, "SubInterfaces")))
441+
if subintfs is not None:
442+
for subintf in subintfs.findall(str(QName(ns, "SubInterface"))):
443+
intfalias = subintf.find(str(QName(ns, "AttachTo"))).text
444+
intfname = port_alias_map.get(intfalias, intfalias)
445+
ipprefix = subintf.find(str(QName(ns, "Prefix"))).text
446+
subintfvlan = subintf.find(str(QName(ns, "Vlan"))).text
447+
subintfname = intfname + VLAN_SUB_INTERFACE_SEPARATOR + subintfvlan
448+
intfs[(subintfname, ipprefix)] = {}
449+
444450
mvrfConfigs = child.find(str(QName(ns, "MgmtVrfConfigs")))
445451
mvrf = {}
446452
if mvrfConfigs != None:
@@ -1207,7 +1213,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
12071213
elif child.tag == str(QName(ns, "CpgDec")):
12081214
(bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname)
12091215
elif child.tag == str(QName(ns, "PngDec")):
1210-
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, is_storage_device, png_ecmp_content) = parse_png(child, hostname, dpg_ecmp_content)
1216+
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, png_ecmp_content) = parse_png(child, hostname, dpg_ecmp_content)
12111217
elif child.tag == str(QName(ns, "UngDec")):
12121218
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname, None)
12131219
elif child.tag == str(QName(ns, "MetadataDeclaration")):
@@ -1273,9 +1279,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
12731279

12741280
results['DEVICE_METADATA']['localhost']['peer_switch'] = list(results['PEER_SWITCH'].keys())[0]
12751281

1276-
if is_storage_device:
1277-
results['DEVICE_METADATA']['localhost']['storage_device'] = "true"
1278-
12791282
# for this hostname, if sub_role is defined, add sub_role in
12801283
# device_metadata
12811284
if sub_role is not None:
@@ -1375,6 +1378,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
13751378
elif intf[0][0:11] == 'PortChannel':
13761379
pc_intfs[intf] = {}
13771380
pc_intfs[intf[0]] = {}
1381+
elif VLAN_SUB_INTERFACE_SEPARATOR in intf[0]:
1382+
vlan_sub_intfs[intf] = {}
1383+
vlan_sub_intfs[intf[0]] = {'admin_status': 'up'}
13781384
else:
13791385
phyport_intfs[intf] = {}
13801386
phyport_intfs[intf[0]] = {}
@@ -1457,6 +1463,13 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
14571463
if port[0] in ports:
14581464
ports.get(port[0])['admin_status'] = 'up'
14591465

1466+
if len(vlan_sub_intfs):
1467+
for subintf in vlan_sub_intfs:
1468+
if not isinstance(subintf, tuple):
1469+
parent_port = subintf.split(".")[0]
1470+
if parent_port in ports:
1471+
ports.get(parent_port)['admin_status'] = 'up'
1472+
14601473
for member in list(pc_members.keys()) + list(vlan_members.keys()):
14611474
port = ports.get(member[1])
14621475
if port:
@@ -1497,9 +1510,16 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
14971510

14981511
results['PORTCHANNEL_INTERFACE'] = pc_intfs
14991512

1500-
if current_device['type'] in backend_device_types and is_storage_device:
1513+
# for storage backend subinterface info present in minigraph takes precedence over ResourceType
1514+
if current_device['type'] in backend_device_types and bool(vlan_sub_intfs):
15011515
del results['INTERFACE']
15021516
del results['PORTCHANNEL_INTERFACE']
1517+
is_storage_device = True
1518+
results['VLAN_SUB_INTERFACE'] = vlan_sub_intfs
1519+
elif current_device['type'] in backend_device_types and (resource_type is None or 'Storage' in resource_type):
1520+
del results['INTERFACE']
1521+
del results['PORTCHANNEL_INTERFACE']
1522+
is_storage_device = True
15031523

15041524
for intf in phyport_intfs.keys():
15051525
if isinstance(intf, tuple):
@@ -1520,8 +1540,12 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
15201540
else:
15211541
sub_intf = pc_intf + VLAN_SUB_INTERFACE_SEPARATOR + VLAN_SUB_INTERFACE_VLAN_ID
15221542
vlan_sub_intfs[sub_intf] = {"admin_status" : "up"}
1523-
15241543
results['VLAN_SUB_INTERFACE'] = vlan_sub_intfs
1544+
elif resource_type is not None and 'Storage' in resource_type:
1545+
is_storage_device = True
1546+
1547+
if is_storage_device:
1548+
results['DEVICE_METADATA']['localhost']['storage_device'] = "true"
15251549

15261550
results['VLAN'] = vlans
15271551
results['VLAN_MEMBER'] = vlan_members

0 commit comments

Comments
 (0)