From 18e97fba2cda0da281869531ce291ee9af4a9576 Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Thu, 26 Apr 2018 19:01:33 -0700 Subject: [PATCH] [docker-lldpd]: Various fixes (#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 --- dockers/docker-lldp-sv2/lldpd.conf.j2 | 3 --- dockers/docker-lldp-sv2/lldpmgrd | 19 +++++++++++++++ dockers/docker-lldp-sv2/start.sh | 24 +++++++++++++++++++ .../tests/sample_output/lldpd.conf | 4 ---- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/dockers/docker-lldp-sv2/lldpd.conf.j2 b/dockers/docker-lldp-sv2/lldpd.conf.j2 index ea8be54b097d..94a04596699f 100644 --- a/dockers/docker-lldp-sv2/lldpd.conf.j2 +++ b/dockers/docker-lldp-sv2/lldpd.conf.j2 @@ -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 %} diff --git a/dockers/docker-lldp-sv2/lldpmgrd b/dockers/docker-lldp-sv2/lldpmgrd index 89bba918bf3d..a044d5ed9d77 100755 --- a/dockers/docker-lldp-sv2/lldpmgrd +++ b/dockers/docker-lldp-sv2/lldpmgrd @@ -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)) @@ -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 ============================== @@ -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) diff --git a/dockers/docker-lldp-sv2/start.sh b/dockers/docker-lldp-sv2/start.sh index 26337fb0667d..adc322979813 100755 --- a/dockers/docker-lldp-sv2/start.sh +++ b/dockers/docker-lldp-sv2/start.sh @@ -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 diff --git a/src/sonic-config-engine/tests/sample_output/lldpd.conf b/src/sonic-config-engine/tests/sample_output/lldpd.conf index 049d9f09059c..29739cb890d0 100644 --- a/src/sonic-config-engine/tests/sample_output/lldpd.conf +++ b/src/sonic-config-engine/tests/sample_output/lldpd.conf @@ -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