[lldpmgrd] Convert to Python 3 (#5785)

- Convert lldpmgrd to Python 3
- Install Python 3 swsscommon package in docker-lldp
This commit is contained in:
Joe LeVeque 2020-11-03 12:50:11 -08:00 committed by GitHub
parent 0a1c5792a1
commit e3164d5fb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
""" """
lldpmgrd lldpmgrd
@ -18,10 +18,8 @@ try:
import os import os
import subprocess import subprocess
import sys import sys
import syslog
import os.path
import time import time
from sonic_py_common import daemon_base from sonic_py_common import daemon_base
from swsscommon import swsscommon from swsscommon import swsscommon
except ImportError as err: except ImportError as err:
@ -74,7 +72,7 @@ class LldpManager(daemon_base.DaemonBase):
port_table_dict = dict(fvp) port_table_dict = dict(fvp)
# Get the oper-status for the port # Get the oper-status for the port
if port_table_dict.has_key("oper_status"): if "oper_status" in port_table_dict:
port_oper_status = port_table_dict.get("oper_status") port_oper_status = port_table_dict.get("oper_status")
self.log_info("Port name {} oper status: {}".format(port_name, port_oper_status)) self.log_info("Port name {} oper status: {}".format(port_name, port_oper_status))
return port_oper_status == "up" return port_oper_status == "up"
@ -131,7 +129,7 @@ class LldpManager(daemon_base.DaemonBase):
# List of port names (keys of elements) to delete from self.pending_cmds # List of port names (keys of elements) to delete from self.pending_cmds
to_delete = [] to_delete = []
for (port_name, cmd) in self.pending_cmds.iteritems(): for (port_name, cmd) in self.pending_cmds.items():
self.log_debug("Running command: '{}'".format(cmd)) self.log_debug("Running command: '{}'".format(cmd))
rc, stderr = run_cmd(self, cmd) rc, stderr = run_cmd(self, cmd)
@ -195,7 +193,7 @@ class LldpManager(daemon_base.DaemonBase):
fvp_dict = dict(fvp) fvp_dict = dict(fvp)
# handle config change # handle config change
if (fvp_dict.has_key("alias") or fvp_dict.has_key("description")) and (op in ["SET", "DEL"]): if ("alias" in fvp_dict or "description" in fvp_dict) and (op in ["SET", "DEL"]):
if self.is_port_up(key): if self.is_port_up(key):
self.generate_pending_lldp_config_cmd_for_port(key) self.generate_pending_lldp_config_cmd_for_port(key)
else: else:
@ -207,7 +205,7 @@ class LldpManager(daemon_base.DaemonBase):
fvp_dict = dict(fvp) fvp_dict = dict(fvp)
# handle port status change # handle port status change
if fvp_dict.has_key("oper_status"): if "oper_status" in fvp_dict:
if "up" in fvp_dict.get("oper_status"): if "up" in fvp_dict.get("oper_status"):
self.generate_pending_lldp_config_cmd_for_port(key) self.generate_pending_lldp_config_cmd_for_port(key)
else: else:
@ -245,7 +243,7 @@ def main():
lldpmgr.run() lldpmgr.run()
def run_cmd(self, cmd): def run_cmd(self, cmd):
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc = subprocess.Popen(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate() (stdout, stderr) = proc.communicate()
return proc.returncode, stderr return proc.returncode, stderr

View File

@ -6,7 +6,7 @@ DOCKER_LLDP_DBG = $(DOCKER_LLDP_STEM)-$(DBG_IMAGE_MARK).gz
$(DOCKER_LLDP)_PATH = $(DOCKERS_PATH)/docker-lldp $(DOCKER_LLDP)_PATH = $(DOCKERS_PATH)/docker-lldp
$(DOCKER_LLDP)_DEPENDS += $(LLDPD) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(DOCKER_LLDP)_DEPENDS += $(LLDPD) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(PYTHON3_SWSSCOMMON)
$(DOCKER_LLDP)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS) $(DOCKER_LLDP)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS)
$(DOCKER_LLDP)_DBG_DEPENDS += $(LLDPD_DBG) $(LIBSWSSCOMMON_DBG) $(DOCKER_LLDP)_DBG_DEPENDS += $(LLDPD_DBG) $(LIBSWSSCOMMON_DBG)