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

libyang python APIs #3874

Closed
wants to merge 3 commits into from
Closed

Conversation

li-pingmao
Copy link
Contributor

- What I did
libyang Python APIs:
- python APIs based on libyang
- functions to load/merge yang models and Yang data files
- function to validate data trees based on Yang models
- functions to merge yang data files/trees
- add/set/delete node in schema and data trees
- find data/schema nodes from xpath from the Yang data/schema tree in memory
- find dependencies
- dump the data tree in json/xml

- How I did it
- based on libyang python2 modules which is built by libyang
- add functions to load/validate Yang models and Yang data trees
- Add functions to

- How to verify it
- pytests while build sonic-yang-mgmt python wheel package
- create sample Yang models for sonic ACL/interface/port/clan
- sample Yang data files
- test file with test cases, it includes categories to test, xpath and expected results for testing Yang data/schema tree wrapper functions

pytests while build target/python-wheels/sonic_yang_mgmt-1.0-py2-none-any.whl:

============================= test session starts ==============================
platform linux2 -- Python 2.7.13, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /sonic/src/sonic-yang-mgmt, inifile:
plugins: cov-2.4.0
collected 18 items

tests/test_sonic_yang_mgmt.py .
tests/libyang-python-tests/test_sonic_yang.py .................

========================== 18 passed in 0.21 seconds ===========================

- Description for the changelog

Note: Due to dependency on PR#3861 (#3861), this PR has 2 commits, please review the 2nd commit only(the first commit in this PR is a cherry-pick of PR#3861).

- A picture of a cute animal (not mandatory but encouraged)

Praveen Chaudhary and others added 2 commits December 11, 2019 10:33
This Package will contain YANG models for sonic which are written with guidelines mentioned in
https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md.

This package will include python yang libraries which will be used with sonic utilities
pacakge to validate the config.
      - python APIs based on libyang
      - functions to load/merge yang models and data files
      - add/set/delete node in schema and data trees
      - find dependencies
src/sonic-yang-mgmt/sonic_yang.py Show resolved Hide resolved
},
author="lnos-coders",
author_email='lnos-coders@linkedin.com',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before. Can we switch to >= 3.5

src/sonic-yang-mgmt/sonic_yang.py Outdated Show resolved Hide resolved
src/sonic-yang-mgmt/sonic_yang.py Outdated Show resolved Hide resolved
src/sonic-yang-mgmt/sonic_yang.py Outdated Show resolved Hide resolved
src/sonic-yang-mgmt/sonic_yang.py Show resolved Hide resolved
return mod

"""
load_data_model(): load both Yang module fileis and data json files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fileis/files/

src/sonic-yang-mgmt/sonic_yang.py Outdated Show resolved Hide resolved
if (module is not None):
if (format == "XML"):
#libyang bug with format
result = module.print_mem(ly.LYD_JSON, ly.LYP_FORMAT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you ask for LYD_JSON for XML & LYD_XML for JSON ?

Apparently this bug does not impact self.root

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bug in libyang

@praveen-li
Copy link
Collaborator

@li-pingmao : Kindly close this PR, by giving reference to PR 3861. Thx

@li-pingmao
Copy link
Contributor Author

This PR was pushed as part of PR 3861.

@li-pingmao li-pingmao closed this May 1, 2020
praveen-li referenced this pull request in praveen-li/sonic-buildimage May 8, 2020
Changes:
1.) prefix test_ for sample yang models.
2.) name properly with data_node or schema_node.
3.) Update function calls after libyang PLY APIs updates.
4.) Fix test cases after sample yang files name changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants