From bd7733774bdca3d553d4feecb7f960b6059072c9 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:05:18 +1000 Subject: [PATCH] [minigraph] Added support to parse "AssociatedSliceStr" attribute of minigraph (#19160) What I did: Added support to parse "AssociatedSliceStr" attribute of minigraph and save as slice_type as part of DEVICE_METADATA for Chassis Device Type. Yang model are done as part of : #19094 Also as part of this change fixed issue of current device not selected correctly as asic_hostname not being correct. Why I did: In BGP Templates we need to take different action based on this attribute. Signed-off-by: Abhishek Dosi --- src/sonic-config-engine/minigraph.py | 22 +++++++++++---- .../voq_chassis_lc_single_asic.xml | 28 +++++++++---------- .../tests/test_chassis_cfggen.py | 5 ++-- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 390410067feb..0d5d4424c208 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -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")): @@ -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): @@ -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 @@ -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")): @@ -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 @@ -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) @@ -2101,7 +2109,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw current_device = [devices[key] for key in devices if key.lower() == hostname.lower()][0] else: try: - current_device = [devices[key] for key in devices if key.lower() == asic_name.lower()][0] + current_device = [devices[key] for key in devices if key.lower() == asic_hostname.lower()][0] except: current_device = {} @@ -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': { @@ -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': { diff --git a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml index 1e80a5bcbd58..bb237ecbd79d 100644 --- a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml +++ b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml @@ -45188,7 +45188,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45215,7 +45215,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45242,7 +45242,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45269,7 +45269,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45296,7 +45296,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45323,7 +45323,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45350,7 +45350,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45377,7 +45377,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45404,7 +45404,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45431,7 +45431,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -45458,7 +45458,7 @@ ::/0 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -46133,7 +46133,7 @@ fc00:23::1/128 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -46160,7 +46160,7 @@ 2a01:111:e210:5e::/128 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production TestbedForstr-sonic @@ -46187,7 +46187,7 @@ 2a01:111:e210:5e::/128 TestbedForstr-sonic - TestbedForstr-sonic + AZNG_Production None TestbedForstr-sonic diff --git a/src/sonic-config-engine/tests/test_chassis_cfggen.py b/src/sonic-config-engine/tests/test_chassis_cfggen.py index b4cd571bd577..c309e7f2d694 100644 --- a/src/sonic-config-engine/tests/test_chassis_cfggen.py +++ b/src/sonic-config-engine/tests/test_chassis_cfggen.py @@ -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', @@ -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) \ No newline at end of file + os.remove(self.output_file)