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

Read cloudtype info from minigraph #4642

Merged
merged 1 commit into from
May 26, 2020
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
9 changes: 7 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ def parse_meta(meta, hname):
erspan_dst = []
deployment_id = None
region = None
cloudtype = 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 @@ -552,7 +553,9 @@ def parse_meta(meta, hname):
deployment_id = value
elif name == "Region":
region = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region
elif name == "CloudType":
cloudtype = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype


def parse_linkmeta(meta, hname):
Expand Down Expand Up @@ -797,6 +800,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
bgp_peers_with_range = None
deployment_id = None
region = None
cloudtype = None
hostname = None
linkmetas = {}

Expand Down Expand Up @@ -832,7 +836,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) = parse_meta(child, hostname)
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype) = 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 @@ -861,6 +865,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
'bgp_asn': bgp_asn,
'deployment_id': deployment_id,
'region': region,
'cloudtype': cloudtype,
'docker_routing_config_mode': docker_routing_config_mode,
'hostname': hostname,
'hwsku': hwsku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@
<a:Reference i:nil="true"/>
<a:Value>usfoo</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>CloudType</a:Name>
<a:Reference i:nil="true"/>
<a:Value>Public</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>ErspanDestinationIpv4</a:Name>
<a:Reference i:nil="true"/>
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 @@ -58,6 +58,11 @@ def test_minigraph_region(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), 'usfoo')

def test_minigraph_cloudtype(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'cloudtype\']" -m "' + self.sample_graph_metadata + '"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'Public')

def test_print_data(self):
argument = '-m "' + self.sample_graph + '" --print-data'
output = self.run_script(argument)
Expand Down