Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minigraph.py] add support to parse deployment id of neighbor devices #1890

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def parse_device(device):
d_type = None # don't shadow type()
hwsku = None
name = None
deployment_id = None
if str(QName(ns3, "type")) in device.attrib:
d_type = device.attrib[str(QName(ns3, "type"))]

Expand All @@ -53,7 +54,9 @@ def parse_device(device):
name = node.text
elif node.tag == str(QName(ns, "HwSku")):
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):
neighbors = {}
Expand Down Expand Up @@ -92,8 +95,10 @@ def parse_png(png, hname):

if child.tag == str(QName(ns, "Devices")):
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 }
if deployment_id:
device_data['deployment_id'] = deployment_id
devices[name] = device_data

if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
Expand Down Expand Up @@ -546,7 +551,7 @@ def parse_xml(filename, platform=None, port_config_file=None):

def parse_device_desc_xml(filename):
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['DEVICE_METADATA'] = {'localhost': {
Expand Down
36 changes: 21 additions & 15 deletions src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,33 @@
</DeviceDataPlaneInfo>
</DpgDec>
<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>
<Device i:type="ToRRouter">
<Hostname>switch-t0</Hostname>
<HwSku>Force10-S6000</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA01T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA02T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA03T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA04T1</Hostname>
<HwSku>Arista</HwSku>
<Hostname>switch-01t1</Hostname>
<Address xmlns:a="Microsoft.Search.Autopilot.NetMux">
<a:IPPrefix>10.1.0.186/32</a:IPPrefix>
</Address>
<DeploymentId>2</DeploymentId>
<DeviceLocation i:nil="true"/>
<ManagementAddress xmlns:a="Microsoft.Search.Autopilot.NetMux">
<a:IPPrefix>10.7.0.196/26</a:IPPrefix>
</ManagementAddress>
<HwSku>Force10-S6000</HwSku>
</Device>
</Devices>
</PngDec>
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def test_minigraph_deployment_id(self):
output = self.run_script(argument)
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):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'
output = self.run_script(argument)
Expand Down