Skip to content

Commit

Permalink
[minigraph.py]: Prefer parsing device type from <ElementType> (#6184)
Browse files Browse the repository at this point in the history
* Parse device type from <ElementType> first in <PngDec>
* Fall back to <Device> type attribute if no <ElementType> is found

Signed-off-by: Lawrence Lee <[email protected]>
  • Loading branch information
theasianpianist authored and abdosi committed Dec 19, 2020
1 parent 8d5cf6a commit 024330c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def parse_device(device):
hwsku = None
name = None
deployment_id = None
if str(QName(ns3, "type")) in device.attrib:
d_type = device.attrib[str(QName(ns3, "type"))]

for node in device:
if node.tag == str(QName(ns, "Address")):
Expand All @@ -78,6 +76,12 @@ def parse_device(device):
hwsku = node.text
elif node.tag == str(QName(ns, "DeploymentId")):
deployment_id = node.text
elif node.tag == str(QName(ns, "ElementType")):
d_type = node.text

if d_type is None and str(QName(ns3, "type")) in device.attrib:
d_type = device.attrib[str(QName(ns3, "type"))]

return (lo_prefix, mgmt_prefix, name, hwsku, d_type, deployment_id)

def parse_png(png, hname):
Expand Down
3 changes: 2 additions & 1 deletion src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
</DeviceLinkBase>
</DeviceInterfaceLinks>
<Devices>
<Device i:type="ToRRouter">
<Device xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution" i:type="a:ToRRouter">
<ElementType>ToRRouter</ElementType>
<Hostname>switch-t0</Hostname>
<HwSku>Force10-S6000</HwSku>
<ClusterName>AAA00PrdStr00</ClusterName>
Expand Down

0 comments on commit 024330c

Please sign in to comment.