Skip to content

Commit 42d9a44

Browse files
authored
Minigraph resource type changes (#5198)
* Parse sub_role from minigraph into DEVICE_METADATA * Change minigraph sub_role to resource_type
1 parent 9a1f68b commit 42d9a44

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/sonic-config-engine/minigraph.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def parse_meta(meta, hname):
547547
deployment_id = None
548548
region = None
549549
cloudtype = None
550+
resource_type = None
550551
device_metas = meta.find(str(QName(ns, "Devices")))
551552
for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))):
552553
if device.find(str(QName(ns1, "Name"))).text.lower() == hname.lower():
@@ -573,7 +574,9 @@ def parse_meta(meta, hname):
573574
region = value
574575
elif name == "CloudType":
575576
cloudtype = value
576-
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype
577+
elif name == "ResourceType":
578+
resource_type = value
579+
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type
577580

578581

579582
def parse_linkmeta(meta, hname):
@@ -820,6 +823,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
820823
neighbors = None
821824
devices = None
822825
sub_role = None
826+
resource_type = None
823827
docker_routing_config_mode = "separated"
824828
port_speeds_default = {}
825829
port_speed_png = {}
@@ -871,7 +875,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
871875
elif child.tag == str(QName(ns, "UngDec")):
872876
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
873877
elif child.tag == str(QName(ns, "MetadataDeclaration")):
874-
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype) = parse_meta(child, hostname)
878+
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type) = parse_meta(child, hostname)
875879
elif child.tag == str(QName(ns, "LinkMetadataDeclaration")):
876880
linkmetas = parse_linkmeta(child, hostname)
877881
elif child.tag == str(QName(ns, "DeviceInfos")):
@@ -917,6 +921,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
917921
current_device['sub_role'] = sub_role
918922
results['DEVICE_METADATA']['localhost']['sub_role'] = sub_role
919923
results['DEVICE_METADATA']['localhost']['asic_name'] = asic_name
924+
925+
if resource_type is not None:
926+
results['DEVICE_METADATA']['localhost']['resource_type'] = resource_type
927+
920928
results['BGP_NEIGHBOR'] = bgp_sessions
921929
results['BGP_MONITORS'] = bgp_monitors
922930
results['BGP_PEER_RANGE'] = bgp_peers_with_range

src/sonic-config-engine/tests/simple-sample-graph-metadata.xml

+5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
<a:Reference i:nil="true"/>
254254
<a:Value>10.0.10.7;10.0.10.8</a:Value>
255255
</a:DeviceProperty>
256+
<a:DeviceProperty>
257+
<a:Name>ResourceType</a:Name>
258+
<a:Reference i:nil="true"/>
259+
<a:Value>resource_type_x</a:Value>
260+
</a:DeviceProperty>
256261
</a:Properties>
257262
</a:DeviceMetadata>
258263
</Devices>

src/sonic-config-engine/tests/test_cfggen.py

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def test_minigraph_cloudtype(self):
8080
output = self.run_script(argument)
8181
self.assertEqual(output.strip(), 'Public')
8282

83+
def test_minigraph_resourcetype(self):
84+
argument = '-v "DEVICE_METADATA[\'localhost\'][\'resource_type\']" -m "' + self.sample_graph_metadata + '"'
85+
output = self.run_script(argument)
86+
self.assertEqual(output.strip(), 'resource_type_x')
87+
8388
def test_print_data(self):
8489
argument = '-m "' + self.sample_graph + '" --print-data'
8590
output = self.run_script(argument)

0 commit comments

Comments
 (0)