Remove direct dependency on libyang#4118
Open
bhouse-nexthop wants to merge 1 commit intosonic-net:masterfrom
Open
Remove direct dependency on libyang#4118bhouse-nexthop wants to merge 1 commit intosonic-net:masterfrom
bhouse-nexthop wants to merge 1 commit intosonic-net:masterfrom
Conversation
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This was referenced Nov 4, 2025
e869613 to
600cf75
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
600cf75 to
842d685
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
842d685 to
9380b1f
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
9380b1f to
4975789
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
forced a rebuild, hoping it pulls the updated assets from the merge of sonic-net/sonic-buildimage#24414 so it passes |
mssonicbld
added a commit
to mssonicbld/sonic-buildimage-msft
that referenced
this pull request
Jan 22, 2026
#### Why I did it This is needed by sonic-utilities to prevent a direct dependency on libyang. By adding these helpers, sonic-utilities will use only what is provided by sonic-yang-mgmt and not be dependent on the version of libyang installed. #### How I did it Added helpers to: - Load a yang module based on the provided string and return the loaded module name. - Recursively locate dependencies for a given yang path #### How to verify it See included test cases. #### Which release branch to backport (provide reason below if selected) N/A #### Tested branch (Please provide the tested image version) master as of 2025-11-03 #### Description for the changelog sonic-yang-mgmt: helpers to prevent dependents from calling into libyang #### Link to config_db schema for YANG module changes N/A #### A picture of a cute animal (not mandatory but encouraged) Fixes #22385 Needed by sonic-net/sonic-utilities#4118
r12f
pushed a commit
to Azure/sonic-buildimage-msft
that referenced
this pull request
Jan 23, 2026
…om calling into libyang (#1951) #### Why I did it This is needed by sonic-utilities to prevent a direct dependency on libyang. By adding these helpers, sonic-utilities will use only what is provided by sonic-yang-mgmt and not be dependent on the version of libyang installed. #### How I did it Added helpers to: - Load a yang module based on the provided string and return the loaded module name. - Recursively locate dependencies for a given yang path #### How to verify it See included test cases. #### Which release branch to backport (provide reason below if selected) N/A #### Tested branch (Please provide the tested image version) master as of 2025-11-03 #### Description for the changelog sonic-yang-mgmt: helpers to prevent dependents from calling into libyang #### Link to config_db schema for YANG module changes N/A #### A picture of a cute animal (not mandatory but encouraged) Fixes #22385 Needed by sonic-net/sonic-utilities#4118
4975789 to
3d87521
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
saiarcot895
reviewed
Apr 10, 2026
qiluo-msft
pushed a commit
to sonic-net/sonic-buildimage
that referenced
this pull request
Apr 16, 2026
…olation (#26563) Why I did it NOTE: This is part of the libyang3 enablement series. These fixes are needed to be able to merge sonic-net/sonic-utilities#4118 to remove direct dependency on libyang from sonic-utilities Fix uses clause compilation to handle all YANG node types in groupings. Previously, _preProcessYangGrouping only captured leaf, leaf-list, and choice nodes from groupings, silently dropping container, list, and uses children. Similarly, _compileUsesClause only merged those three types. Both now handle all six node types (leaf, leaf-list, choice, container, list, uses). Also add "notification" to the node types traversed by _compileUsesClauseModel so uses clauses within notification nodes are compiled. Fix sonic-cfg-help parse_leaf to handle union types with a single member. When xmltodict converts a YANG union with one type, it produces a dict instead of a list. The old code assumed a list and would iterate dict keys, producing incorrect results or crashing. Work item tracking Microsoft ADO (number only): How I did it Rewrite find_data_dependencies() to properly handle container, list, and global "/" xpaths by recursing into data tree descendants via tree_dfs() while preserving per-leaf value matching against backlink targets. The previous implementation lost value matching when called on non-leaf xpaths, causing incorrect dependency results (e.g., returning refs for unrelated ports when querying a specific port's container). The rewrite splits the logic into helper methods: _find_data_dependencies_node(): recurses via tree_dfs(), extracts leaf values, finds schema backlinks, and resolves them against the data tree with value filtering _find_data_dependencies_global(): iterates top-level data nodes via tree_for() and delegates to _find_data_dependencies_node() _resolve_backlink_data(): matches backlink schema paths against actual data nodes, filtering by the originating leaf's value Remove the unused error_log_level parameter from loadData(). The parameter was never meaningfully used and added unnecessary API surface. Restructure tests into independent classes with isolated fixtures: Test_SonicYang_Loading: class-scoped fixtures for the progressive load/merge/validate pipeline where tests build on prior state Test_SonicYang: function-scoped fixtures that create a fresh SonicYang instance per test, ensuring each test starts from a clean data tree rather than depending on mutations from prior tests Test_SonicYang_UsesCompilation: validates grouping preprocessing captures container/list/uses nodes, uses clause compilation merges them correctly, and notification nodes are traversed Previously all tests shared a single class-scoped SonicYang instance, meaning test_add_node, test_delete_node, and test_set_datanode_value permanently modified the data tree for all subsequent tests. This coupling made it impossible to run tests individually or reorder them without failures, and masked bugs where test expectations depended on accumulated state rather than the config data file. How to verify it Run test suite with the changes made in this PR: Add regression test cases for find_data_dependencies: List entry xpath (PORT_LIST without leaf suffix) returns the same dependencies as querying the specific leaf ACL_TABLE_LIST entry returns only ACL_RULE refs matching that specific table name Fix ACL_TABLE container and global "/" test expectations to only include refs matching existing ACL_TABLE entries Add test-grouping.yang model and tests exercising uses compilation with container, list, nested uses, and notification nodes. Add unit tests for sonic-cfg-help union type handling covering single-type, multi-type, and non-leafref union members.
3d87521 to
48108e8
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
48108e8 to
356a67c
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
/azpw run |
Collaborator
|
Retrying failed(or canceled) jobs... |
sonic-utilities should never call directly into libyang. All functionality it needs should be provided in sonic-yang-mgmt. This resolves issues when libyang changes API/ABI such as happened between libyang1 and libyang2, and again between libyang2 and libyang3. Depends on sonic-net/sonic-buildimage#24414 Signed-off-by: Brad House <[email protected]>
356a67c to
86f1c8a
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
@saiarcot895 @qiluo-msft this is the next libyang3 blocker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
sonic-utilities should never call directly into libyang. All functionality it needs should be provided in sonic-yang-mgmt. This resolves issues when libyang changes API/ABI such as happened between libyang1 and libyang2, and again between libyang2 and libyang3.
Depends on sonic-net/sonic-buildimage#24414 and sonic-net/sonic-buildimage#26563
Fixes sonic-net/sonic-buildimage#22385
How I did it
Removed calls to libyang and instead uses new functionality introduced in sonic-yang-mgmt.
Also installs both libyang1 and libyang3 for tests to maintain compatibility with both during the migration.
How to verify it
After sonic-net/sonic-buildimage#24414 merges observe test cases still pass.
Previous command output (if the output of a command-line utility has changed)
N/A
New command output (if the output of a command-line utility has changed)
N/A