Remove sonic-daemon-base package (#5131)

sonic-daemon-base package has been deprecated in favor of the sonic-py-common package. All related functionality has been moved there.
This commit is contained in:
Joe LeVeque 2020-08-09 21:27:36 -07:00 committed by GitHub
parent 966ac85e24
commit 2b5e418e2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 0 additions and 325 deletions

4
.gitignore vendored
View File

@ -33,10 +33,6 @@ src/sonic-config-engine/**/*.pyc
src/sonic-config-engine/build
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/.eggs/
src/sonic-py-common/build

View File

@ -169,12 +169,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 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')
# Do this before installing sonic-utilities so that it doesn't attempt to install
# an older version as part of its dependencies

View File

@ -1,10 +0,0 @@
SPATH := $($(SONIC_DAEMON_BASE_PY2)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-daemon-base.mk rules/sonic-daemon-base.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files $(SPATH))
$(SONIC_DAEMON_BASE_PY2)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_DAEMON_BASE_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_DAEMON_BASE_PY2)_DEP_FILES := $(DEP_FILES)

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

@ -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,217 +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
# Platform root directory inside docker
PLATFORM_ROOT_DOCKER = '/usr/share/sonic/platform'
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
SONIC_ENV_FILE = '/etc/sonic/sonic-environment'
PLATFORM_ENVVAR = 'PLATFORM'
HWSKU_ENVVAR = 'HWSKU'
HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku'
PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform'
# Port config information
PORT_CONFIG = 'port_config.ini'
PLATFORM_JSON = 'platform.json'
EEPROM_MODULE_NAME = 'eeprom'
EEPROM_CLASS_NAME = 'board'
#
# Helper functions =============================================================
#
def db_connect(db_name):
from swsscommon import swsscommon
return swsscommon.DBConnector(db_name,
REDIS_TIMEOUT_MSECS,
True)
#
# 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:
platform = hwsku = None
if os.path.exists(SONIC_ENV_FILE):
with open(SONIC_ENV_FILE, "r") as env_file:
for line in env_file:
if PLATFORM_ENVVAR in line:
platform = line.split('=')[1]
if HWSKU_ENVVAR in line:
hwsku = line.split('=')[1]
if not platform:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
stdout, stderr = proc.communicate()
assert not stderr and not proc.returncode, "Failed to detect platform: %s, rc: %s" % (stderr, proc.returncode)
platform = stdout.rstrip('\n')
if not hwsku:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
stdout, stderr = proc.communicate()
assert not stderr and not proc.returncode, "Failed to detect hwsku: %s, rc: %s" % (stderr, proc.returncode)
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 'platform.json' file
port_config_file_path = "/".join([platform_path, PLATFORM_JSON])
if not os.path.isfile(port_config_file_path):
# platform.json doesn't exist. Try loading the legacy 'port_config.ini' file
port_config_file_path = "/".join([hwsku_path, PORT_CONFIG])
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()