Skip to content
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

Create a Python library to house common general SONiC-related APIs #4999

Open
6 of 11 tasks
jleveque opened this issue Jul 17, 2020 · 1 comment
Open
6 of 11 tasks

Create a Python library to house common general SONiC-related APIs #4999

jleveque opened this issue Jul 17, 2020 · 1 comment

Comments

@jleveque
Copy link
Contributor

jleveque commented Jul 17, 2020

There is currently a lot of duplicated code in many SONiC repos, and other shared code is located in various packages. We need to centralize this common functionality in a Python library which resides in sonic-buildimage that we can import from sonic-daemon-base, sonic-utilities, sonic-platform-common, sonic-platform-daemons, etc., and eliminate duplicate code in the process. Examples of this functionality include:

  • get_platform()
  • get_hwsku
  • get_path_to_platform_and_hwsku()
  • get_path_to_port_config_file()
  • Logging
  • ...

Plan of action:

  • Create sonic-py-common package in sonic-buildimage repo
  • Migrate all Python applications in sonic-buildimage from sonic-daemon-base and sonic_device_util to sonic-py-common
  • Migrate all Python applications in submodules from sonic-daemon-base and sonic_device_util to sonic-py-common
  • Migrate sonic-mgmt
    • master PR merged 8/8/20
      • 201911 PR not needed, no 201911 branch
  • Remove sonic-daemon-base from sonic-buildimage entirely
  • Remove sonic_device_util.py from sonic-buildimage entirely
  • Migrate common code from sonic-utilities into sonic-py-common
  • Migrate all Python daemons to inherit from sonic_py_common.daemon_base (lldpmgrd, bgpcfgd, etc.)
    • lldpmgrd: master PR merged 9/15/20
    • caclmgrd: master PR merged 9/15/20
    • procdockerstatsd: master PR merged 9/14/20
    • bgpcfgd
    • hostcfgd
    • ctrmgrd
  • Remove all bespoke logging code from Python applications and import from sonic_py_common instead
    • dockers/docker-sflow/port_index_mapper.py
    • files/image_config/process-reboot-cause/process-reboot-cause: master PR
    • files/scripts/core_cleanup.py
    • src/sonic-yang-mgmt/sonic_yang.py
  • Remove portconfig.py from sonic-config-engine and move functionality into sonic-py-common
  • Add regression tests for sonic-py-common to sonic-mgmt repo
@jleveque
Copy link
Contributor Author

First step toward resolving this: #5003

jleveque added a commit that referenced this issue Aug 3, 2020
…ge (#5043)

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 in #5003
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 the next step toward resolving #4999

Also reverted my previous change in which device_info.get_platform() would first try obtaining the platform ID string from Config DB and fall back to gathering it from machine.conf upon failure because this function is called by sonic-cfggen before the data is in the DB, in which case, the db_connect() call will hang indefinitely, which was not the behavior I expected. As of now, the function will always reference machine.conf.
jleveque added a commit to sonic-net/sonic-platform-common that referenced this issue Aug 5, 2020
As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request migrates from importing the sonic-daemon-base package to importing the sonic-py-common package. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
jleveque added a commit to sonic-net/sonic-platform-daemons that referenced this issue Aug 5, 2020
As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request migrates from importing the sonic-daemon-base package to importing the sonic-py-common package. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
jleveque added a commit to sonic-net/sonic-utilities that referenced this issue Aug 8, 2020
…ge (#1008)

As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request redirects all Python applications/scripts in sonic-utilities repo to point to sonic-py-common and removes multiple duplicate definitions of common functions in the process. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
- Also align some style
jleveque added a commit that referenced this issue Aug 13, 2020
…on 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 #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 #4999
jleveque added a commit to sonic-net/sonic-platform-daemons that referenced this issue Aug 13, 2020
…ckage (#83)

As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request migrates from importing the sonic-daemon-base package to importing the sonic-py-common package. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
jleveque added a commit to sonic-net/sonic-utilities that referenced this issue Aug 14, 2020
…on package (#1040)

As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request redirects all Python applications/scripts in sonic-utilities repo to point to sonic-py-common and removes multiple duplicate definitions of common functions in the process. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
- Also align some style

This is a port of #1008 to the 201911 branch
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this issue Feb 25, 2021
…ge (sonic-net#5043)

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 in sonic-net#5003
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 the next step toward resolving sonic-net#4999

Also reverted my previous change in which device_info.get_platform() would first try obtaining the platform ID string from Config DB and fall back to gathering it from machine.conf upon failure because this function is called by sonic-cfggen before the data is in the DB, in which case, the db_connect() call will hang indefinitely, which was not the behavior I expected. As of now, the function will always reference machine.conf.
malletvapid23 added a commit to malletvapid23/Sonic-Utility that referenced this issue Aug 3, 2023
…ge (#1008)

As part of consolidating all common Python-based functionality into the new sonic-py-common package, this pull request redirects all Python applications/scripts in sonic-utilities repo to point to sonic-py-common and removes multiple duplicate definitions of common functions in the process. This is the next step toward resolving sonic-net/sonic-buildimage#4999.

- Also reorganize imports for consistency
- Also align some style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant