[telemetry] Support both libyang1 and libyang3 in validate_yang_events.py#25508
Open
bingwang-ms wants to merge 1 commit into
Open
[telemetry] Support both libyang1 and libyang3 in validate_yang_events.py#25508bingwang-ms wants to merge 1 commit into
bingwang-ms wants to merge 1 commit into
Conversation
…s.py SONiC 202511 (Debian 13) ships libyang1 Python bindings as the 'yang' module (python3-yang package). SONiC 202512+ will have libyang3 Python bindings as the 'libyang' module after sonic-buildimage#26584 lands. The previous commit (c6fb27f) ported the script from 'import yang' to 'import libyang', which works on 202512+ but breaks on 202511 with ModuleNotFoundError: No module named 'libyang'. Add a try/except import fallback so the script works on both: - libyang3 (import libyang): uses the new API (IOType.FILEPATH, parse_data_mem with keyword args) - libyang1 (import yang): uses the old API (LYS_IN_YANG, LYD_JSON / LYD_OPT_CONFIG | LYD_OPT_STRICT) Verified on Nokia IXR7220-H6 running SONiC.20251210.07 (202511). Signed-off-by: Bing Wang <bingwang@microsoft.com>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
This PR has backport request for branch(es): 202511,202505. ---Powered by SONiC BuildBot
|
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.
Description of PR
Summary:
On SONiC 202511 and earlier, the DUT has libyang1 (Python module
yang, packagepython3-yangvia SWIG binding). Starting with SONiC 202512+, libyang3 (Python modulelibyang) will be available.validate_yang_events.pywas written for libyang3 and fails withModuleNotFoundError: No module named libyangon 202511 DUTs.This PR adds a try/except fallback so the script works with either libyang version. The libyang1 API uses
yang.Contextwithctx.parse_module_path()andctx.parse_data_mem(), while libyang3 useslibyang.Contextwithctx.parse_module()andctx.parse_data(). Both paths are now supported.Fixes failing
test_eventson Nokia TH6 (SONiC 202511) and other platforms running SONiC ≤202511.Type of change
Back port request
Approach
What is the motivation for this PR?
validate_yang_events.pyuses libyang3 Python API but SONiC 202511 DUTs only have libyang1. This causestest_eventsto fail withModuleNotFoundError: No module named libyang.How did you do it?
Added a try/except import block: try
import libyang(libyang3), fall back toimport yang as libyang(libyang1). Added an_LY3boolean flag to branch the API calls that differ between libyang1 and libyang3.How did you verify/test it?
Ran
test_eventson Nokia TH6 testbed (SONiC 202511/Debian 13). Test PASSED.Any platform specific information?
Affects all platforms running SONiC ≤202511 with libyang1.
Supported testbed topology if it's a new test case?
N/A
Documentation
N/A