Skip to content

Commit

Permalink
Added support to parse "AssociatedSliceStr" attribute of minigraph and
Browse files Browse the repository at this point in the history
save as `slice_type` as part of DEVICE_METADATA

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
  • Loading branch information
abdosi committed May 31, 2024
1 parent b110783 commit 0f2d26d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def parse_device(device):
deployment_id = None
cluster = None
d_subtype = None
slice_type = None

for node in device:
if node.tag == str(QName(ns, "Address")):
Expand All @@ -492,11 +493,13 @@ def parse_device(device):
cluster = node.text
elif node.tag == str(QName(ns, "SubType")):
d_subtype = node.text
elif node.tag == str(QName(ns, "AssociatedSliceStr")) and node.text and "AZNG_Production" in node.text:
slice_type = "AZNG_Production"

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

return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype)
return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type)


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

if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type) = \
parse_device(device)
device_data = {}
if hwsku != None:
device_data['hwsku'] = hwsku
Expand All @@ -654,6 +658,8 @@ def parse_png(png, hname, dpg_ecmp_content = None):
device_data['type'] = d_type
if d_subtype != None:
device_data['subtype'] = d_subtype
if slice_type != None:
device_data['slice_type'] = slice_type
devices[name] = device_data

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

if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _) = parse_device(device)
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _, slice_type) = parse_device(device)
device_data = {}
if hwsku != None:
device_data['hwsku'] = hwsku
Expand All @@ -793,6 +799,8 @@ def parse_asic_png(png, asic_name, hostname):
device_data['mgmt_addr_v6'] = mgmt_prefix_v6
if d_type != None:
device_data['type'] = d_type
if slice_type != None:
device_data['slice_type'] = slice_type
devices[name] = device_data

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

if current_device and 'slice_type' in current_device and current_device['slice_type']:
results['DEVICE_METADATA']['localhost']['slice_type'] = current_device['slice_type']

if kube_data:
results['KUBERNETES_MASTER'] = {
'SERVER': {
Expand Down Expand Up @@ -2809,7 +2820,7 @@ def get_mux_cable_entries(ports, mux_cable_ports, active_active_ports, neighbors

def parse_device_desc_xml(filename):
root = ET.parse(filename).getroot()
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _) = parse_device(root)
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _, _) = parse_device(root)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr/>
<AssociatedSliceStr/>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ClusterName/>
<DeploymentId i:nil="true"/>
Expand All @@ -938,7 +938,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr/>
<AssociatedSliceStr/>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ClusterName/>
<DeploymentId i:nil="true"/>
Expand All @@ -963,7 +963,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr/>
<AssociatedSliceStr/>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ClusterName/>
<DeploymentId i:nil="true"/>
Expand Down
2 changes: 2 additions & 0 deletions src/sonic-config-engine/tests/test_multinpu_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def test_device_asic_metadata(self):
else:
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')
self.assertEqual(output['localhost']['deployment_id'], "1")
if asic != 3:
self.assertEqual(output['localhost']['slice_type'], "AZNG_Production")

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

0 comments on commit 0f2d26d

Please sign in to comment.