Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading