From 7789a3479ca18365a543a49041b7fccc41a9ef86 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sat, 2 Feb 2019 08:40:00 +0200 Subject: [PATCH] Refactor daemons based on sonic-daemon-common package Signed-off-by: Kevin Wang --- sonic-ledd/scripts/ledd | 146 +++------------------------- sonic-psud/scripts/psud | 150 ++++------------------------ sonic-xcvrd/scripts/xcvrd | 200 ++++++++------------------------------ 3 files changed, 72 insertions(+), 424 deletions(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index 75a1d7e69..e62418752 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -15,6 +15,7 @@ try: import sys import syslog from swsscommon import swsscommon + from sonic_daemon_common.daemon_common import daemon_util except ImportError, e: raise ImportError (str(e) + " - required module not found") @@ -34,133 +35,18 @@ Options: LED_MODULE_NAME = "led_control" LED_CLASS_NAME = "LedControl" - -SONIC_CFGGEN = "/usr/local/bin/sonic-cfggen" -MINIGRAPH_FILE = "/etc/sonic/minigraph.xml" -HWSKU_KEY = "minigraph_hwsku" -PLATFORM_KEY = "platform" - -# platform directory in base image -PLATFORM_ROOT = "/usr/share/sonic/device" - -# platform root directory inside docker -PLATFORM_ROOT_DOCKER = "/usr/share/sonic/platform" - -REDIS_HOSTNAME = "localhost" -REDIS_PORT = 6379 -REDIS_TIMEOUT_USECS = 0 - SELECT_TIMEOUT = 1000 -#========================== Syslog wrappers ========================== - -def log_info(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - -def log_warning(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - -def log_error(msg): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - -#========================== Signal Handling ========================== - -def signal_handler(sig, frame): - if sig == signal.SIGHUP: - log_info("Caught SIGHUP - ignoring...") - return - elif sig == signal.SIGINT: - log_info("Caught SIGINT - exiting...") - sys.exit(128 + sig) - elif sig == signal.SIGTERM: - log_info("Caught SIGTERM - exiting...") - sys.exit(128 + sig) - else: - log_warning("Caught unhandled signal '" + sig + "'") - - -#============ Functions to load platform-specific classes ============ - -# Returns platform and HW SKU -def get_platform_and_hwsku(): - try: - proc = subprocess.Popen([SONIC_CFGGEN, '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN, '-m', MINIGRAPH_FILE, '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError, e: - log_error("Cannot detect platform") - raise OSError("Cannot detect platform") - - return (platform, hwsku) - - -# Loads platform-specific LED control module from source -def load_platform_led_control_module(): - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = '/'.join([PLATFORM_ROOT, platform]) - hwsku_path = '/'.join([platform_path, hwsku]) - - module_file_base = '/'.join([platform_path, 'plugins', LED_MODULE_NAME + '.py']) - - module_file_docker = '/'.join([PLATFORM_ROOT_DOCKER, 'plugins', LED_MODULE_NAME + '.py']) - - # If we can't locate a platform-specific module, exit gracefully, assuming this - # platform utilizes a hardware-based LED control solution - if os.path.isfile(module_file_base): - module_file = module_file_base - elif os.path.isfile(module_file_docker): - module_file = module_file_docker - else: - log_info("Failed to locate platform-specific %s module." % LED_MODULE_NAME) - return None - - try: - module = imp.load_source(LED_MODULE_NAME, module_file) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (LED_MODULE_NAME, str(e))) - return None - - log_info("Loaded module '%s'." % LED_MODULE_NAME) - - try: - led_control_class = getattr(module, LED_CLASS_NAME) - led_control = led_control_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (LED_CLASS_NAME, str(e))) - return None - - log_info("Instantiated class '%s.%s'." % (LED_MODULE_NAME, LED_CLASS_NAME)) - - return led_control - #=============================== Main ================================ def main(): - log_info("Starting up...") + ledd_util = daemon_util() + if not ledd_util: + print "Failed to load led daemon utilities" + sys.exit(1) if not os.geteuid() == 0: - log_error("Must be root to run this daemon") + ledd_util.log_error("Must be root to run this daemon") print "Error: Must be root to run this daemon" sys.exit(1) @@ -183,21 +69,17 @@ def main(): print 'ledd version ' + VERSION sys.exit(0) - # Register our signal handlers - signal.signal(signal.SIGHUP, signal_handler) - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) - # Load platform-specific LedControl module - led_control = load_platform_led_control_module() - if led_control is None: - sys.exit(0) + led_control = ledd_util.load_platform_util(LED_MODULE_NAME, LED_CLASS_NAME) + if not led_control: + ledd_util.log_error("failed to load ledutil") + sys.exit(1) # Open a handle to the Application database appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, - REDIS_HOSTNAME, - REDIS_PORT, - REDIS_TIMEOUT_USECS) + ledd_util.redis_hostname, + ledd_util.redis_port, + ledd_util.redis_timeout_usecs) # Subscribe to PORT table notifications in the Application DB sel = swsscommon.Select() @@ -214,7 +96,7 @@ def main(): # Do not flood log when select times out continue if state != swsscommon.Select.OBJECT: - log_warning("sel.select() did not return swsscommon.Select.OBJECT") + ledd_util.log_warning("sel.select() did not return swsscommon.Select.OBJECT") continue (key, op, fvp) = sst.pop() diff --git a/sonic-psud/scripts/psud b/sonic-psud/scripts/psud index 4c50a7dc2..a2aca19fe 100644 --- a/sonic-psud/scripts/psud +++ b/sonic-psud/scripts/psud @@ -1,7 +1,7 @@ #!/usr/bin/env python2 """ - Psud + psud PSU information update daemon for SONiC This daemon will loop to collect PSU related information and then write the information to state DB. Currently it is implemented based on old plugins rather than new platform APIs. So the PSU information just @@ -10,163 +10,48 @@ """ try: - import getopt - import os - import imp - import signal - import subprocess import sys - import syslog import time from swsscommon import swsscommon + from sonic_daemon_common.daemon_common import daemon_util except ImportError, e: raise ImportError (str(e) + " - required module not found") #============================= Constants ============================= -VERSION = '1.0' - -SYSLOG_IDENTIFIER = os.path.basename(__file__) PLATFORM_SPECIFIC_MODULE_NAME = "psuutil" PLATFORM_SPECIFIC_CLASS_NAME = "PsuUtil" -# Platform root directory inside docker -PLATFORM_ROOT_DOCKER = "/usr/share/sonic/platform" -SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' -HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' -PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' - -# Global platform-specific psuutil class instance -platform_psuutil = None - -REDIS_HOSTNAME = "localhost" -REDIS_PORT = 6379 -REDIS_TIMEOUT_MSECS = 0 - PSU_INFO_UPDATE_PERIOD_SECS = 3 -#========================== Syslog wrappers ========================== - -def log_info(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -def log_warning(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -def log_error(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -#========================== Signal Handling ========================== - -def signal_handler(sig, frame): - if sig == signal.SIGHUP: - log_info("Caught SIGHUP - ignoring...") - return - elif sig == signal.SIGINT: - log_info("Caught SIGINT - exiting...") - sys.exit(128 + sig) - elif sig == signal.SIGTERM: - log_info("Caught SIGTERM - exiting...") - sys.exit(128 + sig) - else: - log_warning("Caught unhandled signal '" + sig + "'") - return - #============ Functions to load platform-specific classes ============ -# Returns platform and HW SKU -def get_platform_and_hwsku(): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError, e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - -# Loads platform specific psuutil module from source -def load_platform_psuutil(): - global platform_psuutil - - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = PLATFORM_ROOT_DOCKER - hwsku_path = "/".join([platform_path, hwsku]) - - try: - module_file = "/".join([platform_path, "plugins", PLATFORM_SPECIFIC_MODULE_NAME + ".py"]) - module = imp.load_source(PLATFORM_SPECIFIC_MODULE_NAME, module_file) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (PLATFORM_SPECIFIC_MODULE_NAME, str(e)), True) - return -1 - - try: - platform_psuutil_class = getattr(module, PLATFORM_SPECIFIC_CLASS_NAME) - platform_psuutil = platform_psuutil_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_SPECIFIC_CLASS_NAME, str(e)), True) - return -2 - - return 0 - -def psu_db_update(psu_tbl, num_psus): +def psu_db_update(psuutil, psu_tbl, num_psus): for psu_index in range(1, num_psus + 1): fvs = swsscommon.FieldValuePairs([('presence', - 'true' if platform_psuutil.get_psu_presence(psu_index) else 'false'), + 'true' if psuutil.get_psu_presence(psu_index) else 'false'), ('status', - 'true' if platform_psuutil.get_psu_status(psu_index) else 'false')]) + 'true' if psuutil.get_psu_status(psu_index) else 'false')]) psu_tbl.set("PSU {}".format(psu_index), fvs) #=============================== Main ================================ def main(): - log_info("Starting up...") - - # Register our signal handlers - signal.signal(signal.SIGHUP, signal_handler) - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) + psud_util = daemon_util() + if not psud_util: + print "Failed to load psu daemon utilities" + sys.exit(1) # Load platform-specific psuutil class - err = load_platform_psuutil() - if err != 0: - log_error("failed to load psuutil") + platform_psuutil = psud_util.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME) + if not platform_psuutil: + psud_util.log_error("failed to load psuutil") sys.exit(1) state_db = swsscommon.DBConnector(swsscommon.STATE_DB, - REDIS_HOSTNAME, - REDIS_PORT, - REDIS_TIMEOUT_MSECS) + psud_util.redis_hostname, + psud_util.redis_port, + psud_util.redis_timeout_msecs) psu_tbl = swsscommon.Table(state_db, "PSU_INFO") chassis_tbl = swsscommon.Table(state_db, "CHASSIS_INFO") num_psus = platform_psuutil.get_num_psus() @@ -174,16 +59,15 @@ def main(): chassis_tbl.set('chassis 1', fvs) # Start main loop to listen to the PSU change event. - log_info("Start main loop") + psud_util.log_info("Start main loop") while True: - psu_db_update(psu_tbl, num_psus) + psu_db_update(platform_psuutil, psu_tbl, num_psus) time.sleep(PSU_INFO_UPDATE_PERIOD_SECS) # Clean all the information from DB and then exit for psu_index in range(1, num_psus + 1): psu_tbl._del("PSU {}".format(psu_index)) chassis_tbl._del('chassis 1') - log_error("Error: return error from psu daemon, exiting...") return 1 if __name__ == '__main__': diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 777719011..b5c88f319 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -1,50 +1,30 @@ #!/usr/bin/env python2 """ - Xcvrd + xcvrd Transceiver information update daemon for SONiC """ try: - import getopt import os - import imp - import signal - import subprocess import sys - import syslog import time import threading from swsscommon import swsscommon + from sonic_daemon_common.daemon_common import daemon_util except ImportError, e: raise ImportError (str(e) + " - required module not found") #============================= Constants ============================= -VERSION = '1.0' - -SYSLOG_IDENTIFIER = os.path.basename(__file__) - -PLATFORM_ROOT_PATH = '/usr/share/sonic/device' -SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' -HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' -PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' - PLATFORM_SPECIFIC_MODULE_NAME = "sfputil" PLATFORM_SPECIFIC_CLASS_NAME = "SfpUtil" # Global platform-specific sfputil class instance platform_sfputil = None +# Global xcvr dameon util class instance +xcvrd_util = None -# platform directory in base image -PLATFORM_ROOT = "/usr/share/sonic/device" - -# platform root directory inside docker -PLATFORM_ROOT_DOCKER = "/usr/share/sonic/platform" - -REDIS_HOSTNAME = "localhost" -REDIS_PORT = 6379 -REDIS_TIMEOUT_MSECS = 0 SELECT_TIMEOUT_MSECS = 1000 DOM_INFO_UPDATE_PERIOD_SECS = 60 @@ -61,122 +41,13 @@ VOLT_UNIT = 'Volts' POWER_UNIT = 'dBm' BIAS_UNIT = 'mA' -#========================== Syslog wrappers ========================== - -def log_info(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -def log_warning(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -def log_error(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - if also_print_to_console: - print msg - -#========================== Signal Handling ========================== - -def signal_handler(sig, frame): - if sig == signal.SIGHUP: - log_info("Caught SIGHUP - ignoring...") - return - elif sig == signal.SIGINT: - log_info("Caught SIGINT - exiting...") - sys.exit(128 + sig) - elif sig == signal.SIGTERM: - log_info("Caught SIGTERM - exiting...") - sys.exit(128 + sig) - else: - log_warning("Caught unhandled signal '" + sig + "'") - return - - -#============ Functions to load platform-specific classes ============ - -# Returns platform and HW SKU -def get_platform_and_hwsku(): - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - - return (platform, hwsku) - -# Loads platform specific sfputil module from source -def load_platform_sfputil(): - global platform_sfputil - - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = PLATFORM_ROOT_DOCKER - hwsku_path = "/".join([platform_path, hwsku]) - - try: - module_file = "/".join([platform_path, "plugins", PLATFORM_SPECIFIC_MODULE_NAME + ".py"]) - module = imp.load_source(PLATFORM_SPECIFIC_MODULE_NAME, module_file) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (PLATFORM_SPECIFIC_MODULE_NAME, str(e)), True) - return -1 - - try: - platform_sfputil_class = getattr(module, PLATFORM_SPECIFIC_CLASS_NAME) - platform_sfputil = platform_sfputil_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_SPECIFIC_CLASS_NAME, str(e)), True) - return -2 - - return 0 - -# Returns path to port config file -def get_path_to_port_config_file(): - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = PLATFORM_ROOT_DOCKER - hwsku_path = "/".join([platform_path, hwsku]) - - # First check for the presence of the new 'port_config.ini' file - port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) - if not os.path.isfile(port_config_file_path): - # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file - port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) - - return port_config_file_path - # find out the underneath physical port list by logical name def logical_port_name_to_physical_port_list(port_name): if port_name.startswith("Ethernet"): if platform_sfputil.is_logical_port(port_name): return platform_sfputil.get_logical_to_physical(port_name) else: - print "Error: Invalid port '%s'" % port_name + xcvrd_util.log_error("Invalid port '%s'" % port_name) return None else: return [int(port_name)] @@ -225,7 +96,7 @@ def post_port_sfp_info_to_db(logical_port_name, table): physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) if physical_port_list is None: - log_error("Error: No physical ports found for logical port '%s'" % logical_port_name) + xcvrd_util.log_error("No physical ports found for logical port '%s'" % logical_port_name) return PHYSICAL_PORT_NOT_EXIST if len(physical_port_list) > 1: @@ -251,7 +122,7 @@ def post_port_sfp_info_to_db(logical_port_name, table): return SFP_EEPROM_NOT_READY except NotImplementedError: - log_error("This functionality is currently not implemented for this platform") + xcvrd_util.log_error("This functionality is currently not implemented for this platform") sys.exit(3) # update dom sensor info to db @@ -261,7 +132,7 @@ def post_port_dom_info_to_db(logical_port_name, table): physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) if physical_port_list is None: - log_error("Error: No physical ports found for logical port '%s'" % logical_port_name) + xcvrd_util.log_error("No physical ports found for logical port '%s'" % logical_port_name) return PHYSICAL_PORT_NOT_EXIST if len(physical_port_list) > 1: @@ -297,7 +168,7 @@ def post_port_dom_info_to_db(logical_port_name, table): return SFP_EEPROM_NOT_READY except NotImplementedError: - log_error("This functionality is currently not implemented for this platform") + xcvrd_util.log_error("This functionality is currently not implemented for this platform") sys.exit(3) # del sfp and dom info from db @@ -307,7 +178,7 @@ def del_port_sfp_dom_info_to_db(logical_port_name, int_tbl, dom_tbl): physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) if physical_port_list is None: - log_error("Error: No physical ports found for logical port '%s'" % logical_port_name) + xcvrd_util.log_error("No physical ports found for logical port '%s'" % logical_port_name) return PHYSICAL_PORT_NOT_EXIST if len(physical_port_list) > 1: @@ -322,7 +193,7 @@ def del_port_sfp_dom_info_to_db(logical_port_name, int_tbl, dom_tbl): dom_tbl._del(port_name) except NotImplementedError: - log_error("This functionality is currently not implemented for this platform") + xcvrd_util.log_error("This functionality is currently not implemented for this platform") sys.exit(3) # Timer thread wrapper class to update dom info to DB periodically @@ -334,7 +205,7 @@ class dom_info_update_task: def task_run(self): if self.task_stopping_event.isSet(): - log_error("Error: dom info update thread received stop event, exiting...") + xcvrd_util.log_error("dom info update thread received stop event, exiting...") return logical_port_list = platform_sfputil.logical @@ -348,20 +219,32 @@ class dom_info_update_task: self.task_stopping_event.set() self.task_timer.join() +# Returns path to port config file +def get_path_to_port_config_file(): + (platform_path, hwsku_path) = xcvrd_util.get_path_to_platform_and_hwsku() + # First check for the presence of the new 'port_config.ini' file + port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) + if not os.path.isfile(port_config_file_path): + # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file + port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) + + return port_config_file_path + #=============================== Main ================================ def main(): - log_info("Starting up...") + global platform_sfputil + global xcvrd_util - # Register our signal handlers - signal.signal(signal.SIGHUP, signal_handler) - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) + xcvrd_util = daemon_util() + if not xcvrd_util: + print "Failed to load xcvrd daemon utilities" + sys.exit(1) # Load platform-specific sfputil class - err = load_platform_sfputil() - if err != 0: - log_error("failed to load sfputil") + platform_sfputil = xcvrd_util.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME) + if not platform_sfputil: + xcvrd_util.log_error("failed to load sfputil") sys.exit(1) # Load port info @@ -370,22 +253,22 @@ def main(): platform_sfputil.read_porttab_mappings(port_config_file_path) # platform_sfputil.read_port_mappings() except Exception, e: - log_error("Error reading port info (%s)" % str(e), True) + xcvrd_util.log_error("failed to reading port info (%s)" % str(e)) sys.exit(2) # Connect to STATE_DB and create transceiver info/dom info table state_db = swsscommon.DBConnector(swsscommon.STATE_DB, - REDIS_HOSTNAME, - REDIS_PORT, - REDIS_TIMEOUT_MSECS) + xcvrd_util.redis_hostname, + xcvrd_util.redis_port, + xcvrd_util.redis_timeout_msecs) int_tbl = swsscommon.Table(state_db, "TRANSCEIVER_INFO") dom_tbl = swsscommon.Table(state_db, "TRANSCEIVER_DOM_SENSOR") # Connect to APPL_DB abd subscribe to PORT table notifications appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, - REDIS_HOSTNAME, - REDIS_PORT, - REDIS_TIMEOUT_MSECS) + xcvrd_util.redis_hostname, + xcvrd_util.redis_port, + xcvrd_util.redis_timeout_msecs) sel = swsscommon.Select() sst = swsscommon.SubscriberStateTable(appl_db, swsscommon.APP_PORT_TABLE_NAME) @@ -397,7 +280,7 @@ def main(): if state == swsscommon.Select.TIMEOUT: continue if state != swsscommon.Select.OBJECT: - log_warning("sel.select() did not return swsscommon.Select.OBJECT") + xcvrd_util.log_warning("sel.select() did not return swsscommon.Select.OBJECT") continue (key, op, fvp) = sst.pop() @@ -415,7 +298,7 @@ def main(): dom_info_update.task_run() # Start main loop to listen to the SFP change event. - log_info("Start main loop") + xcvrd_util.log_info("Start main loop") while True: status, port_dict = platform_sfputil.get_transceiver_change_event() if status: @@ -447,7 +330,6 @@ def main(): logical_port_list = platform_sfputil.logical for logical_port_name in logical_port_list: del_port_sfp_dom_info_to_db(logical_port_name, int_tbl, dom_tbl) - log_error("Error: return error from get_transceiver_change_event(), exiting...") return 1 if __name__ == '__main__':