From 419da041d6e7b1db8e4484bc99f8c4cd3b5828c6 Mon Sep 17 00:00:00 2001 From: anish-n <44376847+anish-n@users.noreply.github.com> Date: Mon, 12 Apr 2021 10:33:41 -0700 Subject: [PATCH] Add downstreamsubrole parsing to minigraph.py (#7193) --- src/sonic-config-engine/minigraph.py | 12 ++++++++++-- .../tests/simple-sample-graph-metadata.xml | 5 +++++ src/sonic-config-engine/tests/test_cfggen.py | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index df8f0fe3222..02bf6483d3a 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -602,6 +602,7 @@ def parse_meta(meta, hname): deployment_id = None region = None cloudtype = None + downstream_subrole = None device_metas = meta.find(str(QName(ns, "Devices"))) for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): if device.find(str(QName(ns1, "Name"))).text.lower() == hname.lower(): @@ -628,7 +629,9 @@ def parse_meta(meta, hname): region = value elif name == "CloudType": cloudtype = value - return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype + elif name == "DownStreamSubRole": + downstream_subrole = value + return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, downstream_subrole def parse_linkmeta(meta, hname): @@ -881,6 +884,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None): neighbors = None devices = None sub_role = None + downstream_subrole = None docker_routing_config_mode = "separated" port_speeds_default = {} port_speed_png = {} @@ -937,7 +941,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None): elif child.tag == str(QName(ns, "UngDec")): (u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname) elif child.tag == str(QName(ns, "MetadataDeclaration")): - (syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype) = parse_meta(child, hostname) + (syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, downstream_subrole) = parse_meta(child, hostname) elif child.tag == str(QName(ns, "LinkMetadataDeclaration")): linkmetas = parse_linkmeta(child, hostname) elif child.tag == str(QName(ns, "DeviceInfos")): @@ -985,6 +989,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None): current_device['sub_role'] = sub_role results['DEVICE_METADATA']['localhost']['sub_role'] = sub_role results['DEVICE_METADATA']['localhost']['asic_name'] = asic_name + + if downstream_subrole is not None: + results['DEVICE_METADATA']['localhost']['downstream_subrole'] = downstream_subrole + results['BGP_NEIGHBOR'] = bgp_sessions results['BGP_MONITORS'] = bgp_monitors results['BGP_PEER_RANGE'] = bgp_peers_with_range diff --git a/src/sonic-config-engine/tests/simple-sample-graph-metadata.xml b/src/sonic-config-engine/tests/simple-sample-graph-metadata.xml index d4f1b369e5a..49e3fc699ae 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph-metadata.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph-metadata.xml @@ -253,6 +253,11 @@ 10.0.10.7;10.0.10.8 + + DownStreamSubRole + + downstream_subrole_y + diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 078c45ef165..0fffab2ed02 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -78,6 +78,11 @@ def test_minigraph_cloudtype(self): output = self.run_script(argument) self.assertEqual(output.strip(), 'Public') + def test_minigraph_downstream_subrole(self): + argument = '-v "DEVICE_METADATA[\'localhost\'][\'downstream_subrole\']" -m "' + self.sample_graph_metadata + '"' + output = self.run_script(argument) + self.assertEqual(output.strip(), 'downstream_subrole_y') + def test_print_data(self): argument = '-m "' + self.sample_graph + '" --print-data' output = self.run_script(argument)