Skip to content

Commit cbe4633

Browse files
committed
[docker-lldpd]: Various fixes (sonic-net#1650)
* We don't need configure anything until we have interfaces created * Don't run lldpcli for a port, until a port is up and running * Remove lldpd socket before starting lldpd * Fix sample files for lldpd configuration * Another attempt to make the test working * Quick fix for lldpd paused after start bug RB=1294300 G=lnos-reviewers R=ntrianta,pmao,rmolina,sfardeen,zxu A=
1 parent 058a5fd commit cbe4633

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

dockers/docker-lldp-sv2/lldpd.conf.j2

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{% if MGMT_INTERFACE %}
22
configure ports eth0 lldp portidsubtype local {{ MGMT_INTERFACE.keys()[0][0] }}
33
{% endif %}
4-
{% for local_port in DEVICE_NEIGHBOR %}
5-
configure ports {{ local_port }} lldp portidsubtype local {{ PORT[local_port]['alias'] }} description {{ DEVICE_NEIGHBOR[local_port]['name'] }}:{{ DEVICE_NEIGHBOR[local_port]['port'] }}
6-
{% endfor %}

dockers/docker-lldp-sv2/lldpmgrd

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ try:
2020
import subprocess
2121
import sys
2222
import syslog
23+
import os.path
2324
from swsscommon import swsscommon
2425
except ImportError as err:
2526
raise ImportError("%s - required module not found" % str(err))
@@ -70,6 +71,19 @@ def signal_handler(sig, frame):
7071
else:
7172
log_warning("Caught unhandled signal '" + sig + "'")
7273

74+
# ========================== Helpers ==================================
75+
76+
def is_port_up(port_name):
77+
filename = "/sys/class/net/%s/operstate" % port_name
78+
if not os.path.exists(filename):
79+
return False
80+
81+
with open(filename) as fp:
82+
state = fp.read()
83+
if 'up' in state:
84+
return True
85+
else:
86+
return False
7387

7488
# ============================== Classes ==============================
7589

@@ -161,6 +175,11 @@ class LldpManager(object):
161175
to_delete = []
162176

163177
for (port_name, cmd) in self.pending_cmds.iteritems():
178+
if not is_port_up(port_name):
179+
# it doesn't make any sense to configure lldpd if the target port is unavailable
180+
# let's postpone the command for the next iteration
181+
continue
182+
164183
log_debug("Running command: '{}'".format(cmd))
165184

166185
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

dockers/docker-lldp-sv2/start.sh

+24
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,32 @@ mkdir -p /var/sonic
66
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
77

88
rm -f /var/run/rsyslogd.pid
9+
rm -f /var/run/lldpd.socket
910

1011
supervisorctl start rsyslogd
1112
supervisorctl start lldpd
1213
supervisorctl start lldp-syncd
1314
supervisorctl start lldpmgrd
15+
16+
# Current lldpd version has a bug.
17+
# When lldpd starts it is in the pause state by default
18+
# But then it execute 'lldpcli resume' to configure and unpause itself.
19+
# When lldpd execute lldpcli, it doesn't check the return code
20+
# Sometimes lldpcli returns failure, but lldpd doesn't catch it
21+
# and keeps working paused and unconfigured
22+
#
23+
# The fix below addresses the issue.
24+
#
25+
26+
# wait until lldpd started
27+
until [[ -e /var/run/lldpd.socket ]];
28+
do
29+
sleep 1;
30+
done
31+
32+
# Manually try to resume lldpd, until it's successful
33+
while /bin/true;
34+
do
35+
lldpcli -u /var/run/lldpd.socket -c /etc/lldpd.conf -c /etc/lldpd.d resume > /dev/null && break
36+
sleep 1
37+
done
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
configure ports eth0 lldp portidsubtype local eth0
2-
configure ports Ethernet112 lldp portidsubtype local fortyGigE0/112 description ARISTA01T1:Ethernet1/1
3-
configure ports Ethernet116 lldp portidsubtype local fortyGigE0/116 description ARISTA02T1:Ethernet1/1
4-
configure ports Ethernet120 lldp portidsubtype local fortyGigE0/120 description ARISTA03T1:Ethernet1/1
5-
configure ports Ethernet124 lldp portidsubtype local fortyGigE0/124 description ARISTA04T1:Ethernet1/1
62

0 commit comments

Comments
 (0)