diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py index 6d5ed91581..e737dae1c3 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py @@ -14,7 +14,7 @@ try: import json import syslog from sonic_platform_base.chassis_base import ChassisBase - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger from sonic_platform.fan import Fan from sonic_platform.psu import Psu from sonic_platform.component import Component diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py index 2871172755..63fdb06844 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py @@ -8,7 +8,6 @@ try: import os import time import subprocess - import sonic_device_util import syslog from ctypes import create_string_buffer from sonic_platform_base.sfp_base import SfpBase @@ -18,7 +17,6 @@ try: from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper - from sonic_daemon_base.daemon_base import Logger except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py index 83ac8b2bfe..5932b30c32 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py @@ -11,7 +11,6 @@ import os import time import subprocess -import sonic_device_util from ctypes import create_string_buffer try: diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py index 86fc5ea726..eaf6743bc5 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py @@ -3,9 +3,10 @@ import os import struct import subprocess -from sonic_daemon_base.daemon_base import DaemonBase from mmap import * +from sonic_py_common import device_info + HOST_CHK_CMD = "docker > /dev/null 2>&1" EMPTY_STRING = "" @@ -13,7 +14,7 @@ EMPTY_STRING = "" class APIHelper(): def __init__(self): - (self.platform, self.hwsku) = DaemonBase().get_platform_and_hwsku() + (self.platform, self.hwsku) = device_info.get_platform_and_hwsku() def is_host(self): return os.system(HOST_CHK_CMD) == 0 diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index faf3b867fa..3e84bd7c41 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -10,7 +10,6 @@ import time import subprocess -import sonic_device_util from ctypes import create_string_buffer try: diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py index 4c5ebf9ea8..c0187033b8 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py @@ -11,7 +11,6 @@ import os import time import subprocess -import sonic_device_util from ctypes import create_string_buffer try: diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py index 4ba33dc8b2..3f33e4dc15 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py @@ -35,7 +35,7 @@ import time import os.path import sfputil as jnpr_sfp -from sonic_daemon_base.daemon_base import Logger +from sonic_py_common.logger import Logger from pprint import pprint SYSLOG_IDENTIFIER = "sfputil" diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py index e1543bedb8..bafdd4bbc7 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py @@ -42,7 +42,7 @@ try: from sonic_platform_base.sonic_sfp.sff8472 import sff8472InterfaceId from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger from ctypes import create_string_buffer except ImportError as e: diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index 545917a5ea..034a2e68ba 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -8,7 +8,7 @@ try: import io import string from ctypes import create_string_buffer - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger except ImportError, e: raise ImportError (str(e) + "- required module not found") diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py index c9ae1a3354..fbfe0d99ae 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py @@ -21,7 +21,7 @@ try: from cStringIO import StringIO from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo - from sonic_device_util import get_machine_info + from sonic_py_common.device_info import get_machine_info import subprocess except ImportError, e: raise ImportError (str(e) + "- required module not found") diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 738c11a6f0..72454c6090 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -97,12 +97,6 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in python-yaml \ python-bitarray -# Install SONiC config engine Python package -CONFIG_ENGINE_WHEEL_NAME=$(basename {{config_engine_wheel_path}}) -sudo cp {{config_engine_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $CONFIG_ENGINE_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_WHEEL_NAME - # Install Python client for Redis sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install "redis==3.5.3" @@ -137,6 +131,24 @@ sudo cp {{swsssdk_py2_wheel_path}} $FILESYSTEM_ROOT/$SWSSSDK_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $SWSSSDK_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$SWSSSDK_PY2_WHEEL_NAME +# Install sonic-py-common Python 2 package +SONIC_PY_COMMON_PY2_WHEEL_NAME=$(basename {{sonic_py_common_py2_wheel_path}}) +sudo cp {{sonic_py_common_py2_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY2_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $SONIC_PY_COMMON_PY2_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY2_WHEEL_NAME + +# Install sonic-py-common Python 3 package +SONIC_PY_COMMON_PY3_WHEEL_NAME=$(basename {{sonic_py_common_py3_wheel_path}}) +sudo cp {{sonic_py_common_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PY_COMMON_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_WHEEL_NAME + +# Install SONiC config engine Python package +CONFIG_ENGINE_WHEEL_NAME=$(basename {{config_engine_wheel_path}}) +sudo cp {{config_engine_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $CONFIG_ENGINE_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_WHEEL_NAME + # Install sonic-yang-models py3 package, install dependencies sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang_*.deb sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang-cpp_*.deb @@ -163,18 +175,6 @@ sudo cp {{daemon_base_py2_wheel_path}} $FILESYSTEM_ROOT/$DAEMON_BASE_PY2_WHEEL_N 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 sonic-py-common Python 2 package -SONIC_PY_COMMON_PY2_WHEEL_NAME=$(basename {{sonic_py_common_py2_wheel_path}}) -sudo cp {{sonic_py_common_py2_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY2_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $SONIC_PY_COMMON_PY2_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY2_WHEEL_NAME - -# Install sonic-py-common Python 3 package -SONIC_PY_COMMON_PY3_WHEEL_NAME=$(basename {{sonic_py_common_py3_wheel_path}}) -sudo cp {{sonic_py_common_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PY_COMMON_PY3_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_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 diff --git a/files/image_config/process-reboot-cause/process-reboot-cause b/files/image_config/process-reboot-cause/process-reboot-cause index c9d57fd77b..7762250ae6 100755 --- a/files/image_config/process-reboot-cause/process-reboot-cause +++ b/files/image_config/process-reboot-cause/process-reboot-cause @@ -13,7 +13,7 @@ try: import syslog import re - import sonic_device_util + from sonic_py_common import device_info except ImportError as err: raise ImportError("%s - required module not found" % str(err)) @@ -85,7 +85,7 @@ def find_software_reboot_cause(): if os.path.isfile(FIRST_BOOT_PLATFORM_FILE): if software_reboot_cause == REBOOT_CAUSE_UNKNOWN: - version_info = sonic_device_util.get_sonic_version_info() + version_info = device_info.get_sonic_version_info() build_version = version_info['build_version'] if version_info else "unknown" software_reboot_cause += " (First boot of SONiC version {})".format(build_version) os.remove(FIRST_BOOT_PLATFORM_FILE) diff --git a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/sfp.py b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/sfp.py index 4d71424ccf..760aa179c2 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/sfp.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/sfp.py @@ -11,7 +11,6 @@ import os import time import subprocess -import sonic_device_util from ctypes import create_string_buffer try: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index bd7fb98b02..68c3fe16a8 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -11,9 +11,8 @@ try: from sonic_platform_base.chassis_base import ChassisBase from sonic_platform_base.component_base import ComponentBase - from sonic_device_util import get_machine_info - from sonic_device_util import get_platform_info - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common import device_info + from sonic_py_common.logger import Logger from os import listdir from os.path import isfile, join import sys @@ -66,10 +65,10 @@ class Chassis(ChassisBase): self.sku_name = self._get_sku_name() self.platform_name = self._get_platform_name() - mi = get_machine_info() + mi = device_info.get_machine_info() if mi is not None: self.name = mi['onie_platform'] - self.platform_name = get_platform_info(mi) + self.platform_name = device_info.get_platform() else: self.name = self.sku_name self.platform_name = self._get_platform_name() diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index 6279f2d9e3..d26df89f04 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -11,7 +11,7 @@ try: import os.path from sonic_platform_base.psu_base import PsuBase - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger from sonic_platform.fan import Fan from .led import PsuLed, SharedLed, ComponentFaultyIndicator from .device_data import DEVICE_DATA diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index aa9d18d04f..67d8b6331a 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -21,7 +21,7 @@ try: from sonic_platform_base.sonic_sfp.inf8628 import inf8628InterfaceId from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_InterfaceId from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_Dom - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger from python_sdk_api.sxd_api import * from python_sdk_api.sx_api import * diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py index 859e411fb0..29f2aee64d 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py @@ -9,7 +9,7 @@ import os import time import select from python_sdk_api.sx_api import * -from sonic_daemon_base.daemon_base import Logger +from sonic_py_common.logger import Logger # SFP status from PMAOS register # 0x1 plug in diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py index 0571707eb7..4ebe282524 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/thermal.py @@ -10,7 +10,7 @@ try: from sonic_platform_base.thermal_base import ThermalBase - from sonic_daemon_base.daemon_base import Logger + from sonic_py_common.logger import Logger from os import listdir from os.path import isfile, join import io diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 2e0ead9157..55e3f1d300 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -14,8 +14,14 @@ $(DOCKER_SONIC_VS)_DEPENDS += $(SWSS) \ $(DOCKER_SONIC_VS)_PYTHON_DEBS += $(SONIC_UTILS) -$(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SONIC_YANG_MODELS_PY3) -$(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SONIC_YANG_MGMT_PY) +# swsssdk is a dependency of sonic-py-common +# TODO: sonic-py-common should depend on swsscommon instead +$(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SWSSSDK_PY2) \ + $(SWSSSDK_PY3) \ + $(SONIC_PY_COMMON_PY2) \ + $(SONIC_PY_COMMON_PY3) \ + $(SONIC_YANG_MODELS_PY3) \ + $(SONIC_YANG_MGMT_PY) ifeq ($(INSTALL_DEBUG_TOOLS), y) $(DOCKER_SONIC_VS)_DEPENDS += $(SWSS_DBG) \ diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 0947fdd47b..e96db2d79d 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -49,6 +49,7 @@ RUN apt-get install -y net-tools \ python3-pip RUN pip install setuptools +RUN pip3 install setuptools RUN pip install py2_ipaddress RUN pip install six RUN pip install pyroute2==0.5.3 netifaces==0.10.7 diff --git a/rules/docker-config-engine-buster.mk b/rules/docker-config-engine-buster.mk index cd4703e578..ac84f92edd 100644 --- a/rules/docker-config-engine-buster.mk +++ b/rules/docker-config-engine-buster.mk @@ -4,6 +4,7 @@ DOCKER_CONFIG_ENGINE_BUSTER = docker-config-engine-buster.gz $(DOCKER_CONFIG_ENGINE_BUSTER)_PATH = $(DOCKERS_PATH)/docker-config-engine-buster $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SWSSSDK_PY2) +$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE) $(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER) diff --git a/rules/docker-config-engine-stretch.mk b/rules/docker-config-engine-stretch.mk index 2a1e36d288..497593a316 100644 --- a/rules/docker-config-engine-stretch.mk +++ b/rules/docker-config-engine-stretch.mk @@ -3,6 +3,7 @@ DOCKER_CONFIG_ENGINE_STRETCH = docker-config-engine-stretch.gz $(DOCKER_CONFIG_ENGINE_STRETCH)_PATH = $(DOCKERS_PATH)/docker-config-engine-stretch $(DOCKER_CONFIG_ENGINE_STRETCH)_PYTHON_WHEELS += $(SWSSSDK_PY2) +$(DOCKER_CONFIG_ENGINE_STRETCH)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) $(DOCKER_CONFIG_ENGINE_STRETCH)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE) $(DOCKER_CONFIG_ENGINE_STRETCH)_LOAD_DOCKERS += $(DOCKER_BASE_STRETCH) diff --git a/rules/docker-config-engine.mk b/rules/docker-config-engine.mk index f540bb66f3..5d65314b67 100644 --- a/rules/docker-config-engine.mk +++ b/rules/docker-config-engine.mk @@ -3,6 +3,7 @@ DOCKER_CONFIG_ENGINE = docker-config-engine.gz $(DOCKER_CONFIG_ENGINE)_PATH = $(DOCKERS_PATH)/docker-config-engine $(DOCKER_CONFIG_ENGINE)_PYTHON_WHEELS += $(SWSSSDK_PY2) +$(DOCKER_CONFIG_ENGINE)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) $(DOCKER_CONFIG_ENGINE)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE) $(DOCKER_CONFIG_ENGINE)_LOAD_DOCKERS += $(DOCKER_BASE) SONIC_DOCKER_IMAGES += $(DOCKER_CONFIG_ENGINE) diff --git a/rules/sonic-config.mk b/rules/sonic-config.mk index 854b577b33..3adb460f58 100644 --- a/rules/sonic-config.mk +++ b/rules/sonic-config.mk @@ -2,6 +2,6 @@ SONIC_CONFIG_ENGINE = sonic_config_engine-1.0-py2-none-any.whl $(SONIC_CONFIG_ENGINE)_SRC_PATH = $(SRC_PATH)/sonic-config-engine -$(SONIC_CONFIG_ENGINE)_DEPENDS += $(SWSSSDK_PY2) +$(SONIC_CONFIG_ENGINE)_DEPENDS += $(SWSSSDK_PY2) $(SONIC_PY_COMMON_PY2) $(SONIC_CONFIG_ENGINE)_PYTHON_VERSION = 2 SONIC_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE) diff --git a/rules/sonic-ledd.mk b/rules/sonic-ledd.mk index 056f0f6c9b..c9d66b113d 100644 --- a/rules/sonic-ledd.mk +++ b/rules/sonic-ledd.mk @@ -2,4 +2,5 @@ SONIC_LEDD = python-sonic-ledd_1.1-1_all.deb $(SONIC_LEDD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-ledd +$(SONIC_LEDD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) SONIC_PYTHON_STDEB_DEBS += $(SONIC_LEDD) diff --git a/rules/sonic-platform-common.mk b/rules/sonic-platform-common.mk index d0c9366621..c7ab75d9f8 100644 --- a/rules/sonic-platform-common.mk +++ b/rules/sonic-platform-common.mk @@ -3,14 +3,15 @@ SONIC_PLATFORM_COMMON_PY2 = sonic_platform_common-1.0-py2-none-any.whl $(SONIC_PLATFORM_COMMON_PY2)_SRC_PATH = $(SRC_PATH)/sonic-platform-common $(SONIC_PLATFORM_COMMON_PY2)_PYTHON_VERSION = 2 -$(SONIC_PLATFORM_COMMON_PY2)_DEPENDS = $(SONIC_CONFIG_ENGINE) +$(SONIC_PLATFORM_COMMON_PY2)_DEPENDS += $(SONIC_PY_COMMON_PY2) $(SONIC_CONFIG_ENGINE) SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2) # Als build sonic-platform-common into python3 wheel, so we can use PSU code in SNMP docker SONIC_PLATFORM_COMMON_PY3 = sonic_platform_common-1.0-py3-none-any.whl $(SONIC_PLATFORM_COMMON_PY3)_SRC_PATH = $(SRC_PATH)/sonic-platform-common $(SONIC_PLATFORM_COMMON_PY3)_PYTHON_VERSION = 3 +$(SONIC_PLATFORM_COMMON_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3) # Synthetic dependency just to avoid race condition -$(SONIC_PLATFORM_COMMON_PY3)_DEPENDS = $(SONIC_PLATFORM_COMMON_PY2) +$(SONIC_PLATFORM_COMMON_PY3)_DEPENDS += $(SONIC_PLATFORM_COMMON_PY2) $(SONIC_PLATFORM_COMMON_PY3)_TEST = n SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY3) diff --git a/rules/sonic-psud.mk b/rules/sonic-psud.mk index 0249115359..404b18d2fe 100644 --- a/rules/sonic-psud.mk +++ b/rules/sonic-psud.mk @@ -2,4 +2,5 @@ SONIC_PSUD = python-sonic-psud_1.0-1_all.deb $(SONIC_PSUD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-psud +$(SONIC_PSUD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) SONIC_PYTHON_STDEB_DEBS += $(SONIC_PSUD) diff --git a/rules/sonic-py-common.mk b/rules/sonic-py-common.mk index b730ef5585..6afe9a826c 100644 --- a/rules/sonic-py-common.mk +++ b/rules/sonic-py-common.mk @@ -11,5 +11,8 @@ SONIC_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) SONIC_PY_COMMON_PY3 = sonic_py_common-1.0-py3-none-any.whl $(SONIC_PY_COMMON_PY3)_SRC_PATH = $(SRC_PATH)/sonic-py-common $(SONIC_PY_COMMON_PY3)_DEPENDS += $(SWSSSDK_PY3) +# Synthetic dependency to avoid building the Python 2 and 3 packages +# simultaneously and any potential conflicts which may arise +$(SONIC_PY_COMMON_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY2) $(SONIC_PY_COMMON_PY3)_PYTHON_VERSION = 3 SONIC_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) diff --git a/rules/sonic-syseepromd.mk b/rules/sonic-syseepromd.mk index 8f7a6e5e90..b8c6817957 100644 --- a/rules/sonic-syseepromd.mk +++ b/rules/sonic-syseepromd.mk @@ -2,4 +2,5 @@ SONIC_SYSEEPROMD = python-sonic-syseepromd_1.0-1_all.deb $(SONIC_SYSEEPROMD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-syseepromd +$(SONIC_SYSEEPROMD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) SONIC_PYTHON_STDEB_DEBS += $(SONIC_SYSEEPROMD) diff --git a/rules/sonic-utilities.mk b/rules/sonic-utilities.mk index 96091ddbc2..c5f3a3b29e 100644 --- a/rules/sonic-utilities.mk +++ b/rules/sonic-utilities.mk @@ -12,8 +12,13 @@ SONIC_UTILS = python-sonic-utilities_1.2-1_all.deb $(SONIC_UTILS)_SRC_PATH = $(SRC_PATH)/sonic-utilities -$(SONIC_UTILS)_DEBS_DEPENDS = $(LIBYANG) $(LIBYANG_CPP) $(LIBYANG_PY2) \ - $(LIBYANG_PY3) -$(SONIC_UTILS)_WHEEL_DEPENDS = $(SONIC_CONFIG_ENGINE) $(SONIC_YANG_MGMT_PY) \ +$(SONIC_UTILS)_DEBS_DEPENDS = $(LIBYANG) \ + $(LIBYANG_CPP) \ + $(LIBYANG_PY2) \ + $(LIBYANG_PY3) +$(SONIC_UTILS)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) \ + $(SONIC_PY_COMMON_PY3) \ + $(SONIC_CONFIG_ENGINE) \ + $(SONIC_YANG_MGMT_PY) \ $(SONIC_YANG_MODELS_PY3) SONIC_PYTHON_STDEB_DEBS += $(SONIC_UTILS) diff --git a/rules/sonic-xcvrd.mk b/rules/sonic-xcvrd.mk index b97f8dd11b..c4b6016f1a 100644 --- a/rules/sonic-xcvrd.mk +++ b/rules/sonic-xcvrd.mk @@ -2,4 +2,5 @@ SONIC_XCVRD = python-sonic-xcvrd_1.0-1_all.deb $(SONIC_XCVRD)_SRC_PATH = $(SRC_PATH)/sonic-platform-daemons/sonic-xcvrd +$(SONIC_XCVRD)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) SONIC_PYTHON_STDEB_DEBS += $(SONIC_XCVRD) diff --git a/rules/sonic_bgpcfgd.mk b/rules/sonic_bgpcfgd.mk index 650874b619..32abbd5af9 100644 --- a/rules/sonic_bgpcfgd.mk +++ b/rules/sonic_bgpcfgd.mk @@ -2,6 +2,10 @@ SONIC_BGPCFGD = sonic_bgpcfgd-1.0-py2-none-any.whl $(SONIC_BGPCFGD)_SRC_PATH = $(SRC_PATH)/sonic-bgpcfgd -$(SONIC_BGPCFGD)_DEPENDS += $(SWSSSDK_PY2) +# These dependencies are only needed becuase they are dependencies +# of sonic-config-engine and bgpcfgd explicitly calls sonic-cfggen +# as part of its unit tests. +# TODO: Refactor unit tests so that these dependencies are not needed +$(SONIC_BGPCFGD)_DEPENDS += $(SWSSSDK_PY2) $(SONIC_PY_COMMON_PY2) $(SONIC_BGPCFGD)_PYTHON_VERSION = 2 SONIC_PYTHON_WHEELS += $(SONIC_BGPCFGD) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 2fe6999872..5ee209d17d 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -14,7 +14,7 @@ from lxml import etree as ET from lxml.etree import QName from portconfig import get_port_config -from sonic_device_util import get_npu_id_from_name +from sonic_py_common.device_info import get_npu_id_from_name """minigraph.py version_added: "1.9" diff --git a/src/sonic-config-engine/setup.py b/src/sonic-config-engine/setup.py index c75a5b5a03..f08577234c 100755 --- a/src/sonic-config-engine/setup.py +++ b/src/sonic-config-engine/setup.py @@ -18,7 +18,15 @@ setup(name='sonic-config-engine', url='https://github.com/Azure/sonic-buildimage', py_modules=['portconfig', 'minigraph', 'openconfig_acl', 'sonic_device_util', 'config_samples', 'redis_bcc', 'lazy_re'], scripts=['sonic-cfggen'], - install_requires=['lxml', 'jinja2>=2.10', 'netaddr', 'ipaddr', 'pyyaml', 'pyangbind==0.6.0'], + install_requires=[ + 'ipaddr', + 'jinja2>=2.10', + 'lxml', + 'netaddr', + 'pyyaml', + 'pyangbind==0.6.0', + 'sonic-py-common' + ], test_suite='setup.get_test_suite', data_files=[ ('/usr/share/sonic/templates', glob.glob('data/*')), diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index eb4c101f8c..b062fbda6b 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -41,11 +41,8 @@ from minigraph import parse_xml from minigraph import parse_device_desc_xml from minigraph import parse_asic_sub_role from portconfig import get_port_config, get_port_config_file_name, get_breakout_mode -from sonic_device_util import get_machine_info -from sonic_device_util import get_platform_info -from sonic_device_util import get_system_mac -from sonic_device_util import get_npu_id_from_name -from sonic_device_util import is_multi_npu +from sonic_py_common.device_info import get_platform, get_system_mac +from sonic_py_common.device_info import get_npu_id_from_name, is_multi_npu from config_samples import generate_sample_config from config_samples import get_available_config from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig @@ -235,7 +232,7 @@ def main(): group.add_argument("-K", "--key", help="Lookup for a specific key") args = parser.parse_args() - platform = get_platform_info(get_machine_info()) + platform = get_platform() db_kwargs = {} if args.redis_unix_sock_file != None: diff --git a/src/sonic-py-common/sonic_py_common/daemon_base.py b/src/sonic-py-common/sonic_py_common/daemon_base.py index d88b07edca..77188a004f 100644 --- a/src/sonic-py-common/sonic_py_common/daemon_base.py +++ b/src/sonic-py-common/sonic_py_common/daemon_base.py @@ -56,7 +56,7 @@ class DaemonBase(Logger): platform_util = None # Get path to platform and hwsku - (platform_path, hwsku_path) = device_info.get_path_to_platform_and_hwsku() + (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku() try: module_file = "/".join([platform_path, "plugins", module_name + ".py"]) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 72b9e5a286..a1645182a8 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -1,5 +1,6 @@ import glob import os +import re import subprocess import yaml @@ -57,22 +58,11 @@ def get_platform(): Returns: A string containing the device's platform identifier """ - # First, attempt to retrieve the platform string from Config DB - config_db = ConfigDBConnector() - config_db.connect() - - metadata = config_db.get_table('DEVICE_METADATA') - - if 'localhost' in metadata and 'platform' in metadata['localhost']: - return metadata['localhost']['platform'] - - # If we were unable to retrieve the platform string from Config DB, attempt - # to retrieve it from the machine configuration file machine_info = get_machine_info() if machine_info: - if machine_info.has_key('onie_platform'): - return machine_info['onie_platform'] - elif machine_info.has_key('aboot_platform'): + if 'onie_platform' in machine_info: + return machine_info['onie_platform'] + elif 'aboot_platform' in machine_info: return machine_info['aboot_platform'] return None diff --git a/src/sonic-py-common/sonic_py_common/logger.py b/src/sonic-py-common/sonic_py_common/logger.py index ee5e9f35fe..26adf999a0 100644 --- a/src/sonic-py-common/sonic_py_common/logger.py +++ b/src/sonic-py-common/sonic_py_common/logger.py @@ -1,4 +1,5 @@ import os +import sys import syslog """ @@ -24,7 +25,7 @@ class Logger(object): if not log_identifier: log_identifier = os.path.basename(sys.argv[0]) - + self.syslog.openlog(ident=log_identifier, logoption=(syslog.LOG_PID | syslog.LOG_NDELAY), facility=log_facility)