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

Update minigraph.py to parse kubernetes config from minigraph.xml #6633

Merged
merged 6 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ def parse_meta(meta, hname):
region = None
cloudtype = None
resource_type = None
kube_data = {}
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 Down Expand Up @@ -808,7 +809,11 @@ def parse_meta(meta, hname):
cloudtype = value
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
elif name == "KubernetesEnabled":
kube_data["disable"] = value
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
elif name == "KubernetesServerIp":
kube_data["ip"] = value
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, kube_data


def parse_linkmeta(meta, hname):
Expand Down Expand Up @@ -1097,6 +1102,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
host_lo_intfs = None
is_storage_device = False
local_devices = []
kube_data = {}

# hostname is the asic_name, get the asic_id from the asic_name
if asic_name is not None:
Expand Down Expand Up @@ -1133,7 +1139,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, None)
elif child.tag == str(QName(ns, "MetadataDeclaration")):
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type) = parse_meta(child, hostname)
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, kube_data) = 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 @@ -1174,6 +1180,13 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
}
}

if kube_data:
results['KUBERNETES_MASTER'] = { 'SERVER': {
'disable': 'True' if kube_data.get('disable', '0') == '0' else 'False',
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
'ip': kube_data.get('ip', '')
}
}

results['PEER_SWITCH'] = get_peer_switch_info(linkmetas, devices)

if bool(results['PEER_SWITCH']):
Expand Down
10 changes: 10 additions & 0 deletions src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@
<a:Reference i:nil="true"/>
<a:Value>10.0.10.7;10.0.10.8</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>KubernetesEnabled</a:Name>
<a:Reference i:nil="true"/>
<a:Value>0</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>KubernetesServerIp</a:Name>
<a:Reference i:nil="true"/>
<a:Value>10.10.10.10</a:Value>
</a:DeviceProperty>
</a:Properties>
</a:DeviceMetadata>
</Devices>
Expand Down
9 changes: 8 additions & 1 deletion src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import subprocess

Expand Down Expand Up @@ -195,6 +196,12 @@ def test_metadata_tacacs(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'10.0.10.7': {'priority': '1', 'tcp_port': '49'}, '10.0.10.8': {'priority': '1', 'tcp_port': '49'}}")

def test_metadata_kube(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "KUBERNETES_MASTER[\'SERVER\']"'
output = self.run_script(argument)
self.assertEqual(json.loads(output.strip().replace("'", "\"")),
json.loads('{"ip": "10.10.10.10", "disable": "True"}'))

def test_minigraph_mgmt_port(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "MGMT_PORT"'
output = self.run_script(argument)
Expand Down Expand Up @@ -289,4 +296,4 @@ def test_minigraph_mux_cable_table(self):
utils.to_dict(output.strip()),
expected_table
)