Skip to content

Commit 789c97c

Browse files
committed
Added Support to Parse Associated Slice in minigraph and add as config
to DEVICE_METADATA. Yang model updated accordingly. Signed-off-by: Abhishek Dosi <[email protected]>
1 parent 3da6d01 commit 789c97c

7 files changed

Lines changed: 41 additions & 9 deletions

File tree

src/sonic-config-engine/minigraph.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def parse_device(device):
122122
deployment_id = None
123123
cluster = None
124124
d_subtype = None
125+
slice_type = None
125126

126127
for node in device:
127128
if node.tag == str(QName(ns, "Address")):
@@ -144,11 +145,13 @@ def parse_device(device):
144145
cluster = node.text
145146
elif node.tag == str(QName(ns, "SubType")):
146147
d_subtype = node.text
148+
elif node.tag == str(QName(ns, "AssociatedSliceStr")) and node.text and "AZNG_Production" in node.text:
149+
slice_type = "AZNG_Production"
147150

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

151-
return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype)
154+
return (lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type)
152155

153156

154157
def calculate_lcm_for_ecmp (nhdevices_bank_map, nhip_bank_map):
@@ -286,7 +289,8 @@ def parse_png(png, hname, dpg_ecmp_content = None):
286289

287290
if child.tag == str(QName(ns, "Devices")):
288291
for device in child.findall(str(QName(ns, "Device"))):
289-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
292+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, d_subtype, slice_type) = \
293+
parse_device(device)
290294
device_data = {}
291295
if hwsku != None:
292296
device_data['hwsku'] = hwsku
@@ -306,6 +310,8 @@ def parse_png(png, hname, dpg_ecmp_content = None):
306310
device_data['type'] = d_type
307311
if d_subtype != None:
308312
device_data['subtype'] = d_subtype
313+
if slice_type != None:
314+
device_data['slice_type'] = slice_type
309315
devices[name] = device_data
310316

311317
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
@@ -427,7 +433,7 @@ def parse_asic_png(png, asic_name, hostname):
427433

428434
if child.tag == str(QName(ns, "Devices")):
429435
for device in child.findall(str(QName(ns, "Device"))):
430-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _) = parse_device(device)
436+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, name, hwsku, d_type, deployment_id, cluster, _, slice_type) = parse_device(device)
431437
device_data = {}
432438
if hwsku != None:
433439
device_data['hwsku'] = hwsku
@@ -445,6 +451,8 @@ def parse_asic_png(png, asic_name, hostname):
445451
device_data['mgmt_addr_v6'] = mgmt_prefix_v6
446452
if d_type != None:
447453
device_data['type'] = d_type
454+
if slice_type != None:
455+
device_data['slice_type'] = slice_type
448456
devices[name] = device_data
449457

450458
return (neighbors, devices, port_speeds)
@@ -1654,6 +1662,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
16541662
if cluster:
16551663
results['DEVICE_METADATA']['localhost']['cluster'] = cluster
16561664

1665+
if current_device and 'slice_type' in current_device and current_device['slice_type']:
1666+
results['DEVICE_METADATA']['localhost']['slice_type'] = current_device['slice_type']
1667+
16571668
if kube_data:
16581669
results['KUBERNETES_MASTER'] = {
16591670
'SERVER': {
@@ -2289,7 +2300,7 @@ def get_mux_cable_entries(ports, mux_cable_ports, active_active_ports, neighbors
22892300

22902301
def parse_device_desc_xml(filename):
22912302
root = ET.parse(filename).getroot()
2292-
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _) = parse_device(root)
2303+
(lo_prefix, lo_prefix_v6, mgmt_prefix, mgmt_prefix_v6, hostname, hwsku, d_type, _, _, _, _) = parse_device(root)
22932304

22942305
results = {}
22952306
results['DEVICE_METADATA'] = {'localhost': {

src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@
913913
<a:IPPrefix>::/0</a:IPPrefix>
914914
</AddressV6>
915915
<AssociatedClustersStr/>
916-
<AssociatedSliceStr/>
916+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
917917
<AssociatedTagsStr/>
918918
<ClusterName/>
919919
<DeploymentId i:nil="true"/>
@@ -938,7 +938,7 @@
938938
<a:IPPrefix>::/0</a:IPPrefix>
939939
</AddressV6>
940940
<AssociatedClustersStr/>
941-
<AssociatedSliceStr/>
941+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
942942
<AssociatedTagsStr/>
943943
<ClusterName/>
944944
<DeploymentId i:nil="true"/>
@@ -963,7 +963,7 @@
963963
<a:IPPrefix>::/0</a:IPPrefix>
964964
</AddressV6>
965965
<AssociatedClustersStr/>
966-
<AssociatedSliceStr/>
966+
<AssociatedSliceStr>AZNG_Production</AssociatedSliceStr>
967967
<AssociatedTagsStr/>
968968
<ClusterName/>
969969
<DeploymentId i:nil="true"/>
@@ -988,7 +988,7 @@
988988
<a:IPPrefix>::/0</a:IPPrefix>
989989
</AddressV6>
990990
<AssociatedClustersStr/>
991-
<AssociatedSliceStr/>
991+
<AssociatedSliceStr/>
992992
<AssociatedTagsStr/>
993993
<ClusterName/>
994994
<DeploymentId i:nil="true"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ def test_device_asic_metadata(self):
335335
else:
336336
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')
337337
self.assertEqual(output['localhost']['deployment_id'], "1")
338+
if asic != 3:
339+
self.assertEqual(output['localhost']['slice_type'], "AZNG_Production")
338340

339341
def test_global_asic_acl(self):
340342
argument = ["-m", self.sample_graph, "-p", self.sample_port_config, "--var-json", "ACL_TABLE"]

src/sonic-yang-models/tests/files/sample_config_db.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@
370370
"rack_mgmt_map": "dummy_value",
371371
"timezone": "Europe/Kiev",
372372
"bgp_router_id": "8.8.8.8",
373-
"chassis_hostname": "str-sonic-chassis-1"
373+
"chassis_hostname": "str-sonic-chassis-1",
374+
"slice_type": "AZNG_Production"
374375
}
375376
},
376377
"VLAN": {

src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,8 @@
172172
},
173173
"DEVICE_METADATA_VALID_CHASSIS_HOSTNAME": {
174174
"desc": "Verifying valid chassis hostname configuration."
175+
},
176+
"DEVICE_METADATA_VALID_SLICE_TYPE": {
177+
"desc": "Verifying valid slice type configuration."
175178
}
176179
}

src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,5 +471,14 @@
471471
}
472472
}
473473
}
474+
},
475+
"DEVICE_METADATA_VALID_SLICE_TYPE": {
476+
"sonic-device_metadata:sonic-device_metadata": {
477+
"sonic-device_metadata:DEVICE_METADATA": {
478+
"sonic-device_metadata:localhost": {
479+
"slice_type": "AZNG_Production"
480+
}
481+
}
482+
}
474483
}
475484
}

src/sonic-yang-models/yang-models/sonic-device_metadata.yang

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ module sonic-device_metadata {
259259
description "hostname of the chassis to which this linecard or supervisor belongs to";
260260
type stypes:hostname;
261261
}
262+
263+
leaf slice_type {
264+
description "Metadata tag for the device.";
265+
type string;
266+
}
267+
262268
}
263269
/* end of container localhost */
264270
}

0 commit comments

Comments
 (0)