Skip to content

Commit

Permalink
Added cluster to "DEVICE_METADATA|localhost"
Browse files Browse the repository at this point in the history
  • Loading branch information
renukamanavalan committed Feb 2, 2021
1 parent bab6ca0 commit ac3c708
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def parse_device(device):
hwsku = None
name = None
deployment_id = None
cluster = None

for node in device:
if node.tag == str(QName(ns, "Address")):
Expand All @@ -100,11 +101,13 @@ def parse_device(device):
deployment_id = node.text
elif node.tag == str(QName(ns, "ElementType")):
d_type = node.text
elif node.tag == str(QName(ns, "ClusterName")):
cluster = 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, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id)
return (lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster)

def calculate_lcm_for_ecmp (nhdevices_bank_map, nhip_bank_map):
banks_enumerated = {}
Expand Down Expand Up @@ -244,18 +247,18 @@ def parse_png(png, hname, dpg_ecmp_content = None):

if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id) = parse_device(device)
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster) = parse_device(device)
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
if cluster:
device_data['cluster'] = cluster
if deployment_id:
device_data['deployment_id'] = deployment_id
if lo_prefix_v6:
device_data['lo_addr_v6'] = lo_prefix_v6
devices[name] = device_data

if name == hname:
cluster = device.find(str(QName(ns, "ClusterName")))

if cluster != None and cluster.text != None and "str" in cluster.text.lower():
if cluster and "str" in cluster.lower():
is_storage_device = True

if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
Expand Down Expand Up @@ -380,8 +383,10 @@ def parse_asic_png(png, asic_name, hostname):

if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id) = parse_device(device)
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster) = parse_device(device)
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
if cluster:
device_data['cluster'] = cluster
if deployment_id:
device_data['deployment_id'] = deployment_id
if lo_prefix_v6:
Expand Down Expand Up @@ -1180,6 +1185,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
}
}

cluster = [devices[key] for key in devices if key.lower() == hostname.lower()][0].get('cluster', "")
if cluster:
results['DEVICE_METADATA']['localhost']['cluster'] = cluster

if kube_data:
results['KUBERNETES_MASTER'] = { 'SERVER': {
'disable': 'True' if kube_data.get('disable', '0') == '0' else 'False',
Expand Down Expand Up @@ -1537,7 +1546,7 @@ def get_mux_cable_entries(mux_cable_ports, neighbors, devices):

def parse_device_desc_xml(filename):
root = ET.parse(filename).getroot()
(lo_prefix, lo_prefix_v6, mgmt_prefix, hostname, hwsku, d_type, _) = parse_device(root)
(lo_prefix, lo_prefix_v6, mgmt_prefix, hostname, hwsku, d_type, _, _) = parse_device(root)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def test_minigraph_deployment_id(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "1")

def test_minigraph_cluster(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DEVICE_METADATA[\'localhost\'][\'cluster\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "AAA00PrdStr00")

def test_minigraph_neighbor_metadata(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR_METADATA"'

Expand Down

0 comments on commit ac3c708

Please sign in to comment.