Skip to content

Commit

Permalink
[docker-lldpd]: Various fixes (sonic-net#1650)
Browse files Browse the repository at this point in the history
    * 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=
  • Loading branch information
zhenggen-xu committed Apr 27, 2018
1 parent 058a5fd commit cbe4633
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
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 @@ -161,6 +175,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

0 comments on commit cbe4633

Please sign in to comment.