From e4ed475fcde0d68abb3b2814a71b76296642a7ee Mon Sep 17 00:00:00 2001 From: Hua Liu <58683130+liuh-80@users.noreply.github.com> Date: Fri, 3 Jun 2022 14:30:09 +0800 Subject: [PATCH] Change pycommon to use swsscommon (#10099) #### Why I did it Switch py-common from swsssdk to swsscommon. #### How I did it Change code and make file to use swsscommon. #### How to verify it Pass all UT and E2E test. #### Which release branch to backport (provide reason below if selected) - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 #### Description for the changelog #### Link to config_db schema for YANG module changes #### A picture of a cute animal (not mandatory but encouraged) --- rules/sonic-py-common.mk | 3 +++ src/sonic-py-common/setup.py | 8 -------- src/sonic-py-common/sonic_py_common/device_info.py | 4 +--- src/sonic-py-common/tests/device_info_test.py | 2 +- .../tests/{mock_swsssdk.py => mock_swsscommon.py} | 0 5 files changed, 5 insertions(+), 12 deletions(-) rename src/sonic-py-common/tests/{mock_swsssdk.py => mock_swsscommon.py} (100%) diff --git a/rules/sonic-py-common.mk b/rules/sonic-py-common.mk index be5f5d8e69..4d315c8b97 100644 --- a/rules/sonic-py-common.mk +++ b/rules/sonic-py-common.mk @@ -4,6 +4,8 @@ ifeq ($(ENABLE_PY2_MODULES), y) 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)_DEBS_DEPENDS = $(LIBSWSSCOMMON) \ + $(PYTHON_SWSSCOMMON) $(SONIC_PY_COMMON_PY2)_PYTHON_VERSION = 2 SONIC_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2) endif @@ -13,6 +15,7 @@ endif 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) +$(SONIC_PY_COMMON_PY3)_DEBS_DEPENDS = $(PYTHON3_SWSSCOMMON) ifeq ($(ENABLE_PY2_MODULES), y) # Synthetic dependency to avoid building the Python 2 and 3 packages # simultaneously and any potential conflicts which may arise diff --git a/src/sonic-py-common/setup.py b/src/sonic-py-common/setup.py index bed64fe7fd..f12c0d83cb 100644 --- a/src/sonic-py-common/setup.py +++ b/src/sonic-py-common/setup.py @@ -3,11 +3,6 @@ from setuptools import setup dependencies = [ 'natsort==6.2.1', # 6.2.1 is the last version which supports Python 2 'pyyaml', - 'swsssdk>=2.0.1', -] - -high_performance_deps = [ - 'swsssdk[high_perf]>=2.0.1', ] setup( @@ -21,9 +16,6 @@ setup( maintainer='Joe LeVeque', maintainer_email='jolevequ@microsoft.com', install_requires=dependencies, - extras_require={ - 'high_perf': high_performance_deps, - }, packages=[ 'sonic_py_common', ], 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 d57e08b3b5..73654b8819 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -7,8 +7,7 @@ import subprocess import yaml from natsort import natsorted -# TODO: Replace with swsscommon -from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector +from swsscommon.swsscommon import ConfigDBConnector, SonicV2Connector USR_SHARE_SONIC_PATH = "/usr/share/sonic" HOST_DEVICE_PATH = USR_SHARE_SONIC_PATH + "/device" @@ -485,7 +484,6 @@ def get_all_namespaces(config_db=None): front_ns = [] back_ns = [] num_npus = get_num_npus() - SonicDBConfig.load_sonic_global_db_config() if is_multi_npu(): for npu in range(num_npus): diff --git a/src/sonic-py-common/tests/device_info_test.py b/src/sonic-py-common/tests/device_info_test.py index bb7af40ad9..1256037ff5 100644 --- a/src/sonic-py-common/tests/device_info_test.py +++ b/src/sonic-py-common/tests/device_info_test.py @@ -13,7 +13,7 @@ import pytest from sonic_py_common import device_info -from .mock_swsssdk import SonicV2Connector +from .mock_swsscommon import SonicV2Connector # TODO: Remove this if/else block once we no longer support Python 2 if sys.version_info.major == 3: diff --git a/src/sonic-py-common/tests/mock_swsssdk.py b/src/sonic-py-common/tests/mock_swsscommon.py similarity index 100% rename from src/sonic-py-common/tests/mock_swsssdk.py rename to src/sonic-py-common/tests/mock_swsscommon.py