Example #1
0
def main():
    logger = Logger(SYSLOG_IDENTIFIER)
    logger.set_min_log_priority_info()

    if os.getuid() != 0:
        logger.log_error('Root required to clean up core files')
        return

    logger.log_info('Cleaning up core files')
    core_files = [f for f in os.listdir(CORE_FILE_DIR) if os.path.isfile(os.path.join(CORE_FILE_DIR, f))]

    core_files_by_process = defaultdict(list)
    for f in core_files:
        process = f.split('.')[0]
        curr_files = core_files_by_process[process]
        curr_files.append(f)

        if len(curr_files) > MAX_CORE_FILES:
            curr_files.sort(reverse = True, key = lambda x: datetime.utcfromtimestamp(int(x.split('.')[1])))
            oldest_core = curr_files[MAX_CORE_FILES]
            logger.log_info('Deleting {}'.format(oldest_core))
            try:
                os.remove(os.path.join(CORE_FILE_DIR, oldest_core))
            except:
                logger.log_error('Unexpected error occured trying to delete {}'.format(oldest_core))
            core_files_by_process[process] = curr_files[0:MAX_CORE_FILES]

    logger.log_info('Finished cleaning up core files')
Example #2
0
    def __init__(self, sfp_list):
        self._api_common = Common()
        self._sfp_list = sfp_list
        self._logger = Logger()

        # clear interrupt
        self._api_common.read_one_line_file(self.INT_PATH)
Example #3
0
def main():
    logger = Logger(SYSLOG_IDENTIFIER)
    logger.set_min_log_priority_info()

    if len(sys.argv) != 3:
        raise Exception('Pass service and valid asic-id as arguments')

    service = sys.argv[1]
    args_asic_id = sys.argv[2]

    # Get num asics
    num_asics = multi_asic.get_num_asics()
    if num_asics == 0:
        logger.log_error(
            'Detected no asics on this platform for service {}'.format(
                service))
        sys.exit(1)

    # Connect to STATE_DB and subscribe to chassis-module table notifications
    state_db = daemon_base.db_connect("CHASSIS_STATE_DB")

    sel = swsscommon.Select()
    sst = swsscommon.SubscriberStateTable(state_db, CHASSIS_ASIC_INFO_TABLE)
    sel.addSelectable(sst)

    while True:
        (state, c) = sel.select(SELECT_TIMEOUT_MSECS)
        if state == swsscommon.Select.TIMEOUT:
            continue
        if state != swsscommon.Select.OBJECT:
            continue

        (asic_key, asic_op, asic_fvp) = sst.pop()
        asic_id = re.search(r'\d+$', asic_key)
        global_asic_id = asic_id.group(0)

        if asic_op == 'SET':
            asic_fvs = dict(asic_fvp)
            asic_name = asic_fvs.get('name')
            if asic_name is None:
                logger.log_info('Unable to get asic_name for asic{}'.format(
                    global_asic_id))
                continue

            if asic_name.startswith('FABRIC-CARD') is False:
                logger.log_info(
                    'Skipping module with asic_name {} for asic{}'.format(
                        asic_name, global_asic_id))
                continue

            if (global_asic_id == args_asic_id):
                logger.log_info(
                    'Detected asic{} is online'.format(global_asic_id))
                sys.exit(0)
        elif asic_op == 'DEL':
            logger.log_info(
                'Detected asic{} is offline'.format(global_asic_id))
            sys.exit(1)
        else:
            continue
Example #4
0
    def __init__(self, sfp_list):
        self._api_helper = APIHelper()
        self._sfp_list = sfp_list
        self._logger = Logger()

        # clear interrupt
        self._api_helper.read_one_line_file(self.INT_PATH)
#
# Third-Party Code: This code may depend on other components under separate
# copyright notice and license terms.  Your use of the source code for those
# components is subject to the terms and conditions of the respective license
# as noted in the Third-Party source code file.

import time
import os.path
import sfputil as jnpr_sfp
from sonic_py_common.logger import Logger
from pprint import pprint

SYSLOG_IDENTIFIER = "sfputil"

# Global logger class instance
logger = Logger(SYSLOG_IDENTIFIER)

DEBUG = False


def i2c_eeprom_dev_update(port, create_eeprom):
    eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom"
    i2c_path = "/sys/class/i2c-adapter/i2c-{0}"
    i2c_port = port + jnpr_sfp.SFP_I2C_OFFSET
    port_eeprom_path = eeprom_path.format(i2c_port)
    port_i2c_path = i2c_path.format(i2c_port)
    if create_eeprom:
        if not os.path.exists(port_eeprom_path):
            try:
                i2c_file = open(port_i2c_path + "/new_device", "w")
                i2c_file.write("optoe2 0x50")
Example #6
0
 def __init__(self, sfp_list):
     self._api_helper = APIHelper()
     self._sfp_list = sfp_list
     self._logger = Logger()
     self._sfp_change_event_data = {'present': 0}
Example #7
0
from __future__ import print_function

try:
    from sonic_platform_base.watchdog_base import WatchdogBase
    from sonic_py_common.logger import Logger

except ImportError as e:
    raise ImportError(str(e) + "- required module not found")
logger = Logger("wdog")


class Watchdog(WatchdogBase):
    _initialized = False

    def __init__(self, watchdog):
        # logger.set_min_log_priority_info()
        logger.log_info("Watchdog __init__{}".format(self))

    def arm(self, seconds):
        self._initialized = True
        logger.log_info("Watchdog arm")
        # hook this up to actual kicker shortly
        return seconds

    def disarm(self):
        logger.log_info("Watchdog disarm")
        return False

    def is_armed(self):
        if self._initialized is True:
            logger.log_info("Watchdog is_armed")
Example #8
0
 def __init__(self, sfp_list):
     self._api_helper = APIHelper()
     self._sfp_list = sfp_list
     self._logger = Logger()
Example #9
0
import docker
import os
import pickle
import re

from swsscommon import swsscommon
from sonic_py_common import multi_asic
from sonic_py_common.logger import Logger
from .health_checker import HealthChecker
from . import utils

SYSLOG_IDENTIFIER = 'service_checker'
logger = Logger(log_identifier=SYSLOG_IDENTIFIER)


class ServiceChecker(HealthChecker):
    """
    Checker that checks critical system service status via monit service.
    """

    # Cache file to save container_critical_processes
    CRITICAL_PROCESS_CACHE = '/tmp/critical_process_cache'

    CRITICAL_PROCESSES_PATH = 'etc/supervisor/critical_processes'

    # Command to get merged directory of a container
    GET_CONTAINER_FOLDER_CMD = 'docker inspect {} --format "{{{{.GraphDriver.Data.MergedDir}}}}"'

    # Command to query the status of monit service.
    CHECK_MONIT_SERVICE_CMD = 'systemctl is-active monit.service'
Example #10
0
#!/usr/bin/env python

try:
    import os
    import copy
    from sonic_py_common.logger import Logger
except ImportError as e:
    raise ImportError(str(e) + "- required module not found")

logger = Logger("platDev")
PLATFORM_NAME = "aurora-715"
MAX_FAN_MODULE = 5
MAX_FAN = 2

THERMAL_SENSOR_LIST = [{
    'name': "pch_haswell",
    'temp_index': [1],
    'sysfile_path': "/sys/class/hwmon/hwmon0/",
    'support_mask': 0x81,
    'ext_sysfile_list': None
}, {
    'name': "CPU core temp",
    'temp_index': [1, 2],
    'sysfile_path': "/sys/class/hwmon/hwmon1/",
    'support_mask': 0x8B,
    'ext_sysfile_list': None
}, {
    'name': "NCT7511Y(U73)",
    'temp_index': [1, 2],
    'sysfile_path': "/sys/class/hwmon/hwmon2/device/NBA715_THERMAL/",
    'support_mask': 0x0F,
Example #11
0
    from sonic_platform_base.module_base import ModuleBase
    from sonic_platform.module import Module
    from sonic_platform.psu import Psu
    from sonic_platform.thermal import Thermal
    from sonic_platform.fan_drawer import FanDrawer
    from sonic_platform.fan import Fan
    from sonic_platform.component import Component
    from sonic_platform.watchdog import Watchdog
    from sonic_platform.eeprom import Eeprom
    from sonic_py_common.logger import Logger
    from platform_ndk import nokia_common
    from platform_ndk import platform_ndk_pb2

except ImportError as e:
    raise ImportError(str(e) + "- required module not found")
logger = Logger("Chassis")

# Support for vodka only here.  Need to modify this logic later to discern actual
# number of ASICs and ports per prior to next platform
NUM_SFP = 36


class Chassis(ChassisBase):
    """
    NOKIA IXR7250 Platform-specific Chassis class
    """

    REBOOT_CAUSE_DICT = {
        'powerloss': ChassisBase.REBOOT_CAUSE_POWER_LOSS,
        'overtemp': ChassisBase.REBOOT_CAUSE_THERMAL_OVERLOAD_OTHER,
        'reboot': ChassisBase.REBOOT_CAUSE_NON_HARDWARE,
Example #12
0
#
# Description: Module contains the definitions of SONiC platform APIs
#

try:
    from sonic_platform_base.psu_base import PsuBase
    from sonic_py_common.logger import Logger
    from sonic_platform.fan import Fan, FanConst
except ImportError as e:
    raise ImportError(str(e) + "- required module not found")

VOLTAGE_UPPER_LIMIT = 14
VOLTAGE_LOWER_LIMIT = 10

PSU_SYS_FS = "/sys/devices/virtual/hwmon/hwmon1/device/"
logger = Logger('sonic-platform-psu')


class Psu(PsuBase):

    __num_of_fans = 1
    __name_of_psus = ['PSU1', 'PSU2']

    def __init__(self, index):
        self.__index = index
        self.__psu_presence_attr = PSU_SYS_FS + "psu{}".format(self.__index +
                                                               1)
        self.__psu_voltage_out_attr = PSU_SYS_FS + \
            "psoc_psu{}_vout".format(self.__index + 1)
        self.__psu_current_out_attr = PSU_SYS_FS + \
            "psoc_psu{}_iout".format(self.__index + 1)
Example #13
0
#############################################################################
#
# Module contains an implementation of SONiC Platform Base API and
# provides the PSUs status which are available in the platform
#
#############################################################################

try:
    from sonic_py_common.logger import Logger
    from sonic_platform_base.thermal_base import ThermalBase
except ImportError as e:
    raise ImportError(str(e) + "- required module not found")

logger = Logger("thermal")


class Thermal(ThermalBase):
    """Platform-specific Thermal class"""
    def __init__(self,
                 index,
                 name,
                 sysfile_path,
                 is_bmc,
                 support_mask=0x1,
                 ext_sysfile_list=None):
        # index is used to indicate the temp{} under sffile_path
        # support_mask:  1:support  0:not support
        #   bit 0 : temperature (always 1)
        #   bit 1 : high threshold
        #   bit 2 : low threshold
        #   bit 3 : high critical threshold
Example #14
0
from sonic_platform_base.sonic_thermal_control.thermal_info_base import ThermalPolicyInfoBase
from sonic_platform_base.sonic_thermal_control.thermal_json_object import thermal_json_object
from sonic_py_common import daemon_base
from sonic_py_common.logger import Logger
from swsscommon import swsscommon
from sonic_platform_base.module_base import ModuleBase

logger = Logger('thermal_infos')


@thermal_json_object('fan_info')
class FanInfo(ThermalPolicyInfoBase):
    """
    FanOverride information needed by thermal policy
    """
    INFO_NAME = 'fan_info'

    def __init__(self):
        self._chassis = None
        self._fan_platform_override = False

    def collect(self, chassis):
        """
        Collect platform chassis.
        :param chassis: The chassis object
        :return:
        """
        self._chassis = chassis

    def get_fanalgo_override(self):
        """
Example #15
0
from sonic_platform_base.sonic_thermal_control.thermal_action_base import ThermalPolicyActionBase
from sonic_platform_base.sonic_thermal_control.thermal_json_object import thermal_json_object

from sonic_py_common.logger import Logger
from platform_ndk import nokia_common
from platform_ndk import platform_ndk_pb2

logger = Logger('thermal_actions')


@thermal_json_object('thermal.platform.publish')
class PublishThermalAlgoAction(ThermalPolicyActionBase):
    """
    Action to publish thermal information to platform
    """

    def execute(self, thermal_info_dict):
        """
        Publish thermal information to platform
        :param thermal_info_dict: A dictionary stores all thermal information.
        :return:
        """
        from .thermal_infos import ChassisInfo
        from .thermal_infos import ThermalInfo
        if ChassisInfo.INFO_NAME in thermal_info_dict:
            # chassis_info_obj = thermal_info_dict[ChassisInfo.INFO_NAME]
            # chassis = chassis_info_obj.get_chassis()
            pass
        else:
            return
Example #16
0
#

from __future__ import print_function
import os
import time
import subprocess
from swsscommon import swsscommon
from platform_ndk import nokia_common
from platform_ndk import platform_ndk_pb2
from sonic_platform.sfp import Sfp
from sonic_py_common.logger import Logger
from sonic_py_common import daemon_base

# from sfp.Sfp import SfpHasBeenTransitioned

logger = Logger("sfp_event")

MAX_NOKIA_SFP_EVENT_SLEEP_TIME = 5
TRANSCEIVER_INFO_TABLE = 'TRANSCEIVER_INFO'
SFPEVENT_TOTAL_NUM_TESTS = 4

# @todo-nokia Remove once the below APIs are present in util_base.py as part of PDDF
PLATFORM_ROOT_DOCKER = '/usr/share/sonic/platform'
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku'
PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform'


class sfp_event:
    ''' Listen to plugin/plugout cable events '''
    def __init__(self, num_ports, stub):
Example #17
0
PORT_TYPE_MASK = 0xF0000000
NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET)
CPU_MASK = PORT_TYPE_MASK & (PORT_TYPE_CPU << PORT_TYPE_OFFSET)

# parameters for SFP presence
SFP_STATUS_INSERTED = '1'

# SFP constants
SFP_PAGE_SIZE = 256
SFP_UPPER_PAGE_OFFSET = 128
SFP_VENDOR_PAGE_START = 640

BYTES_IN_DWORD = 4

# Global logger class instance
logger = Logger()


# SDK initializing stuff, called from chassis
def initialize_sdk_handle():
    rc, sdk_handle = sx_api_open(None)
    if (rc != SX_STATUS_SUCCESS):
        logger.log_warning(
            "Failed to open api handle, please check whether SDK is running.")
        sdk_handle = None

    return sdk_handle


def deinitialize_sdk_handle(sdk_handle):
    if sdk_handle is not None:
Example #18
0
    from sonic_py_common.logger import Logger
except ImportError as e:
    raise ImportError(str(e) + "- required module not found")

MAX_SPEED_OF_FAN_FRONT = 23000
MAX_SPEED_OF_FAN_BACK = 20500
MAX_SPEED_OF_FAN_PSU = 18100
MAX_PWM_OF_FAN = 255


class FanConst:
    FAN_PSU_START_INDEX = 4


FAN_SYS_FS = "/sys/devices/virtual/hwmon/hwmon1/"
logger = Logger('sonic-platform-fan')


class Fan(FanBase):

    __name_of_fans = ['FAN1', 'FAN2', 'FAN3', 'FAN4', 'PSU1_FAN1', 'PSU2_FAN1']
    __start_of_psu_fans = FanConst().FAN_PSU_START_INDEX
    __fan_gpi_attr = FAN_SYS_FS + "fan_gpi"

    def __init__(self, index):
        self.__index = index

        if self.__index >= self.__start_of_psu_fans:
            self.__presence_attr = FAN_SYS_FS + \
                "psu{}".format(self.__index - self.__start_of_psu_fans + 1)
            self.__pwm_attr = FAN_SYS_FS + \