[_sonic_yang_ext.py]: Extend sonic yang class to support cropping, transalation, reverse translation of Config DB.#3891
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
…, PortChannel and ACL. [Sonic Yang Tree]: YANG models as per Guidelines. Guideline doc: https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md [yang-model-tests]: YANG model test code and JSON input for testing. [setup.py]: Add testing for yang models. [sonic-slave-stretch]: Add a package ijson for sonic_yang_mgmt build.
…ansalation, reverse translation of config DB. This PR includes: -- Cropping input config based on Yang Model. -- Translate input config based on Yang Model. -- rev Translate input config based on Yang Model. -- Find xpath of port, portleaf and a yang list. -- Find if node is key of a list while deletion if yes, then delete the parent.
|
Curious! Having two different modules doing the same would be hard to maintain. Have you looked in-depth the committed code (from Broadcom) that does this translation ? |
@renukamanavalan Thanks |
|
@renukamanavalan |
|
This PR is merged in PR 3861. |
…atically (#22614) #### Why I did it src/sonic-utilities ``` * 6ce5257 - (HEAD -> master, origin/master, origin/HEAD) Update ubuntu version in azure pipeline (#3891) (5 hours ago) [Vasundhara Volam] * c78e0f7 - (origin/202505) VNET CLI- ADD/DEL VNET, ADD/DEL VNET ROUTE, VRF BIND/UNBIND to consider VNET + ADDITIONAL MODIFICATIONS TO SHOW VNET CLIs (#3826) (7 days ago) [KavyaVaniBedida] * 1d6e050 - Revert "Vnet_name added in create_only patterns (#3878)" (#3879) (7 days ago) [miatttao] * 5db13c2 - skip pfcwd if disabled in golden_config (#3880) (8 days ago) [Dashuai Zhang] * 07b232a - Add GCU Support for SKU Mellanox-SN4280-O8C80 (#3871) (8 days ago) [Sai Rama Mohan Reddy S] ``` #### How I did it #### How to verify it #### Description for the changelog
…config DB.
This PR changes are added in PR 3861 now.
From the json format of yang models, a map is created from config DB tables
to container in yang model. Input Config is cropped on based of this map.
Input Config is also translated based of this map.
Similarly from yang data tree, output is reverse translated to config DB.
This PR also includes:
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.
- What I did
-- Cropping input config based on Yang Model.
-- Translate input config based on Yang Model.
-- rev Translate input config based on Yang Model.
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.
- How I did it
Yang model can be represented in JSON as below:
This is used to create a map between Config DB Table and YANG Model Container.
Note: As per guideline https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md. Table maps to only container in YANG.
Map and json format of yang model is used to:
-- Cropping input config based on Yang Model.
-- Translate input config based on Yang Model.
-- rev Translate input config based on Yang Model.
-- Find xpath of port, portleaf and a yang list.
-- Find if node is key of a list while deletion if yes, then delete the parent.
- How to verify it
Added PyTest:
Below are sample config and cropped config files.
Cropped Config