Skip to content

Conversation

@bradh352
Copy link
Contributor

@bradh352 bradh352 commented Feb 8, 2025

Why I did it

Upgrade to libyang3

See master tracking ticket #22385

Fixes #22385

Work item tracking

N/A

How I did it

  • Remove unused libyang 1.0.184
  • Import libyang 3.12.2
  • Import libyang-python 3.1.0
  • Migrate FRR to use libyang 3.12.2
  • Update yang model test cases in preparation of libyang3 (will make the next PR easier to understand)

Important: Please review each commit (including commit message) individually. Looking at the patch-set as a whole may cause confusion.

How to verify it

See that the build still succeeds and existing test cases still pass

Which release branch to backport (provide reason below if selected)

N/A

Tested branch (Please provide the tested image version)

master as of 20250613

Description for the changelog

libyang: upgrade to v3 step 1

Link to config_db schema for YANG module changes

N/A

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

Signed-off-by: Brad House (@bradh352)

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bradh352
Copy link
Contributor Author

bradh352 commented Feb 8, 2025

@ganglyu @qiluo-msft please review ... this needs to be merged before I can submit PRs for the migration of the libyang 1.0.73 code to v3 ...

@wen587
Copy link
Contributor

wen587 commented Feb 8, 2025

Hi @bradh352 , could you help me understand why src/sonic-yang-models/tests/yang_model_tests/tests/ is impacted? Aren't they dependent on libyang 1.0.73?

@ganglyu
Copy link
Contributor

ganglyu commented Feb 8, 2025

@bradh352

Thank you very much for your contribution!

We have encountered numerous issues with libyang 1.0.73, which is currently used by sonic-yang-models. On the other hand, libyang 1.0.184 and libyang 2.1.148, which are used by FRR, have not presented any issues to our knowledge.

My suggestion is to install libyang3 in this PR without replacing the existing dependency.

@ganglyu ganglyu requested a review from saiarcot895 February 8, 2025 07:16
@bradh352
Copy link
Contributor Author

bradh352 commented Feb 8, 2025

@ganglyu

@bradh352

Thank you very much for your contribution!

We have encountered numerous issues with libyang 1.0.73, which is currently used by sonic-yang-models. On the other hand, libyang 1.0.184 and libyang 2.1.148, which are used by FRR, have not presented any issues to our knowledge.

My suggestion is to install libyang3 in this PR without replacing the existing dependency.

I honestly believe not having multiple versions of libyang to be extremely important. I think their API is stabilizing. The only thing required was to apply some commits already upstream in FRR 10.2 to support 3.7.8. From the commit message:

This also backports a series of commits from FRR to support libyang3,
upgrading FRR itself isn't currently in scope:

I think we'd be foolish to kick the can down the road while we're working on it now. I also haven't verified if libyang2 and libyang3 can be installed simultaneously like libyang1 and libyang3 can.

Of course if you tell me there's no way you could possibly accept this PR because of this you leave me little choice but I don't see a sufficient argument at this time against it.

@bradh352
Copy link
Contributor Author

bradh352 commented Feb 8, 2025

Hi @bradh352 , could you help me understand why src/sonic-yang-models/tests/yang_model_tests/tests/ is impacted? Aren't they dependent on libyang 1.0.73?

From the commit message:

sonic-yang-models: Update test cases in preparation for libyang3
Convert some yang model test cases that use eStr for failure matching
to use eStrKey instead to standardize expected failure matching so
when messsages change they can be updated in one place instead of all
over.

Also, split out some new eStrKey values that are needed for libyang3
due to different messages, and document the libyang3 values needed once
upgraded but keep libyang1 values for now.

Finally, some tests were using both eStr and eStrKey and the eStr
portion is not needed to perform a meaningful validation, plus the
eStr in these cases are not valid for libyang3.

So basically, its just to make the review of the upgrade to libyang3 easier. I've actually got libyang3 working and passing these test cases so I wanted a bulk of the test case changes done here to make it easier to review the more complex porting of the libyang1 python swig module to libyang3 python cffi.

@bradh352
Copy link
Contributor Author

bradh352 commented Feb 8, 2025

Guess I need to figure out python wheel packaging for cross compilation to support marvell armhf (its an architecture-specific package since it uses cffi)? I clearly am not testing such a use case currently in my local environment. Anyone have any pointers for this?

@ganglyu
Copy link
Contributor

ganglyu commented Feb 8, 2025

@ganglyu

@bradh352
Thank you very much for your contribution!
We have encountered numerous issues with libyang 1.0.73, which is currently used by sonic-yang-models. On the other hand, libyang 1.0.184 and libyang 2.1.148, which are used by FRR, have not presented any issues to our knowledge.
My suggestion is to install libyang3 in this PR without replacing the existing dependency.

I honestly believe not having multiple versions of libyang to be extremely important. I think their API is stabilizing. The only thing required was to apply some commits already upstream in FRR 10.2 to support 3.7.8. From the commit message:

This also backports a series of commits from FRR to support libyang3,
upgrading FRR itself isn't currently in scope:

I think we'd be foolish to kick the can down the road while we're working on it now. I also haven't verified if libyang2 and libyang3 can be installed simultaneously like libyang1 and libyang3 can.

Of course if you tell me there's no way you could possibly accept this PR because of this you leave me little choice but I don't see a sufficient argument at this time against it.

I will engage the owner of SONiC FRR to review the related changes.

@ganglyu
Copy link
Contributor

ganglyu commented Feb 8, 2025

Guess I need to figure out python wheel packaging for cross compilation to support marvell armhf (its an architecture-specific package since it uses cffi)? I clearly am not testing such a use case currently in my local environment. Anyone have any pointers for this?

I'm not an expert, but I believe the Sonic build pipeline uses the armhf system to build the Sonic image for Marvell armhf. Therefore, we shouldn't encounter any cross-compilation issues in the Sonic build pipeline.

@bradh352
Copy link
Contributor Author

bradh352 commented Feb 8, 2025

Guess I need to figure out python wheel packaging for cross compilation to support marvell armhf (its an architecture-specific package since it uses cffi)? I clearly am not testing such a use case currently in my local environment. Anyone have any pointers for this?

Looks like azure isn't actually cross compiling at all, its running an armhf image that is advertising armv8l support which I think just means the kernel knows its a 64bit cpu ... but the system was compiled for armv7l/armhf, so python is I think determining the system based on uname -m.

I tried using a 64bit arm vm on my macbook to build sonic, but it immediately fails as it thinks I need to use QEMU multiarch ... even hacking the makefile to disable that and it fails later on. Parallels doesn't allow me to directly install an armhf image, so I guess I'm dead in the water trying to test this on my own hardware right now. I might need to pick up an rpi5 or something to build but that seems like it might be really really slow....

So I'll probably try to throw in some test commits to see if a simple 'setarch armhf' works around the issue.

@bradh352 bradh352 force-pushed the bradh352/libyang3-only branch 2 times, most recently from 801cc52 to 4a1b620 Compare February 8, 2025 15:51
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bradh352 bradh352 force-pushed the bradh352/libyang3-only branch from 4a1b620 to 86f10cd Compare February 8, 2025 15:53
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bradh352 bradh352 force-pushed the bradh352/libyang3-only branch from 21c8a3f to 644bc6a Compare June 15, 2025 01:43
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

bradh352 added 9 commits June 15, 2025 08:52
This does the base upgrade from libyang2 to libyang3.   It also drops
the completely unused libyang1 build (as the version used is in the libyang
directory which is 1.0.73).

NOTE: libyang3 depends on pkgconf, which supersedes pkg-config so there is
some churn to docker image building switching packages but it works for
all packages as a replacement.
This patch was rejected upstream as it is considered a bad practice.
However, in the sonic-mgmt-common code, it has chosen to bypass
using libyang for a lot of validation, so this flag is necessary
in this use case.  sonic-mgmt-common will likely switch to goyang
in the future.
We omit the _UNINSTALLS because it messes up dependency tracking with
other packages that depend on libyang3
libyang 1.0.73 provided python bindings via swig.  Those have
been removed and libyang3 now requires the use of the cffi bindings
which are in a separate repo.

The binding names themselves are actually different ('yang' vs 'libyang')
so both should be installable simultaneously.

This is built as a debian package rather than a wheel since it contains
binary elements.
CESNET/libyang-python#134

needed for backwards compatibility for existing configurations.
We need to force libyang3-py3 to be built and tested, and confirm
it can properly co-exist with libyang1 and its python bindings.

Its currently not used, but will be in a followup.
This mostly simplifies the existing test cases and standardizes
behavior where they may be incompatible with libyang3.  The main goal
is to have this in place before the migration to libyang3 to make it
easier to evaluate the actual code review for porting aspects for libyang3.

Convert some yang model test cases that use `eStr` for failure matching
to use `eStrKey` instead to standardize expected failure matching so
when messsages change they can be updated in one place instead of all
over.

Split out some new `eStrKey` values that are needed for libyang3
due to different messages, and document the libyang3 values needed once
upgraded but keep libyang1 values for now.

Finally, some tests were using both `eStr` and `eStrKey` and the `eStr`
portion is not needed to perform a meaningful validation, plus the
`eStr` in these cases are not valid for libyang3.
@bradh352 bradh352 force-pushed the bradh352/libyang3-only branch from 644bc6a to a28041c Compare June 15, 2025 12:53
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bradh352
Copy link
Contributor Author

I keep getting spurious test failures that aren't related to this PR. I guess I'll just keep on forcing rebuilds all tests pass.

@bradh352
Copy link
Contributor Author

@qiluo-msft looks like all test cases passed on the last run if you could do a final review and hopefully merge this.

@liushilongbuaa
Copy link
Contributor

/azpw ms_conflict

1 similar comment
@liushilongbuaa
Copy link
Contributor

/azpw ms_conflict

@bradh352
Copy link
Contributor Author

@qiluo-msft this is merge-ready. You approved in the past but I had upstream a fix to buster builds (not sure why buster is even built as it is EOL). Since this is targeted for 202511 and there are 17 other PRs that depend on this to complete the libyang3 migration it is imperative this be merged sooner rather than later if that goal is going to be accomplished.

@qiluo-msft qiluo-msft merged commit 111570d into sonic-net:master Jun 24, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in yang Jun 24, 2025
$(LIBYANG3)_SRC_PATH = $(SRC_PATH)/libyang3
SONIC_MAKE_DEBS += $(LIBYANG3)

LIBYANG3_DEV = libyang-dev_$(LIBYANG3_FULLVERSION)_$(CONFIGURED_ARCH).deb
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason we're breaking naming convention for the dev header package?

Copy link
Contributor

Choose a reason for hiding this comment

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

What convention are you referring to? The package is from upstream debian, so they set the naming convention for the generate .debs, so this variable simply sets the appropriate name.

Copy link
Contributor

Choose a reason for hiding this comment

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

See also https://packages.debian.org/source/testing/libyang, where Debian chose the name libyang-dev for the dev header package.

Note also that this is because they only support libyang 3 going forward in Trixie, so they don't need to consider providing support for libyang 1 and 2 headers and libraries.

Copy link
Contributor

Choose a reason for hiding this comment

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

See also https://packages.debian.org/source/testing/libyang, where Debian chose the name libyang-dev for the dev header package.

Note also that this is because they only support libyang 3 going forward in Trixie, so they don't need to consider providing support for libyang 1 and 2 headers and libraries.

well that and they conflict so both can't be installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah typically the "libxxx" portion of the package name stays consistent between the library, header, and debug packages (so I was expecting "libyang3-dev..."). I didn't realize they aren't doing this anymore, my mistake.

qiluo-msft pushed a commit to sonic-net/sonic-swss-common that referenced this pull request Jul 8, 2025
Limit grabbed libyang libraries to only v1.

Upgrading to libyang v3 (sonic-net/sonic-buildimage#21679) is causing the swss-common pipeline build to fail. The pipeline assumes that any package starting with libyang_ or libyang- is a libyang v1 package and tries to install it. However, the dev header package for libyang v3 starts with libyang-, so the pipeline tries to download/install it as well, which causes the build to fail since it depends on the base libyang v3 package which is not grabbed because it starts with libyang3.
mssonicbld added a commit to mssonicbld/sonic-swss-common.msft that referenced this pull request Jul 18, 2025
Limit grabbed libyang libraries to only v1.

Upgrading to libyang v3 (sonic-net/sonic-buildimage#21679) is causing the swss-common pipeline build to fail. The pipeline assumes that any package starting with `libyang_` or `libyang-` is a libyang v1 package and tries to install it. However, the dev header package for libyang v3 starts with `libyang-`, so the pipeline tries to download/install it as well, which causes the build to fail since it depends on the base libyang v3 package which is not grabbed because it starts with `libyang3`.
mssonicbld added a commit to Azure/sonic-swss-common.msft that referenced this pull request Jul 18, 2025
Limit grabbed libyang libraries to only v1.

Upgrading to libyang v3 (sonic-net/sonic-buildimage#21679) is causing the swss-common pipeline build to fail. The pipeline assumes that any package starting with `libyang_` or `libyang-` is a libyang v1 package and tries to install it. However, the dev header package for libyang v3 starts with `libyang-`, so the pipeline tries to download/install it as well, which causes the build to fail since it depends on the base libyang v3 package which is not grabbed because it starts with `libyang3`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Enhancement: Upgrade to libyang3

10 participants