[minigraph.py] add support to parse deployment id of neighbor devices (#1890)
* [minigraph.py] add support to parse deployment id of neighbor devices * Add unitest * Fix function name
This commit is contained in:
parent
33b713e7ef
commit
3d137654be
@ -41,6 +41,7 @@ def parse_device(device):
|
|||||||
d_type = None # don't shadow type()
|
d_type = None # don't shadow type()
|
||||||
hwsku = None
|
hwsku = None
|
||||||
name = None
|
name = None
|
||||||
|
deployment_id = None
|
||||||
if str(QName(ns3, "type")) in device.attrib:
|
if str(QName(ns3, "type")) in device.attrib:
|
||||||
d_type = device.attrib[str(QName(ns3, "type"))]
|
d_type = device.attrib[str(QName(ns3, "type"))]
|
||||||
|
|
||||||
@ -53,7 +54,9 @@ def parse_device(device):
|
|||||||
name = node.text
|
name = node.text
|
||||||
elif node.tag == str(QName(ns, "HwSku")):
|
elif node.tag == str(QName(ns, "HwSku")):
|
||||||
hwsku = node.text
|
hwsku = node.text
|
||||||
return (lo_prefix, mgmt_prefix, name, hwsku, d_type)
|
elif node.tag == str(QName(ns, "DeploymentId")):
|
||||||
|
deployment_id = node.text
|
||||||
|
return (lo_prefix, mgmt_prefix, name, hwsku, d_type, deployment_id)
|
||||||
|
|
||||||
def parse_png(png, hname):
|
def parse_png(png, hname):
|
||||||
neighbors = {}
|
neighbors = {}
|
||||||
@ -92,8 +95,10 @@ def parse_png(png, hname):
|
|||||||
|
|
||||||
if child.tag == str(QName(ns, "Devices")):
|
if child.tag == str(QName(ns, "Devices")):
|
||||||
for device in child.findall(str(QName(ns, "Device"))):
|
for device in child.findall(str(QName(ns, "Device"))):
|
||||||
(lo_prefix, mgmt_prefix, name, hwsku, d_type) = parse_device(device)
|
(lo_prefix, mgmt_prefix, name, hwsku, d_type, deployment_id) = parse_device(device)
|
||||||
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
|
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
|
||||||
|
if deployment_id:
|
||||||
|
device_data['deployment_id'] = deployment_id
|
||||||
devices[name] = device_data
|
devices[name] = device_data
|
||||||
|
|
||||||
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
|
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
|
||||||
@ -546,7 +551,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
|
|||||||
|
|
||||||
def parse_device_desc_xml(filename):
|
def parse_device_desc_xml(filename):
|
||||||
root = ET.parse(filename).getroot()
|
root = ET.parse(filename).getroot()
|
||||||
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)
|
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type, _) = parse_device(root)
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
results['DEVICE_METADATA'] = {'localhost': {
|
results['DEVICE_METADATA'] = {'localhost': {
|
||||||
|
@ -181,27 +181,33 @@
|
|||||||
</DeviceDataPlaneInfo>
|
</DeviceDataPlaneInfo>
|
||||||
</DpgDec>
|
</DpgDec>
|
||||||
<PngDec>
|
<PngDec>
|
||||||
<DeviceInterfaceLinks/>
|
<DeviceInterfaceLinks>
|
||||||
|
<DeviceLinkBase i:type="DeviceInterfaceLink">
|
||||||
|
<ElementType>DeviceInterfaceLink</ElementType>
|
||||||
|
<AutoNegotiation>true</AutoNegotiation>
|
||||||
|
<Bandwidth>10000</Bandwidth>
|
||||||
|
<EndDevice>switch-t0</EndDevice>
|
||||||
|
<EndPort>fortyGigE0/0</EndPort>
|
||||||
|
<StartDevice>switch-01t1</StartDevice>
|
||||||
|
<StartPort>port1</StartPort>
|
||||||
|
</DeviceLinkBase>
|
||||||
|
</DeviceInterfaceLinks>
|
||||||
<Devices>
|
<Devices>
|
||||||
<Device i:type="ToRRouter">
|
<Device i:type="ToRRouter">
|
||||||
<Hostname>switch-t0</Hostname>
|
<Hostname>switch-t0</Hostname>
|
||||||
<HwSku>Force10-S6000</HwSku>
|
<HwSku>Force10-S6000</HwSku>
|
||||||
</Device>
|
</Device>
|
||||||
<Device i:type="LeafRouter">
|
<Device i:type="LeafRouter">
|
||||||
<Hostname>ARISTA01T1</Hostname>
|
<Hostname>switch-01t1</Hostname>
|
||||||
<HwSku>Arista</HwSku>
|
<Address xmlns:a="Microsoft.Search.Autopilot.NetMux">
|
||||||
</Device>
|
<a:IPPrefix>10.1.0.186/32</a:IPPrefix>
|
||||||
<Device i:type="LeafRouter">
|
</Address>
|
||||||
<Hostname>ARISTA02T1</Hostname>
|
<DeploymentId>2</DeploymentId>
|
||||||
<HwSku>Arista</HwSku>
|
<DeviceLocation i:nil="true"/>
|
||||||
</Device>
|
<ManagementAddress xmlns:a="Microsoft.Search.Autopilot.NetMux">
|
||||||
<Device i:type="LeafRouter">
|
<a:IPPrefix>10.7.0.196/26</a:IPPrefix>
|
||||||
<Hostname>ARISTA03T1</Hostname>
|
</ManagementAddress>
|
||||||
<HwSku>Arista</HwSku>
|
<HwSku>Force10-S6000</HwSku>
|
||||||
</Device>
|
|
||||||
<Device i:type="LeafRouter">
|
|
||||||
<Hostname>ARISTA04T1</Hostname>
|
|
||||||
<HwSku>Arista</HwSku>
|
|
||||||
</Device>
|
</Device>
|
||||||
</Devices>
|
</Devices>
|
||||||
</PngDec>
|
</PngDec>
|
||||||
|
@ -94,6 +94,11 @@ class TestCfgGenCaseInsensitive(TestCase):
|
|||||||
output = self.run_script(argument)
|
output = self.run_script(argument)
|
||||||
self.assertEqual(output.strip(), "1")
|
self.assertEqual(output.strip(), "1")
|
||||||
|
|
||||||
|
def test_minigraph_neighbor_metadata(self):
|
||||||
|
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR_METADATA"'
|
||||||
|
output = self.run_script(argument)
|
||||||
|
self.assertEqual(output.strip(), "{'switch-01t1': {'lo_addr': '10.1.0.186/32', 'mgmt_addr': '10.7.0.196/26', 'hwsku': 'Force10-S6000', 'type': 'LeafRouter', 'deployment_id': '2'}}")
|
||||||
|
|
||||||
def test_metadata_everflow(self):
|
def test_metadata_everflow(self):
|
||||||
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'
|
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'
|
||||||
output = self.run_script(argument)
|
output = self.run_script(argument)
|
||||||
|
Reference in New Issue
Block a user