[201911] Remove sonic-daemon-base package (#5181)

sonic-daemon-base package has been deprecated in favor of the sonic-py-common package. All related functionality has been moved there.

This is a backport of https://github.com/Azure/sonic-buildimage/pull/5131 and parts of https://github.com/Azure/sonic-buildimage/pull/5168 to the 201911 branch
This commit is contained in:
Joe LeVeque 2020-08-22 17:55:27 -07:00 committed by GitHub
parent 0b64588696
commit 9048d7ae4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2 additions and 309 deletions

4
.gitignore vendored
View File

@ -142,10 +142,6 @@ src/sonic-config-engine/**/*.pyc
src/sonic-config-engine/build src/sonic-config-engine/build
src/sonic-config-engine/sonic_config_engine.egg-info src/sonic-config-engine/sonic_config_engine.egg-info
src/sonic-daemon-base/**/*.pyc
src/sonic-daemon-base/build
src/sonic-daemon-base/sonic_daemon_base.egg-info
src/sonic-py-common/**/*.pyc src/sonic-py-common/**/*.pyc
src/sonic-py-common/.eggs/ src/sonic-py-common/.eggs/
src/sonic-py-common/build src/sonic-py-common/build

View File

@ -133,12 +133,6 @@ sudo cp {{platform_common_py2_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $PLATFORM_COMMON_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $PLATFORM_COMMON_PY2_WHEEL_NAME
sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2_WHEEL_NAME
# Install sonic-daemon-base Python 2 package
DAEMON_BASE_PY2_WHEEL_NAME=$(basename {{daemon_base_py2_wheel_path}})
sudo cp {{daemon_base_py2_wheel_path}} $FILESYSTEM_ROOT/$DAEMON_BASE_PY2_WHEEL_NAME
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $DAEMON_BASE_PY2_WHEEL_NAME
sudo rm -rf $FILESYSTEM_ROOT/$DAEMON_BASE_PY2_WHEEL_NAME
# Install built Python Click package (and its dependencies via 'apt-get -y install -f') # Install built Python Click package (and its dependencies via 'apt-get -y install -f')
# Do this before installing sonic-utilities so that it doesn't attempt to install # Do this before installing sonic-utilities so that it doesn't attempt to install
# an older version as part of its dependencies # an older version as part of its dependencies

View File

@ -3,7 +3,7 @@
SONIC_PLATFORM_API_PY2 = mlnx_platform_api-1.0-py2-none-any.whl SONIC_PLATFORM_API_PY2 = mlnx_platform_api-1.0-py2-none-any.whl
$(SONIC_PLATFORM_API_PY2)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api $(SONIC_PLATFORM_API_PY2)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api
$(SONIC_PLATFORM_API_PY2)_PYTHON_VERSION = 2 $(SONIC_PLATFORM_API_PY2)_PYTHON_VERSION = 2
$(SONIC_PLATFORM_API_PY2)_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_PLATFORM_COMMON_PY2) $(SONIC_DAEMON_BASE_PY2) $(SONIC_CONFIG_ENGINE) $(SONIC_PLATFORM_API_PY2)_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_PLATFORM_COMMON_PY2) $(SONIC_CONFIG_ENGINE)
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2) SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
export mlnx_platform_api_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))" export mlnx_platform_api_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))"

View File

@ -15,7 +15,6 @@ $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_DAEMON_BASE_PY2)
$(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS) $(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
$(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS += $(LIBSWSSCOMMON_DBG) $(LIBSENSORS_DBG) $(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS += $(LIBSWSSCOMMON_DBG) $(LIBSENSORS_DBG)

View File

@ -1,8 +0,0 @@
# SONIC_DAEMON_BASE_PY2 package
SONIC_DAEMON_BASE_PY2 = sonic_daemon_base-1.0-py2-none-any.whl
$(SONIC_DAEMON_BASE_PY2)_SRC_PATH = $(SRC_PATH)/sonic-daemon-base
$(SONIC_DAEMON_BASE_PY2)_PYTHON_VERSION = 2
SONIC_PYTHON_WHEELS += $(SONIC_DAEMON_BASE_PY2)
export daemon_base_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_DAEMON_BASE_PY2))"

View File

@ -2,5 +2,5 @@
SONIC_THERMALCTLD = python-sonic-thermalctld_1.0-1_all.deb SONIC_THERMALCTLD = python-sonic-thermalctld_1.0-1_all.deb
$(SONIC_THERMALCTLD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-thermalctld $(SONIC_THERMALCTLD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-thermalctld
$(SONIC_THERMALCTLD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_DAEMON_BASE_PY2) $(SONIC_THERMALCTLD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2)
SONIC_PYTHON_STDEB_DEBS += $(SONIC_THERMALCTLD) SONIC_PYTHON_STDEB_DEBS += $(SONIC_THERMALCTLD)

View File

@ -1,30 +0,0 @@
from setuptools import setup
setup(
name='sonic-daemon-base',
version='1.0',
description='Sonic daemon base package',
license='Apache 2.0',
author='SONiC Team',
author_email='linuxnetdev@microsoft.com',
url='https://github.com/Azure/sonic-platform-daemons',
maintainer='Kevin Wang',
maintainer_email='kevinw@mellanox.com',
packages=[
'sonic_daemon_base',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Topic :: System :: Hardware',
],
keywords='SONiC sonic PLATFORM platform DAEMON daemon',
)

View File

@ -1,208 +0,0 @@
#!/usr/bin/env python2
try:
import imp
import signal
import subprocess
import os
import sys
import syslog
except ImportError, e:
raise ImportError (str(e) + " - required module not found")
#
# Constants ====================================================================
#
REDIS_TIMEOUT_MSECS = 0
# Redis DB information
REDIS_HOSTNAME = 'localhost'
REDIS_PORT = 6379
REDIS_TIMEOUT_MSECS = 0
# Platform root directory inside docker
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'
# Port config information
PORT_CONFIG = 'port_config.ini'
PORTMAP = 'portmap.ini'
EEPROM_MODULE_NAME = 'eeprom'
EEPROM_CLASS_NAME = 'board'
#
# Helper functions =============================================================
#
def db_connect(db):
from swsscommon import swsscommon
return swsscommon.DBConnector(db,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_MSECS)
#
# Helper classes ===============================================================
#
class Logger(object):
def __init__(self, syslog_identifier = None):
self.syslog = syslog
if syslog_identifier is None:
self.syslog.openlog()
else:
self.syslog.openlog(ident=syslog_identifier, logoption=self.syslog.LOG_NDELAY, facility=self.syslog.LOG_DAEMON)
def __del__(self):
self.syslog.closelog()
def log_error(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_ERR, msg)
if also_print_to_console:
print msg
def log_warning(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_WARNING, msg)
if also_print_to_console:
print msg
def log_notice(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_NOTICE, msg)
if also_print_to_console:
print msg
def log_info(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_INFO, msg)
if also_print_to_console:
print msg
def log_debug(self, msg, also_print_to_console=False):
self.syslog.syslog(self.syslog.LOG_DEBUG, msg)
if also_print_to_console:
print msg
#
# Daemon =======================================================================
#
class DaemonBase(object):
def __init__(self):
# Register our signal handlers
'''all daemons inherit from daemon_base class, and for
signal handling functionality they register the signal_handler() by
overriding the siganl_handler() in daemon_base by their own
implmentation.
But some sonic_platform instances also can invoke the daemon_base
constructor while trying to instantiate the common utilities
for example
platform_chassis = sonic_platform.platform.Platform().get_chassis()
This will cause the re registration of signal_handler which will
cause base class signal_handler() to be invoked when the daemon
gets a signal, whereas the derived class signal_handler should have
been invoked. The if checks will not allow the re registration
of signal handler '''
if not signal.getsignal(signal.SIGHUP):
signal.signal(signal.SIGHUP, self.signal_handler)
if not signal.getsignal(signal.SIGINT):
signal.signal(signal.SIGINT, self.signal_handler)
if not signal.getsignal(signal.SIGTERM):
signal.signal(signal.SIGTERM, self.signal_handler)
# Signal handler
def signal_handler(self, sig, frame):
if sig == signal.SIGHUP:
syslog.syslog(syslog.LOG_INFO, "Caught SIGHUP - ignoring...")
elif sig == signal.SIGINT:
syslog.syslog(syslog.LOG_INFO, "Caught SIGINT - exiting...")
sys.exit(128 + sig)
elif sig == signal.SIGTERM:
syslog.syslog(syslog.LOG_INFO, "Caught SIGTERM - exiting...")
sys.exit(128 + sig)
else:
syslog.syslog(syslog.LOG_WARNING, "Caught unhandled signal '" + sig + "'")
# Returns platform and hwsku
def get_platform_and_hwsku(self):
try:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
platform = stdout.rstrip('\n')
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
hwsku = stdout.rstrip('\n')
except OSError, e:
raise OSError("Failed to detect platform: %s" % (str(e)))
return (platform, hwsku)
# Returns path to platform and hwsku
def get_path_to_platform_and_hwsku(self):
# Get platform and hwsku
(platform, hwsku) = self.get_platform_and_hwsku()
# Load platform module from source
platform_path = PLATFORM_ROOT_DOCKER
hwsku_path = "/".join([platform_path, hwsku])
return (platform_path, hwsku_path)
# Returns path to port config file
def get_path_to_port_config_file(self):
# Get platform and hwsku path
(platform_path, hwsku_path) = self.get_path_to_platform_and_hwsku()
# First check for the presence of the new 'port_config.ini' file
port_config_file_path = "/".join([hwsku_path, PORT_CONFIG])
if not os.path.isfile(port_config_file_path):
# port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file
port_config_file_path = "/".join([hwsku_path, PORTMAP])
if not os.path.isfile(port_config_file_path):
raise IOError("Failed to detect port config file: %s" % (port_config_file_path))
return port_config_file_path
# Loads platform specific psuutil module from source
def load_platform_util(self, module_name, class_name):
platform_util = None
# Get path to platform and hwsku
(platform_path, hwsku_path) = self.get_path_to_platform_and_hwsku()
try:
module_file = "/".join([platform_path, "plugins", module_name + ".py"])
module = imp.load_source(module_name, module_file)
except IOError, e:
raise IOError("Failed to load platform module '%s': %s" % (module_name, str(e)))
try:
platform_util_class = getattr(module, class_name)
# board class of eeprom requires 4 paramerters, need special treatment here.
if module_name == EEPROM_MODULE_NAME and class_name == EEPROM_CLASS_NAME:
platform_util = platform_util_class('','','','')
else:
platform_util = platform_util_class()
except AttributeError, e:
raise AttributeError("Failed to instantiate '%s' class: %s" % (class_name, str(e)))
return platform_util
# Runs daemon
def run(self):
raise NotImplementedError()

View File

@ -1,50 +0,0 @@
import multiprocessing
import os
import signal
import threading
#
# ProcessTaskBase =====================================================================
#
class ProcessTaskBase(object): # TODO: put this class to swss-platform-common
def __init__(self):
self.task_process = None
self.task_stopping_event = multiprocessing.Event()
def task_worker(self):
pass
def task_run(self):
if self.task_stopping_event.is_set():
return
self.task_process = multiprocessing.Process(target=self.task_worker)
self.task_process.start()
def task_stop(self):
self.task_stopping_event.set()
os.kill(self.task_process.pid, signal.SIGKILL)
#
# ThreadTaskBase =====================================================================
#
class ThreadTaskBase(object): # TODO: put this class to swss-platform-common;
def __init__(self):
self.task_thread = None
self.task_stopping_event = threading.Event()
def task_worker(self):
pass
def task_run(self):
if self.task_stopping_event.is_set():
return
self.task_thread = threading.Thread(target=self.task_worker)
self.task_thread.start()
def task_stop(self):
self.task_stopping_event.set()
self.task_thread.join()