[201911][Python] Migrate applications/scripts to import sonic-py-common package (#5132)
As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request: 1. Redirects all Python applications/scripts in sonic-buildimage repo which previously imported sonic_device_util or sonic_daemon_base to instead import sonic-py-common, which was added to the 201911 branch in https://github.com/Azure/sonic-buildimage/pull/5063 2. Replaces all calls to `sonic_device_util.get_platform_info()` to instead call `sonic_py_common.get_platform()` and removes any calls to `sonic_device_util.get_machine_info()` which are no longer necessary (i.e., those which were only used to pass the results to `sonic_device_util.get_platform_info()`. 3. Removes unused imports to the now-deprecated sonic-daemon-base package and sonic_device_util.py module This is a step toward resolving https://github.com/Azure/sonic-buildimage/issues/4999
This commit is contained in:
parent
ef88181cd3
commit
309a098b21
@ -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
|
||||
|
@ -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,7 @@ 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
|
||||
from sonic_py_common.logger import Logger
|
||||
except ImportError as e:
|
||||
raise ImportError(str(e) + "- required module not found")
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import sonic_device_util
|
||||
from ctypes import create_string_buffer
|
||||
|
||||
try:
|
||||
|
@ -11,7 +11,6 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import sonic_device_util
|
||||
from ctypes import create_string_buffer
|
||||
|
||||
try:
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -11,7 +11,6 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import sonic_device_util
|
||||
from ctypes import create_string_buffer
|
||||
|
||||
try:
|
||||
|
@ -11,8 +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_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
|
||||
from glob import glob
|
||||
@ -66,7 +66,7 @@ class Chassis(ChassisBase):
|
||||
# Initialize SKU name and Platform name
|
||||
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']
|
||||
else:
|
||||
|
@ -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
|
||||
except ImportError as e:
|
||||
raise ImportError (str(e) + "- required module not found")
|
||||
|
@ -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 *
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -12,5 +12,5 @@
|
||||
|
||||
SONIC_UTILS = python-sonic-utilities_1.2-1_all.deb
|
||||
$(SONIC_UTILS)_SRC_PATH = $(SRC_PATH)/sonic-utilities
|
||||
$(SONIC_UTILS)_WHEEL_DEPENDS = $(SONIC_CONFIG_ENGINE)
|
||||
$(SONIC_UTILS)_WHEEL_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_CONFIG_ENGINE)
|
||||
SONIC_PYTHON_STDEB_DEBS += $(SONIC_UTILS)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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/*')),
|
||||
|
@ -41,12 +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
|
||||
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 get_npu_device_id
|
||||
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, get_npu_device_id, is_multi_npu
|
||||
from config_samples import generate_sample_config
|
||||
from config_samples import get_available_config
|
||||
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig
|
||||
@ -231,7 +227,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:
|
||||
|
@ -247,6 +247,31 @@ def get_npu_id_from_name(npu_name):
|
||||
return None
|
||||
|
||||
|
||||
def get_npu_device_id(npu_id):
|
||||
platform = get_platform_info(get_machine_info())
|
||||
if not platform:
|
||||
return None
|
||||
|
||||
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, ASIC_CONF_FILENAME)
|
||||
if not os.path.isfile(asic_conf_file_path):
|
||||
return None
|
||||
|
||||
# In a multi-npu device we need to have the file "asic.conf" updated with the asic instance
|
||||
# and the corresponding device id which could be pci_id. Below is an eg: for a 2 ASIC platform/sku.
|
||||
# DEV_ID_ASIC_0=03:00.0
|
||||
# DEV_ID_ASIC_1=04:00.0
|
||||
device_str = "DEV_ID_ASIC_{}".format(npu_id)
|
||||
|
||||
with open(asic_conf_file_path) as asic_conf_file:
|
||||
for line in asic_conf_file:
|
||||
tokens = line.split('=')
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
if tokens[0] == device_str:
|
||||
device_id = tokens[1].strip()
|
||||
return device_id
|
||||
|
||||
|
||||
def get_namespaces():
|
||||
"""
|
||||
In a multi NPU platform, each NPU is in a Linux Namespace.
|
||||
|
Loading…
Reference in New Issue
Block a user