Skip to content

Commit 0f2d26d

Browse files
committed
Added support to parse "AssociatedSliceStr" attribute of minigraph and
save as `slice_type` as part of DEVICE_METADATA Signed-off-by: Abhishek Dosi <[email protected]>
1 parent b110783 commit 0f2d26d

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/sonic-config-engine/minigraph.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def parse_device(device):
470470
deployment_id = None
471471
cluster = None
472472
d_subtype = None
473+
slice_type = None
473474

474475
for node in device:
475476
if node.tag == str(QName(ns, "Address")):
@@ -492,11 +493,13 @@ def parse_device(device):
492493
cluster = node.text
493494
elif node.tag == str(QName(ns, "SubType")):
494495
d_subtype = node.text
496+
elif node.tag == str(QName(ns, "AssociatedSliceStr")) and node.text and "AZNG_Production" in node.text:
497+
slice_type = "AZNG_Production"
495498

496499
if d_type is None and str(QName(ns3, "type")) in device.attrib:
497500
d_type = device.attrib[str(QName(ns3, "type"))]
498501

499-
return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype)
502+
return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type)
500503

501504

502505
def calculate_lcm_for_ecmp (nhdevices_bank_map, nhip_bank_map):
@@ -634,7 +637,8 @@ def parse_png(png, hname, dpg_ecmp_content = None):
634637

635638
if child.tag == str(QName(ns, "Devices")):
636639
for device in child.findall(str(QName(ns, "Device"))):
637-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
640+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type) = \
641+
parse_device(device)
638642
device_data = {}
639643
if hwsku != None:
640644
device_data['hwsku'] = hwsku
@@ -654,6 +658,8 @@ def parse_png(png, hname, dpg_ecmp_content = None):
654658
device_data['type'] = d_type
655659
if d_subtype != None:
656660
device_data['subtype'] = d_subtype
661+
if slice_type != None:
662+
device_data['slice_type'] = slice_type
657663
devices[name] = device_data
658664

659665
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
@@ -775,7 +781,7 @@ def parse_asic_png(png, asic_name, hostname):
775781

776782
if child.tag == str(QName(ns, "Devices")):
777783
for device in child.findall(str(QName(ns, "Device"))):
778-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _) = parse_device(device)
784+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _, slice_type) = parse_device(device)
779785
device_data = {}
780786
if hwsku != None:
781787
device_data['hwsku'] = hwsku
@@ -793,6 +799,8 @@ def parse_asic_png(png, asic_name, hostname):
793799
device_data['mgmt_addr_v6'] = mgmt_prefix_v6
794800
if d_type != None:
795801
device_data['type'] = d_type
802+
if slice_type != None:
803+
device_data['slice_type'] = slice_type
796804
devices[name] = device_data
797805

798806
return (neighbors, devices, port_speeds)
@@ -2137,6 +2145,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
21372145
if cluster:
21382146
results['DEVICE_METADATA']['localhost']['cluster'] = cluster
21392147

2148+
if current_device and 'slice_type' in current_device and current_device['slice_type']:
2149+
results['DEVICE_METADATA']['localhost']['slice_type'] = current_device['slice_type']
2150+
21402151
if kube_data:
21412152
results['KUBERNETES_MASTER'] = {
21422153
'SERVER': {
@@ -2809,7 +2820,7 @@ def get_mux_cable_entries(ports, mux_cable_ports, active_active_ports, neighbors
28092820

28102821
def parse_device_desc_xml(filename):
28112822
root = ET.parse(filename).getroot()
2812-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _) = parse_device(root)
2823+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _, _) = parse_device(root)
28132824

28142825
results = {}
28152826
results['DEVICE_METADATA'] = {'localhost': {

src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@
913913
<a:IPPrefix>::/0</a:IPPrefix>
914914
</AddressV6>
915915
<AssociatedClustersStr/>
916-
<AssociatedSliceStr/>
916+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
917917
<AssociatedTagsStr/>
918918
<ClusterName/>
919919
<DeploymentId i:nil="true"/>
@@ -938,7 +938,7 @@
938938
<a:IPPrefix>::/0</a:IPPrefix>
939939
</AddressV6>
940940
<AssociatedClustersStr/>
941-
<AssociatedSliceStr/>
941+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
942942
<AssociatedTagsStr/>
943943
<ClusterName/>
944944
<DeploymentId i:nil="true"/>
@@ -963,7 +963,7 @@
963963
<a:IPPrefix>::/0</a:IPPrefix>
964964
</AddressV6>
965965
<AssociatedClustersStr/>
966-
<AssociatedSliceStr/>
966+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
967967
<AssociatedTagsStr/>
968968
<ClusterName/>
969969
<DeploymentId i:nil="true"/>

src/sonic-config-engine/tests/test_multinpu_cfggen.py

+2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ def test_device_asic_metadata(self):
342342
else:
343343
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')
344344
self.assertEqual(output['localhost']['deployment_id'], "1")
345+
if asic != 3:
346+
self.assertEqual(output['localhost']['slice_type'], "AZNG_Production")
345347

346348
def test_global_asic_acl(self):
347349
argument = ["-m", self.sample_graph, "-p", self.sample_port_config, "--var-json", "ACL_TABLE"]

0 commit comments

Comments
 (0)