Skip to content

Commit

Permalink
Add downstreamsubrole parsing to minigraph.py (sonic-net#7193)
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-n committed May 4, 2021
1 parent 6204a1d commit 419da04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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):
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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")):
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@
<a:Reference i:nil="true"/>
<a:Value>10.0.10.7;10.0.10.8</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>DownStreamSubRole</a:Name>
<a:Reference i:nil="true"/>
<a:Value>downstream_subrole_y</a:Value>
</a:DeviceProperty>
</a:Properties>
</a:DeviceMetadata>
</Devices>
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 419da04

Please sign in to comment.