-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduce sonic-py-common package #5003
Changes from 11 commits
5f74856
ac83ce3
55a1d79
862e786
284c0db
1de1385
97fef08
bedbc1a
f49c4da
d11f1a6
40a450b
d65f683
4288a8b
0b488e2
1dec66a
f8c19a2
50e7b49
c1e84de
a3d280e
f2d0fb0
f1a541f
59f56d1
461a56c
95419cd
3365c7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,16 @@ installer/x86_64/platforms/ | |
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/build | ||
src/sonic-py-common/dist | ||
src/sonic-py-common/sonic_py_common.egg-info | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this makes sense in a separate PR designed for general cleanup purposes, as it touches more than this new package. Please open an issue to track it. |
||
|
||
# Misc. files | ||
asic_config_checksum | ||
files/Aboot/boot0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SPATH := $($(SONIC_PY_COMMON_PY2)_SRC_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-py-common.mk rules/sonic-py-common.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) | ||
DEP_FILES += $(shell git ls-files $(SPATH)) | ||
|
||
$(SONIC_PY_COMMON_PY2)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(SONIC_PY_COMMON_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(SONIC_PY_COMMON_PY2)_DEP_FILES := $(DEP_FILES) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xumia Could you help review? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SONIC_PY_COMMON_PY2 package | ||
|
||
SONIC_PY_COMMON_PY2 = sonic_py_common-1.0-py2-none-any.whl | ||
$(SONIC_PY_COMMON_PY2)_SRC_PATH = $(SRC_PATH)/sonic-py-common | ||
$(SONIC_PY_COMMON_PY2)_DEPENDS += $(SWSSSDK_PY2) | ||
$(SONIC_PY_COMMON_PY2)_PYTHON_VERSION = 2 | ||
SONIC_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
SONIC_THERMALCTLD = python-sonic-thermalctld_1.0-1_all.deb | ||
$(SONIC_THERMALCTLD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-thermalctld | ||
$(SONIC_THERMALCTLD)_WHEEL_DEPENDS = $(SONIC_DAEMON_BASE_PY2) | ||
$(SONIC_THERMALCTLD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_DAEMON_BASE_PY2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see some code duplication in both repo. Can we merge 2 into 1? #Pending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the ultimate goal. After this merges, I intend to shift all code away from sonic-daemon-base and sonic-device-util, and remove them completely in separate PRs. Please read the "Next Steps" in my description above and see the linked issue: #4999 |
||
SONIC_PYTHON_STDEB_DEBS += $(SONIC_THERMALCTLD) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from setuptools import setup | ||
|
||
dependencies = [ | ||
'swsssdk>=2.0.1', | ||
] | ||
|
||
high_performance_deps = [ | ||
'swsssdk[high_perf]>=2.0.1', | ||
] | ||
|
||
setup( | ||
name='sonic-py-common', | ||
version='1.0', | ||
description='Common Python libraries for SONiC', | ||
license='Apache 2.0', | ||
author='SONiC Team', | ||
author_email='[email protected]', | ||
url='https://github.com/Azure/SONiC', | ||
maintainer='Joe LeVeque', | ||
maintainer_email='[email protected]', | ||
install_requires=dependencies, | ||
extras_require={ | ||
'high_perf': high_performance_deps, | ||
}, | ||
packages=[ | ||
'sonic_py_common', | ||
], | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'Operating System :: Linux', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python', | ||
], | ||
keywords='SONiC sonic PYTHON python COMMON common', | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import imp | ||
import signal | ||
import sys | ||
|
||
from . import device_info, logger | ||
|
||
# | ||
# Constants ==================================================================== | ||
# | ||
REDIS_TIMEOUT_MSECS = 0 | ||
|
||
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) | ||
|
||
# | ||
# DaemonBase =================================================================== | ||
# | ||
|
||
class DaemonBase(logger.Logger): | ||
def __init__(self, log_identifier): | ||
super(DaemonBase, self).__init__(log_identifier, logger.FACILITY_DAEMON) | ||
|
||
# Register our default signal handlers, unless the signal already has a | ||
# handler registered, most likely from a subclass implementation | ||
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) | ||
|
||
# Default signal handler; can be overridden by subclass | ||
def signal_handler(self, sig, frame): | ||
if sig == signal.SIGHUP: | ||
log_info("DaemonBase: Caught SIGHUP - ignoring...") | ||
elif sig == signal.SIGINT: | ||
log_info("DaemonBase: Caught SIGINT - exiting...") | ||
sys.exit(128 + sig) | ||
elif sig == signal.SIGTERM: | ||
log_info("DaemonBase: Caught SIGTERM - exiting...") | ||
sys.exit(128 + sig) | ||
else: | ||
log_warning("DaemonBase: Caught unhandled signal '{}'".format(sig)) | ||
|
||
# Loads platform specific platform 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) = device_info.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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pyc should always be ignored, so suggest consolidate them into one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense in a separate PR designed for general cleanup purposes, as it touches more than this new package. Please open an issue to track it.