Merge pull request #2556 from lguohan/lldp

[docker-lldp]: fix several issues in lldpd docker
This commit is contained in:
lguohan 2019-02-12 16:20:45 -08:00 committed by GitHub
commit 4d2cd3cf49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 16 deletions

View File

@ -9,3 +9,4 @@ configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
{% endif %}
configure system ip management pattern {{ ipv4 }}
{% endif %}
configure system hostname {{ DEVICE_METADATA['localhost']['hostname'] }}

View File

@ -73,17 +73,12 @@ def signal_handler(sig, frame):
# ========================== Helpers ==================================
def is_port_up(port_name):
filename = "/sys/class/net/%s/operstate" % port_name
def is_port_exist(port_name):
filename = "/sys/class/net/%s/ifindex" % 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
return True
# ============================== Classes ==============================
@ -159,8 +154,8 @@ 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
if not is_port_exist(port_name):
# it doesn't make any sense to configure lldpd if the target port does not exist
# let's postpone the command for the next iteration
continue

View File

@ -10,8 +10,6 @@ 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
@ -35,3 +33,6 @@ do
lldpcli -u /var/run/lldpd.socket -c /etc/lldpd.conf -c /etc/lldpd.d resume > /dev/null && break
sleep 1
done
supervisorctl start lldp-syncd
supervisorctl start lldpmgrd

View File

@ -538,10 +538,14 @@ def parse_xml(filename, platform=None, port_config_file=None):
ports.setdefault(port_name, {})['description'] = port_descriptions[port_name]
# for the ports w/o description set it to alias, or port name
for port_name, port in ports.items():
if not port.get('description'):
port['description'] = port.get('alias', port_name)
if neighbors.has_key(port_name):
# for the ports w/o description set it to neighbor name:port
port['description'] = "%s:%s" % (neighbors[port_name]['name'], neighbors[port_name]['port'])
else:
# for the ports w/o neighbor info, set it to port alias
port['description'] = port.get('alias', port_name)
# set default port MTU as 9100
for port in ports.itervalues():

View File

@ -1,3 +1,3 @@
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.0.0.100
configure system hostname switch-t0

View File

@ -151,6 +151,11 @@ class TestCfgGen(TestCase):
"'Ethernet112': {'name': 'ARISTA01T1', 'port': 'Ethernet1/1'}, "
"'Ethernet120': {'name': 'ARISTA03T1', 'port': 'Ethernet1/1'}}")
def test_minigraph_port_description(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet124\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/124', 'admin_status': 'up', 'lanes': '101,102,103,104', 'description': 'ARISTA04T1:Ethernet1/1', 'mtu': '9100'}")
def test_minigraph_bgp(self):
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v "BGP_NEIGHBOR[\'10.0.0.59\']"'
output = self.run_script(argument)

@ -1 +1 @@
Subproject commit 1cdcffc08f6ea1c3fc53f7aeeef5b5632124496f
Subproject commit fe60afa7e24a7053a7bd9d7084268c1bbd203208