From 1e387f1189587590c6f3a94e62e37452a8145761 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 18 Jul 2022 07:10:13 -0700 Subject: [PATCH] Added Support for deployment_id parsing for Device Asic metadata (#11454) What I did: Added Support for deployment_id parsing for Device Asic metadata. Why I did:- Deployment Id is used in BGP docker for FRR template generation. For multi-asic platforms running in namespace without deployment id as key in DEVICE_METADATA FRR template generation fails. This change is needed after this #10154 where if deployment_id is none we don't update DEVICE_METADA dictionary. How I verify:- Added unit-test. --- src/sonic-config-engine/minigraph.py | 11 ++++--- .../tests/multi_npu_data/sample-minigraph.xml | 31 +++++++++++++++++++ .../tests/test_multinpu_cfggen.py | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index a05880e522..ee6a84183e 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -1041,6 +1041,7 @@ def parse_asic_meta(meta, hname): switch_id = None switch_type = None max_cores = None + deployment_id = None macsec_profile = {} device_metas = meta.find(str(QName(ns, "Devices"))) for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): @@ -1057,10 +1058,12 @@ def parse_asic_meta(meta, hname): switch_type = value elif name == "MaxCores": max_cores = value + elif name == "DeploymentId": + deployment_id = value elif name == 'MacSecProfile': macsec_profile = parse_macsec_profile(value) - return sub_role, switch_id, switch_type, max_cores, macsec_profile + return sub_role, switch_id, switch_type, max_cores, deployment_id, macsec_profile def parse_deviceinfo(meta, hwsku): port_speeds = {} @@ -1414,7 +1417,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw elif child.tag == str(QName(ns, "PngDec")): (neighbors, devices, port_speed_png) = parse_asic_png(child, asic_name, hostname) elif child.tag == str(QName(ns, "MetadataDeclaration")): - (sub_role, switch_id, switch_type, max_cores, macsec_profile) = parse_asic_meta(child, asic_name) + (sub_role, switch_id, switch_type, max_cores, deployment_id, macsec_profile) = parse_asic_meta(child, asic_name) elif child.tag == str(QName(ns, "LinkMetadataDeclaration")): linkmetas = parse_linkmeta(child, hostname) elif child.tag == str(QName(ns, "DeviceInfos")): @@ -1989,7 +1992,7 @@ def parse_asic_sub_role(filename, asic_name): root = ET.parse(filename).getroot() for child in root: if child.tag == str(QName(ns, "MetadataDeclaration")): - sub_role, _, _, _, _= parse_asic_meta(child, asic_name) + sub_role, _, _, _, _, _= parse_asic_meta(child, asic_name) return sub_role def parse_asic_switch_type(filename, asic_name): @@ -1997,7 +2000,7 @@ def parse_asic_switch_type(filename, asic_name): root = ET.parse(filename).getroot() for child in root: if child.tag == str(QName(ns, "MetadataDeclaration")): - _, _, switch_type, _, _ = parse_asic_meta(child, asic_name) + _, _, switch_type, _, _, _ = parse_asic_meta(child, asic_name) return switch_type return None diff --git a/src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml b/src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml index 935d2c0c83..be3938f24b 100644 --- a/src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml +++ b/src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml @@ -1465,6 +1465,11 @@ FrontEnd + + DeploymentId + + 1 + @@ -1475,6 +1480,11 @@ FrontEnd + + DeploymentId + + 1 + @@ -1485,6 +1495,11 @@ FrontEnd + + DeploymentId + + 1 + @@ -1495,6 +1510,11 @@ FrontEnd + + DeploymentId + + 1 + @@ -1505,6 +1525,11 @@ BackEnd + + DeploymentId + + 1 + @@ -1515,6 +1540,12 @@ BackEnd + + DeploymentId + + 1 + + diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index 35c2000c0e..a34b0b6cfd 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -304,6 +304,7 @@ class TestMultiNpuCfgGen(TestCase): self.assertEqual(output['localhost']['sub_role'], 'FrontEnd') else: self.assertEqual(output['localhost']['sub_role'], 'BackEnd') + self.assertEqual(output['localhost']['deployment_id'], "1") def test_global_asic_acl(self): argument = "-m {} -p {} --var-json \"ACL_TABLE\"".format(self.sample_graph, self.sample_port_config)