Skip to content

Commit

Permalink
Address Review Comment with following changes:
Browse files Browse the repository at this point in the history
a) Use Device Metadata hostname even in per namespace conatiner.
   updated minigraph parsing for same to have hostname as system
   hostname and add new key for asic name

b) Minigraph changes to have MGMT_INTERFACE Key in per asic/namespace
   config also as needed for LLDP for setting chassis management IP.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
  • Loading branch information
abdosi committed May 6, 2020
1 parent 60aa5c5 commit f1bc3eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
6 changes: 2 additions & 4 deletions dockers/docker-lldp-sv2/lldpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
{# If MGMT port alias is available, use it for port ID subtype, otherwise use port name #}
{% set mgmt_port_name = MGMT_INTERFACE.keys()[0][0] %}
{% set ipv4 = MGMT_INTERFACE.keys()[0][1].split('/')[0] %}
configure system ip management pattern {{ ipv4 }}
{% if DEVICE_METADATA['localhost']['sub_role'] is not defined or DEVICE_METADATA['localhost']['sub_role']|length == 0 %}
{% if MGMT_PORT and MGMT_PORT[mgmt_port_name] and MGMT_PORT[mgmt_port_name].alias %}
configure ports eth0 lldp portidsubtype local {{ MGMT_PORT[mgmt_port_name].alias }}
{% else %}
configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
{% endif %}
configure system ip management pattern {{ ipv4 }}
{% endif %}
{% endif %}
configure system hostname ${hostname}
configure system hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
5 changes: 0 additions & 5 deletions dockers/docker-lldp-sv2/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

sonic-cfggen -d -t /usr/share/sonic/templates/lldpd.conf.j2 > /etc/lldpd.conf

# update the hostname. Not using device metadata as in multi-npu platform each namespace
# has its own device metadata hostname. Using the hostname set by docker using host enviroment

sed -e "s/\${hostname}/$(hostname)/" -i /etc/lldpd.conf

mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

Expand Down
24 changes: 16 additions & 8 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,24 @@ def parse_asic_png(png, asic_name, hostname):
return (neighbors, devices, port_speeds)

def parse_dpg(dpg, hname):
aclintfs = None
mgmtintfs = None
for child in dpg:
"""In Multi-NPU platforms the acl intfs are defined only for the host not for individual asic.
"""
In Multi-NPU platforms the acl intfs are defined only for the host not for individual asic.
There is just one aclintf node in the minigraph
Get the aclintfs node first.
Get the aclintfs node first.
"""
if child.find(str(QName(ns, "AclInterfaces"))) is not None:
if aclintfs is None and child.find(str(QName(ns, "AclInterfaces"))) is not None:
aclintfs = child.find(str(QName(ns, "AclInterfaces")))

"""
In Multi-NPU platforms the mgmt intfs are defined only for the host not for individual asic
There is just one mgmtintf node in the minigraph
Get the mgmtintfs node first. We need mgmt intf to get mgmt ip in per asic dockers.
"""
if mgmtintfs is None and child.find(str(QName(ns, "ManagementIPInterfaces"))) is not None:
mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))

hostname = child.find(str(QName(ns, "Hostname")))
if hostname.text.lower() != hname.lower():
continue
Expand Down Expand Up @@ -291,7 +301,6 @@ def parse_dpg(dpg, hname):
mvrf_en_flag = mv.find(str(QName(ns, "mgmtVrfEnabled"))).text
mvrf["vrf_global"] = {"mgmtVrfEnabled": mvrf_en_flag}

mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))
mgmt_intf = {}
for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))):
intfname = mgmtintf.find(str(QName(ns, "AttachTo"))).text
Expand Down Expand Up @@ -767,18 +776,16 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):

if asic_name is None:
current_device = [devices[key] for key in devices if key.lower() == hostname.lower()][0]
name = hostname
else:
current_device = [devices[key] for key in devices if key.lower() == asic_name.lower()][0]
name = asic_name

results = {}
results['DEVICE_METADATA'] = {'localhost': {
'bgp_asn': bgp_asn,
'deployment_id': deployment_id,
'region': region,
'docker_routing_config_mode': docker_routing_config_mode,
'hostname': name,
'hostname': hostname,
'hwsku': hwsku,
'type': current_device['type']
}
Expand All @@ -788,6 +795,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
if sub_role is not None:
current_device['sub_role'] = sub_role
results['DEVICE_METADATA']['localhost']['sub_role'] = sub_role
results['DEVICE_METADATA']['localhost']['asic_name'] = asic_name
results['BGP_NEIGHBOR'] = bgp_sessions
results['BGP_MONITORS'] = bgp_monitors
results['BGP_PEER_RANGE'] = bgp_peers_with_range
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/sample_output/lldpd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.0.0.100
configure system hostname ${hostname}
configure system hostname switch-t0
5 changes: 3 additions & 2 deletions src/sonic-config-engine/tests/test_multinpu_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_mgmt_port(self):
self.assertDictEqual(output, {'eth0': {'alias': 'eth0', 'admin_status': 'up'}})
for asic in range(NUM_ASIC):
output = json.loads(self.run_script_for_asic(argument, asic, self.port_config[asic]))
self.assertDictEqual(output, {})
self.assertDictEqual(output, {'eth0': {'alias': 'eth0', 'admin_status': 'up'}})

def test_frontend_asic_portchannels(self):
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL\"".format(self.sample_graph, self.port_config[0])
Expand Down Expand Up @@ -213,7 +213,8 @@ def test_device_asic_metadata(self):
for asic in range(NUM_ASIC):
output = json.loads(self.run_script_for_asic(argument, asic,self.port_config[asic]))
asic_name = "asic{}".format(asic)
self.assertEqual(output['localhost']['hostname'], asic_name)
self.assertEqual(output['localhost']['hostname'], 'multi_npu_platform_01')
self.assertEqual(output['localhost']['asic_name'], asic_name)
self.assertEqual(output['localhost']['type'], 'Asic')
if asic == 0 or asic == 1:
self.assertEqual(output['localhost']['sub_role'], 'FrontEnd')
Expand Down

0 comments on commit f1bc3eb

Please sign in to comment.