From 1bdcff5bdec3a1d3dbd2c5653d8371677c970843 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Wed, 19 Jun 2024 07:32:55 +0300 Subject: [PATCH 1/3] [xcvrd] Use new logger implementation and enable runtime log level configuration --- sonic-xcvrd/xcvrd/xcvrd.py | 9 +++++---- .../xcvrd/xcvrd_utilities/media_settings_parser.py | 4 ++-- sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index 72aff4900..bcc0a67dc 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 ============================================================= @@ -2388,7 +2388,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 @@ -2399,7 +2399,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...") + syslogger.SysLogger.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 9e79e6c7b..e70cc6b01 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py @@ -6,7 +6,7 @@ import os import ast -from sonic_py_common import device_info, logger +from sonic_py_common import device_info, syslogger from swsscommon import swsscommon from xcvrd import xcvrd @@ -17,7 +17,7 @@ MEDIA_KEY = 'media_key' LANE_SPEED_KEY = 'lane_speed_key' SYSLOG_IDENTIFIER = "xcvrd" -helper_logger = logger.Logger(SYSLOG_IDENTIFIER) +helper_logger = syslogger.SysLogger(SYSLOG_IDENTIFIER, enable_runtime_config=True) def load_media_settings(): 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' From 30976e45ea043b0d00837ecae51045d6e8ad75ac Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:19:48 +0800 Subject: [PATCH 2/3] Update xcvrd.py --- sonic-xcvrd/xcvrd/xcvrd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index bcc0a67dc..d400566c8 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -2400,7 +2400,7 @@ def __init__(self, log_identifier, skip_cmis_mgr=False, enable_sff_mgr=False): def signal_handler(self, sig, frame): if sig == signal.SIGHUP: self.log_notice("Caught SIGHUP...") - syslogger.SysLogger.update_log_level() + self.update_log_level() elif sig == signal.SIGINT: self.log_info("Caught SIGINT - exiting...") self.stop_event.set() From e3e3b08408ad983d62d30c0b4c22941419bf5e03 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Wed, 30 Oct 2024 09:16:06 +0200 Subject: [PATCH 3/3] Add unit test for signal handler --- sonic-xcvrd/tests/test_xcvrd.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 11b7f4e89..25ccca2ed 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -2958,6 +2958,13 @@ def test_DaemonXcvrd_init_deinit_cold(self): xcvrdaemon.deinit() 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):