Skip to content

Commit

Permalink
configure lldp when the port exists
Browse files Browse the repository at this point in the history
On some platform, portstate might be unknown as it might not
be supported by the driver.

Signed-off-by: Guohan Lu <gulv@microsoft.com>
  • Loading branch information
lguohan committed Feb 12, 2019
1 parent 2543b71 commit c46852a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions dockers/docker-lldp-sv2/lldpmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==============================

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c46852a

Please sign in to comment.