Skip to content

Commit 72e9476

Browse files
author
Shuotian Cheng
authored
[config-engine]: Fix bug multiple ports connecting to same neighbor (#1005)
The current DEVICE_NEIGHBOR format doesn't support multiple different ports connecting with same neighbor. Thus the lldpd.conf file is not generated correctly, causing missing information for LAG members. This fix reverts the data structure in the previous version of minigraph parser - using local port as the key and remote port/device as the value of the map. Sample format is: DEVICE_NEIGHBOR['Ethernet124'] = { 'name': 'ARISTA04T1', 'port': 'Ethernet1/1' } The corresponding unit test in test_cfggen is updated. Add one more unit test for lldpd.conf.j2 verification. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent 7c326e3 commit 72e9476

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% for neighbor in DEVICE_NEIGHBOR %}
2-
configure ports {{ DEVICE_NEIGHBOR[neighbor]['local_port'] }} lldp portidsubtype local {{ PORT[DEVICE_NEIGHBOR[neighbor]['local_port']]['alias'] }} description {{ neighbor }}:{{ DEVICE_NEIGHBOR[neighbor]['port'] }}
1+
{% for local_port in DEVICE_NEIGHBOR %}
2+
configure ports {{ local_port }} lldp portidsubtype local {{ PORT[local_port]['alias'] }} description {{ DEVICE_NEIGHBOR[local_port]['name'] }}:{{ DEVICE_NEIGHBOR[local_port]['port'] }}
33
{% endfor %}

src/sonic-config-engine/minigraph.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,17 @@ def parse_png(png, hname):
9191
if enddevice == hname:
9292
if port_alias_map.has_key(endport):
9393
endport = port_alias_map[endport]
94-
neighbors[startdevice] = {'local_port': endport, 'port': startport}
94+
neighbors[endport] = {'name': startdevice, 'port': startport}
9595
else:
9696
if port_alias_map.has_key(startport):
9797
startport = port_alias_map[startport]
98-
neighbors[enddevice] = {'local_port': startport, 'port': endport}
98+
neighbors[startport] = {'name': enddevice, 'port': endport}
9999

100100
if child.tag == str(QName(ns, "Devices")):
101101
for device in child.findall(str(QName(ns, "Device"))):
102102
(lo_prefix, mgmt_prefix, name, hwsku, d_type) = parse_device(device)
103103
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
104-
name = name.replace('"', '')
105-
if neighbors.has_key(name):
106-
neighbors[name].update(device_data)
107-
else:
108-
devices[name] = device_data
104+
devices[name] = device_data
109105

110106
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
111107
for if_link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
configure ports Ethernet116 lldp portidsubtype local fortyGigE0/116 description ARISTA02T1:Ethernet1/1
2+
configure ports Ethernet124 lldp portidsubtype local fortyGigE0/124 description ARISTA04T1:Ethernet1/1
3+
configure ports Ethernet112 lldp portidsubtype local fortyGigE0/112 description ARISTA01T1:Ethernet1/1
4+
configure ports Ethernet120 lldp portidsubtype local fortyGigE0/120 description ARISTA03T1:Ethernet1/1
5+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def test_minigraph_portchannel_interfaces(self):
106106
self.assertEqual(output.strip(), "[('PortChannel01', 'FC00::71/126'), ('PortChannel01', '10.0.0.56/31')]")
107107

108108
def test_minigraph_neighbors(self):
109-
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR[\'ARISTA01T1\']"'
109+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR[\'Ethernet124\']"'
110110
output = self.run_script(argument)
111-
self.assertEqual(output.strip(), "{'mgmt_addr': None, 'hwsku': 'Arista', 'lo_addr': None, 'local_port': 'Ethernet112', 'type': 'LeafRouter', 'port': 'Ethernet1/1'}")
111+
self.assertEqual(output.strip(), "{'name': 'ARISTA04T1', 'port': 'Ethernet1/1'}")
112112

113113
def test_minigraph_bgp(self):
114114
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v "BGP_NEIGHBOR[\'10.0.0.59\']"'

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ def test_interfaces(self):
2626

2727
def test_alias_map(self):
2828
alias_map_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-snmp-sv2', 'alias_map.j2')
29-
argument = '-m "' + self.t0_minigraph + '" -p "' + self.t0_port_config + '" -t "' + alias_map_template + '"'
29+
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + alias_map_template
3030
output = self.run_script(argument)
3131
data = json.loads(output)
3232
self.assertEqual(data["Ethernet4"], "fortyGigE0/4")
33+
34+
def test_lldp(self):
35+
lldpd_conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-lldp-sv2', 'lldpd.conf.j2')
36+
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + lldpd_conf_template + ' > ' + self.output_file
37+
self.run_script(argument)
38+
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'lldpd.conf'), self.output_file))
3339

3440
def test_teamd(self):
3541

0 commit comments

Comments
 (0)