-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
libyang python APIs #3874
Conversation
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
}, | ||
author="lnos-coders", | ||
author_email='lnos-coders@linkedin.com', | ||
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', |
There was a problem hiding this comment.
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/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-head.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-interface.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-port.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-portchannel.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-vlan.yang
Outdated
Show resolved
Hide resolved
src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang
Outdated
Show resolved
Hide resolved
return mod | ||
|
||
""" | ||
load_data_model(): load both Yang module fileis and data json files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/fileis/files/
if (module is not None): | ||
if (format == "XML"): | ||
#libyang bug with format | ||
result = module.print_mem(ly.LYD_JSON, ly.LYP_FORMAT) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bug in libyang
@li-pingmao : Kindly close this PR, by giving reference to PR 3861. Thx |
This PR was pushed as part of PR 3861. |
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.
- 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)