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

[docker-lldpd]: Various fixes #1650

Merged
merged 6 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions dockers/docker-lldp-sv2/lldpd.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{% if MGMT_INTERFACE %}
configure ports eth0 lldp portidsubtype local {{ MGMT_INTERFACE.keys()[0][0] }}
{% endif %}
{% for local_port in DEVICE_NEIGHBOR %}
configure ports {{ local_port }} lldp portidsubtype local {{ PORT[local_port]['alias'] }} description {{ DEVICE_NEIGHBOR[local_port]['name'] }}:{{ DEVICE_NEIGHBOR[local_port]['port'] }}
{% endfor %}
19 changes: 19 additions & 0 deletions dockers/docker-lldp-sv2/lldpmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ try:
import subprocess
import sys
import syslog
import os.path
from swsscommon import swsscommon
except ImportError as err:
raise ImportError("%s - required module not found" % str(err))
Expand Down Expand Up @@ -70,6 +71,19 @@ def signal_handler(sig, frame):
else:
log_warning("Caught unhandled signal '" + sig + "'")

# ========================== Helpers ==================================

def is_port_up(port_name):
filename = "/sys/class/net/%s/operstate" % port_name
if not os.path.exists(filename):
return False

with open(filename) as fp:
state = fp.read()
if 'up' in state:
return True
else:
return False

# ============================== Classes ==============================

Expand Down Expand Up @@ -159,6 +173,11 @@ class LldpManager(object):
to_delete = []

for (port_name, cmd) in self.pending_cmds.iteritems():
if not is_port_up(port_name):
# it doesn't make any sense to configure lldpd if the target port is unavailable
# let's postpone the command for the next iteration
continue

log_debug("Running command: '{}'".format(cmd))

proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down
24 changes: 24 additions & 0 deletions dockers/docker-lldp-sv2/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@ mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

rm -f /var/run/rsyslogd.pid
rm -f /var/run/lldpd.socket

supervisorctl start rsyslogd
supervisorctl start lldpd
supervisorctl start lldp-syncd
supervisorctl start lldpmgrd

# Current lldpd version has a bug.
# When lldpd starts it is in the pause state by default
# But then it execute 'lldpcli resume' to configure and unpause itself.
# When lldpd execute lldpcli, it doesn't check the return code
# Sometimes lldpcli returns failure, but lldpd doesn't catch it
# and keeps working paused and unconfigured
#
# The fix below addresses the issue.
#

# wait until lldpd started
until [[ -e /var/run/lldpd.socket ]];
do
sleep 1;
done

# Manually try to resume lldpd, until it's successful
while /bin/true;
do
lldpcli -u /var/run/lldpd.socket -c /etc/lldpd.conf -c /etc/lldpd.d resume > /dev/null && break
sleep 1
done
4 changes: 0 additions & 4 deletions src/sonic-config-engine/tests/sample_output/lldpd.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
configure ports eth0 lldp portidsubtype local eth0
configure ports Ethernet112 lldp portidsubtype local fortyGigE0/112 description ARISTA01T1:Ethernet1/1
configure ports Ethernet116 lldp portidsubtype local fortyGigE0/116 description ARISTA02T1:Ethernet1/1
configure ports Ethernet120 lldp portidsubtype local fortyGigE0/120 description ARISTA03T1:Ethernet1/1
configure ports Ethernet124 lldp portidsubtype local fortyGigE0/124 description ARISTA04T1:Ethernet1/1