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 for Chassis Device type

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
  • Loading branch information
abdosi committed May 31, 2024
1 parent c676b70 commit c862d61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
20 changes: 16 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,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if cluster:
results['DEVICE_METADATA']['localhost']['cluster'] = cluster

# Update Slice Type for T2/Chassis Role
if current_device and 'slice_type' in current_device and current_device['slice_type'] and chassis_hostname:
results['DEVICE_METADATA']['localhost']['slice_type'] = current_device['slice_type']

if kube_data:
results['KUBERNETES_MASTER'] = {
'SERVER': {
Expand Down Expand Up @@ -2809,7 +2821,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 @@ -45188,7 +45188,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45215,7 +45215,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45242,7 +45242,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45269,7 +45269,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45296,7 +45296,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45323,7 +45323,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45350,7 +45350,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45377,7 +45377,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45404,7 +45404,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45431,7 +45431,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -45458,7 +45458,7 @@
<a:IPPrefix>::/0</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand Down Expand Up @@ -46133,7 +46133,7 @@
<a:IPPrefix>fc00:23::1/128</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -46160,7 +46160,7 @@
<a:IPPrefix>2a01:111:e210:5e::/128</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr/>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand All @@ -46187,7 +46187,7 @@
<a:IPPrefix>2a01:111:e210:5e::/128</a:IPPrefix>
</AddressV6>
<AssociatedClustersStr>TestbedForstr-sonic</AssociatedClustersStr>
<AssociatedSliceStr>TestbedForstr-sonic</AssociatedSliceStr>
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
<AssociatedTagsStr>None</AssociatedTagsStr>
<ChassisInternalDevices/>
<ClusterName>TestbedForstr-sonic</ClusterName>
Expand Down
5 changes: 3 additions & 2 deletions src/sonic-config-engine/tests/test_chassis_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def test_device_metadata(self):
'sub_role': 'FrontEnd',
'switch_type': 'voq',
'switch_id': 20,
'max_cores': 64})
'max_cores': 64,
'slice_type': 'AZNG_Production'})

def test_port(self):
argument = ['-m', self.sample_graph, '-p',
Expand Down Expand Up @@ -1156,4 +1157,4 @@ def tearDown(self):
os.environ['CFGGEN_UNIT_TESTING'] = ''
os.environ['CFGGEN_UNIT_TESTING_TOPOLOGY'] = ''
if os.path.exists(self.output_file):
os.remove(self.output_file)
os.remove(self.output_file)

0 comments on commit c862d61

Please sign in to comment.