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

[Mellanox] adjust log for Nvidia platform API #17829

Closed
Closed
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
14 changes: 6 additions & 8 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,11 +24,11 @@

try:
from sonic_platform_base.chassis_base import ChassisBase
from sonic_py_common.logger import Logger
import os
from functools import reduce
from .utils import extract_RJ45_ports_index
from . import utils
from .logger import logger
from .device_data import DeviceDataManager
import re
import queue
Expand Down Expand Up @@ -70,8 +70,6 @@
REBOOT_TYPE_KEXEC_PATTERN_WARM = ".*SONIC_BOOT_TYPE=(warm|fastfast).*"
REBOOT_TYPE_KEXEC_PATTERN_FAST = ".*SONIC_BOOT_TYPE=(fast|fast-reboot).*"

# Global logger class instance
logger = Logger()

class Chassis(ChassisBase):
"""Platform-specific Chassis class"""
Expand Down Expand Up @@ -423,11 +421,11 @@ def get_change_event(self, timeout=0):
i = 0
while True:
try:
logger.log_info(f'get_change_event() trying to get changes from queue on iteration {i}')
logger.log_debug(f'get_change_event() trying to get changes from queue on iteration {i}')
port_dict = self.modules_changes_queue.get(timeout=timeout / 1000)
logger.log_info(f'get_change_event() iteration {i} port_dict: {port_dict}')
except queue.Empty:
logger.log_info(f"failed to get item from modules changes queue on itertaion {i}")
logger.log_debug(f"change queue is empty in iteration {i}")

if port_dict:
self.reinit_sfps(port_dict)
Expand All @@ -437,9 +435,9 @@ def get_change_event(self, timeout=0):
else:
if not wait_for_ever:
elapse = time.time() - begin
logger.log_info(f"get_change_event: wait_for_ever {wait_for_ever} elapse {elapse} iteartion {i}")
logger.log_debug(f"get_change_event: wait_for_ever {wait_for_ever} elapse {elapse} iteration {i}")
if elapse * 1000 >= timeout:
logger.log_info(f"elapse {elapse} > timeout {timeout} iteartion {i} returning empty dict")
logger.log_debug(f"elapse {elapse} > timeout {timeout} iteration {i} returning empty dict")
return True, {'sfp': {}}
i += 1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,7 +24,7 @@
import os
import subprocess

from sonic_py_common.logger import Logger
from .logger import logger
try:
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
except ImportError as e:
Expand All @@ -33,8 +33,6 @@
from .device_data import DeviceDataManager
from .utils import default_return, is_host, wait_until

logger = Logger()

#
# this is mlnx-specific
# should this be moved to chassis.py or here, which better?
Expand Down
7 changes: 2 additions & 5 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2019-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,17 +27,14 @@

try:
from sonic_platform_base.fan_base import FanBase
from sonic_py_common.logger import Logger
from .led import ComponentFaultyIndicator
from .logger import logger
from . import utils
from .thermal import Thermal
from .fan_drawer import VirtualDrawer
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

# Global logger class instance
logger = Logger()

PWM_MAX = 255

FAN_PATH = "/var/run/hw-management/thermal/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,15 +27,12 @@
try:
from sonic_platform_base.fan_drawer_base import FanDrawerBase
from sonic_platform_base.fan_base import FanBase
from sonic_py_common.logger import Logger
from .led import FanLed, SharedLed
from .logger import logger
from . import utils
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

# Global logger class instance
logger = Logger()


class MellanoxFanDrawer(FanDrawerBase):
def __init__(self, index):
Expand Down
6 changes: 2 additions & 4 deletions platform/mellanox/mlnx-platform-api/sonic_platform/led.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,12 +17,10 @@
import os
import time

from sonic_py_common.logger import Logger
from .logger import logger
from . import utils
from . import device_data

logger = Logger()


class Led(object):
STATUS_LED_COLOR_GREEN = 'green'
Expand Down
30 changes: 30 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os
from sonic_py_common.logger import Logger

# Global logger instance for nvidia platform API, the argument "enable_set_log_level_on_fly"
# will start a thread to detect CONFIG DB LOGGER table change. The logger instance
# allow user to set log level via swssloglevel command at real time. This instance
# should be shared by all modules of platform API to avoid starting too many logger thread.
if os.environ.get("PLATFORM_API_UNIT_TESTING") != "1":
# platform API is a lib, let caller set the log identifier
logger = Logger(enable_set_log_level_on_fly=True)
else:
# for unit test, there is no redis, don't set enable_set_log_level_on_fly=True
logger = Logger()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES.
# Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,11 +22,9 @@

from . import utils
from .device_data import DeviceDataManager
from .logger import logger
from .vpd_parser import VpdParser

# Global logger class instance
logger = Logger()


class Module(ModuleBase):
STATE_ACTIVATED = 1
Expand Down
Loading