Skip to content

Commit

Permalink
Change minigraph sub_role to resource_type
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-n committed Oct 3, 2020
1 parent eb76a63 commit 2dde8dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
15 changes: 9 additions & 6 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def parse_meta(meta, hname):
deployment_id = None
region = None
cloudtype = None
sub_role = None
resource_type = 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 @@ -573,9 +573,9 @@ def parse_meta(meta, hname):
region = value
elif name == "CloudType":
cloudtype = value
elif name == "SubRole":
sub_role = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, sub_role
elif name == "ResourceType":
resource_type = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type


def parse_linkmeta(meta, hname):
Expand Down Expand Up @@ -822,6 +822,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
neighbors = None
devices = None
sub_role = None
resource_type = None
docker_routing_config_mode = "separated"
port_speeds_default = {}
port_speed_png = {}
Expand Down Expand Up @@ -873,7 +874,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
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, cloudtype, sub_role) = parse_meta(child, hostname)
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type) = 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 @@ -918,9 +919,11 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if sub_role is not None:
current_device['sub_role'] = sub_role
results['DEVICE_METADATA']['localhost']['sub_role'] = sub_role
if asic_name is not None:
results['DEVICE_METADATA']['localhost']['asic_name'] = asic_name

if resource_type is not None:
results['DEVICE_METADATA']['localhost']['resource_type'] = resource_type

results['BGP_NEIGHBOR'] = bgp_sessions
results['BGP_MONITORS'] = bgp_monitors
results['BGP_PEER_RANGE'] = bgp_peers_with_range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@
<a:Value>10.0.10.7;10.0.10.8</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>SubRole</a:Name>
<a:Name>ResourceType</a:Name>
<a:Reference i:nil="true"/>
<a:Value>sub_role_1</a:Value>
<a:Value>resource_type_x</a:Value>
</a:DeviceProperty>
</a:Properties>
</a:DeviceMetadata>
Expand Down
6 changes: 3 additions & 3 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def test_minigraph_cloudtype(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), 'Public')

def test_minigraph_subrole(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'sub_role\']" -m "' + self.sample_graph_metadata + '"'
def test_minigraph_resourcetype(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'resource_type\']" -m "' + self.sample_graph_metadata + '"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'sub_role_1')
self.assertEqual(output.strip(), 'resource_type_x')

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

0 comments on commit 2dde8dd

Please sign in to comment.