Parse Device region field in Minigraph (#4486)

This commit is contained in:
Sumukha Tumkur Vani 2020-04-27 21:48:09 -07:00 committed by Abhishek Dosi
parent bd370fd2b6
commit 3c92bc02cd
3 changed files with 17 additions and 2 deletions

View File

@ -419,6 +419,7 @@ def parse_meta(meta, hname):
mgmt_routes = [] mgmt_routes = []
erspan_dst = [] erspan_dst = []
deployment_id = None deployment_id = None
region = None
device_metas = meta.find(str(QName(ns, "Devices"))) device_metas = meta.find(str(QName(ns, "Devices")))
for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))):
if device.find(str(QName(ns1, "Name"))).text.lower() == hname.lower(): if device.find(str(QName(ns1, "Name"))).text.lower() == hname.lower():
@ -441,7 +442,9 @@ def parse_meta(meta, hname):
erspan_dst = value_group erspan_dst = value_group
elif name == "DeploymentId": elif name == "DeploymentId":
deployment_id = value deployment_id = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id elif name == "Region":
region = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region
def parse_deviceinfo(meta, hwsku): def parse_deviceinfo(meta, hwsku):
port_speeds = {} port_speeds = {}
@ -599,6 +602,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
erspan_dst = [] erspan_dst = []
bgp_peers_with_range = None bgp_peers_with_range = None
deployment_id = None deployment_id = None
region = None
hwsku_qn = QName(ns, "HwSku") hwsku_qn = QName(ns, "HwSku")
hostname_qn = QName(ns, "Hostname") hostname_qn = QName(ns, "Hostname")
@ -623,7 +627,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
elif child.tag == str(QName(ns, "UngDec")): elif child.tag == str(QName(ns, "UngDec")):
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname) (u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
elif child.tag == str(QName(ns, "MetadataDeclaration")): elif child.tag == str(QName(ns, "MetadataDeclaration")):
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname) (syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region) = parse_meta(child, hostname)
elif child.tag == str(QName(ns, "DeviceInfos")): elif child.tag == str(QName(ns, "DeviceInfos")):
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku) (port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
@ -632,6 +636,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
results['DEVICE_METADATA'] = {'localhost': { results['DEVICE_METADATA'] = {'localhost': {
'bgp_asn': bgp_asn, 'bgp_asn': bgp_asn,
'deployment_id': deployment_id, 'deployment_id': deployment_id,
'region': region,
'docker_routing_config_mode': docker_routing_config_mode, 'docker_routing_config_mode': docker_routing_config_mode,
'hostname': hostname, 'hostname': hostname,
'hwsku': hwsku, 'hwsku': hwsku,

View File

@ -215,6 +215,11 @@
<a:Reference i:nil="true"/> <a:Reference i:nil="true"/>
<a:Value>1</a:Value> <a:Value>1</a:Value>
</a:DeviceProperty> </a:DeviceProperty>
<a:DeviceProperty>
<a:Name>Region</a:Name>
<a:Reference i:nil="true"/>
<a:Value>usfoo</a:Value>
</a:DeviceProperty>
<a:DeviceProperty> <a:DeviceProperty>
<a:Name>ErspanDestinationIpv4</a:Name> <a:Name>ErspanDestinationIpv4</a:Name>
<a:Reference i:nil="true"/> <a:Reference i:nil="true"/>

View File

@ -53,6 +53,11 @@ class TestCfgGen(TestCase):
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), 'Force10-Z9100') self.assertEqual(output.strip(), 'Force10-Z9100')
def test_minigraph_region(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'region\']" -m "' + self.sample_graph_metadata + '"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'usfoo')
def test_print_data(self): def test_print_data(self):
argument = '-m "' + self.sample_graph + '" --print-data' argument = '-m "' + self.sample_graph + '" --print-data'
output = self.run_script(argument) output = self.run_script(argument)