diff --git a/sonic-chassisd/scripts/chassisd b/sonic-chassisd/scripts/chassisd index 3e3b5d264..3017f52d3 100755 --- a/sonic-chassisd/scripts/chassisd +++ b/sonic-chassisd/scripts/chassisd @@ -414,13 +414,14 @@ class ModuleUpdater(logger.Logger): self.hostname_table.set(hostname_key, hostname_fvs) # Asics that are on the "not online" modules need to be cleaned up - asics = list(self.asic_table.getKeys()) - for asic in asics: - fvs = self.asic_table.get(asic) - if isinstance(fvs, list): - fvs = dict(fvs[-1]) - if fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules: - self.asic_table._del(asic) + if notOnlineModules: + asics = list(self.asic_table.getKeys()) + for asic in asics: + fvs = self.asic_table.get(asic) + if isinstance(fvs, list): + fvs = dict(fvs[-1]) + if CHASSIS_MODULE_INFO_NAME_FIELD in fvs.keys() and fvs[CHASSIS_MODULE_INFO_NAME_FIELD] in notOnlineModules: + self.asic_table._del(asic) def _get_module_info(self, module_index): """ diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index bd7eda753..e5b7d3180 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -3347,6 +3347,13 @@ def test_DaemonXcvrd_init_deinit_cold(self): status_tbl.hdel.assert_called() + def test_DaemonXcvrd_signal_handler(self): + xcvrd.platform_chassis = MagicMock() + xcvrdaemon = DaemonXcvrd(SYSLOG_IDENTIFIER) + xcvrdaemon.update_log_level = MagicMock() + xcvrdaemon.signal_handler(signal.SIGHUP, None) + xcvrdaemon.update_log_level.assert_called() + @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=(test_path, '/invalid/path'))) def test_load_optical_si_file_from_platform_folder(self): assert optics_si_parser.load_optics_si_settings() != {} diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index 89789899f..0c6e9dded 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -22,7 +22,7 @@ import ctypes from natsort import natsorted - from sonic_py_common import daemon_base, device_info, logger + from sonic_py_common import daemon_base, syslogger from sonic_py_common import multi_asic from swsscommon import swsscommon @@ -116,7 +116,7 @@ # Global logger instance for helper functions and classes # TODO: Refactor so that we only need the logger inherited # by DaemonXcvrd -helper_logger = logger.Logger(SYSLOG_IDENTIFIER) +helper_logger = syslogger.SysLogger(SYSLOG_IDENTIFIER, enable_runtime_config=True) # # Helper functions ============================================================= @@ -2053,7 +2053,7 @@ def retry_eeprom_reading(self): class DaemonXcvrd(daemon_base.DaemonBase): def __init__(self, log_identifier, skip_cmis_mgr=False, enable_sff_mgr=False): - super(DaemonXcvrd, self).__init__(log_identifier) + super(DaemonXcvrd, self).__init__(log_identifier, enable_runtime_log_config=True) self.stop_event = threading.Event() self.sfp_error_event = threading.Event() self.skip_cmis_mgr = skip_cmis_mgr @@ -2064,7 +2064,8 @@ def __init__(self, log_identifier, skip_cmis_mgr=False, enable_sff_mgr=False): # Signal handler def signal_handler(self, sig, frame): if sig == signal.SIGHUP: - self.log_info("Caught SIGHUP - ignoring...") + self.log_notice("Caught SIGHUP...") + self.update_log_level() elif sig == signal.SIGINT: self.log_info("Caught SIGINT - exiting...") self.stop_event.set() diff --git a/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py b/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py index 7d584600d..6a746c71f 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py @@ -8,7 +8,7 @@ import re from natsort import natsorted -from sonic_py_common import device_info, logger +from sonic_py_common import device_info, syslogger from swsscommon import swsscommon from xcvrd import xcvrd from .xcvr_table_helper import * @@ -23,7 +23,7 @@ # This is useful if default value is desired when no match is found for lane speed key LANE_SPEED_DEFAULT_KEY = LANE_SPEED_KEY_PREFIX + DEFAULT_KEY SYSLOG_IDENTIFIER = "xcvrd" -helper_logger = logger.Logger(SYSLOG_IDENTIFIER) +helper_logger = syslogger.SysLogger(SYSLOG_IDENTIFIER, enable_runtime_config=True) PHYSICAL_PORT_NOT_EXIST = -1 diff --git a/sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py b/sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py index f1fc07315..268e2bcae 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py @@ -1,13 +1,13 @@ import json import os -from sonic_py_common import device_info, logger +from sonic_py_common import device_info, syslogger from xcvrd import xcvrd g_optics_si_dict = {} SYSLOG_IDENTIFIER = "xcvrd" -helper_logger = logger.Logger(SYSLOG_IDENTIFIER) +helper_logger = syslogger.SysLogger(SYSLOG_IDENTIFIER, enable_runtime_config=True) def get_optics_si_settings_value(physical_port, lane_speed, key, vendor_name_str): GLOBAL_MEDIA_SETTINGS_KEY = 'GLOBAL_MEDIA_SETTINGS'