Skip to content

Commit

Permalink
[xcvrd] Use new logger implementation and enable runtime log level co…
Browse files Browse the repository at this point in the history
…nfiguration (#515)

* [xcvrd] Use new logger implementation and enable runtime log level configuration

* Update xcvrd.py

* Add unit test for signal handler
  • Loading branch information
Junchao-Mellanox authored Nov 4, 2024
1 parent fc557a1 commit 0cb3644
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() != {}
Expand Down
9 changes: 5 additions & 4 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 =============================================================
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/optics_si_parser.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 0cb3644

Please sign in to comment.