Skip to content

[202405][GCU] Backport sonic-yang-mgmt + libyang perf-dep patches (co-req PR #417 on sonic-utilities.msft)#2733

Open
rimunagala wants to merge 3 commits into
Azure:202405from
rimunagala:rimunagala/202405-gcu-3layer
Open

[202405][GCU] Backport sonic-yang-mgmt + libyang perf-dep patches (co-req PR #417 on sonic-utilities.msft)#2733
rimunagala wants to merge 3 commits into
Azure:202405from
rimunagala:rimunagala/202405-gcu-3layer

Conversation

@rimunagala

@rimunagala rimunagala commented Jul 22, 2026

Copy link
Copy Markdown

Backport GCU perf dependencies: sonic-yang-mgmt helpers + libyang must_size() patch to 202405

This is Layers 2 + 3 of a 2-PR coordinated backport of upstream sonic-net/sonic-utilities#3831 (GCU perf improvements). The Layer 1 code lives at Azure/sonic-utilities.msft#417.

What's in this PR

Layer 2 — src/sonic-yang-mgmt/ (in-tree, not a submodule): 3 cherry-picks backporting upstream #22254:

  • New sonic_yang_path.py — YANG path-manipulation helpers
  • find_schema_dependencies() — schema dep index with caching
  • find_schema_must_count() — must-constraint counting (needs Layer 3)
  • Backlinks / must caches for O(1) lookups

Layer 3 — src/libyang/patch/libyang-leaf-must.patch: exposes Schema_Node_Leaf::must_size() on the libyang 1.0.73 swig CPP binding. Without this, Layer 2's find_schema_must_count() raises AttributeError at runtime.

Why this MUST merge before #417

Without Layer 2, PR #417 python code hits AttributeError: 'SonicYang' object has no attribute 'find_schema_dependencies' on import. Without Layer 3, Layer 2's find_schema_must_count() hits AttributeError: 'Schema_Node_Leaf' object has no attribute 'must_size'.

Layer 1 (#417) present Layer 2 present Layer 3 present Runtime behavior
* * stock 202405 GCU (slow, no perf win)
* AttributeError on GCU init
AttributeError on must-count during patch validation
✅ Full perf win — see #417 for benchmarks

Validation (all 3 layers combined)

Full test matrix (perf, correctness, multi-ASIC, real writes, error handling, code audit) is in Azure/sonic-utilities.msft#417. Headline numbers:

Scenario Baseline Ported Speedup
500-op patch 171.6s 12.6s 13.57x
1000-op patch timeout 32.4s port-only-wins
100-op patch (5-iter mean) 21.4s 4.9s 4.36x

Real (non-dry-run) apply of 50 ACL rules: rc=0 in 7.9s, all 50 present in CONFIG_DB. Rollback of 49 rules: rc=0 in 6.8s. Multi-ASIC patch spanning /asic0/ + /asic1/: rc=0, both namespaces validated. Four malformed-patch scenarios all produce graceful rc=2 errors with no python tracebacks.

Tested on str3-7800-lc3-1 (Arista 7800R3A-36DM2-D36 chassis LC, stock SONiC.20240532.59, Python 3.11.2, libyang 1.0.73 patched).

Files

19 files changed: src/sonic-yang-mgmt/** (Layer 2 python + tests) and src/libyang/patch/libyang-leaf-must.patch (Layer 3).

Merge order

  1. This PR merges first
  2. [202405][GCU perf backport #3831] Config-threading refactor (part 1/N) sonic-utilities.msft#417 (Layer 1) merges next
  3. Follow-up submodule bump here pointing src/sonic-utilities at [code sync] Merge code from sonic-net/sonic-buildimage:202205 to 202205 #417's merged SHA

bradh352 and others added 3 commits July 22, 2026 14:51
When a uses clause imports a grouping, it was only processing leaf entries and ignoring leaf-list and choice clauses. That means that for instance in bgp route maps, route_map_in and route_map_out validations would fail.

Honoring the uses refine clause is now also honored which is depended upon in sonic-utilities.

This now precompiles the uses clause and integrates it as if the uses clause was not part of the schema as multiple end users were having to do this additional processing.

This fixes that behavior and adds test cases to ensure it doesn't regress in the future.

This is the proper fix, replacing #21078 that just worked around it.

Removal of uses logic in sonic-utilities here: sonic-net/sonic-utilities#3814

Fixes #22382

Work item tracking
Microsoft ADO (number only):
How I did it
Added leaf-list lookup.

How to verify it
See test cases pass

Description for the changelog
sonic-yang-mgmt: uses clause with leaf-list, choice not honored
…22254)

Why I did it
Generic Config Updater (GCU) is notoriously slow. These patches add some helpers for the GCU overhaul (mostly in sonic-utilities) in order to facilitate the optimizations. These changes are in sonic-yang-mgmt plus a patch to libyang 1.

Changes include:

Libyang v1 was not exposing must data for leaf nodes (like it does for other node types). Patch to correct this oversight.
Loading of sonic configuration data should not mutate the user-provided data, this forces callers to know they need to deepcopy the data, plus in most instances data won't be mutated.
sonic-yang-mgmt test models should more closely mimic real sonic yang models as we can't implement other features that assume this otherwise (sonic mandates that the top-level container has the same name as the module).
Import sonic configdb<>yang xpath conversion from sonic-utilities as this should be shared code. 90% of this code is copied from the original source but does contain some bugfixes and enhancements including caching.
Make find_schema_dependencies() public, plus add the ability to find dependencies recursively. This implementation is caching.
Add new find_schema_must_count(), with recursive capabilities to find if a node (and its children) have must clauses. This implementation is caching.
sonic-utilities PR: sonic-net/sonic-utilities#3831

Stats below ... (stats need both this and the sonic-utilities PR to be relevant)...

Original Performance:
Dry Run:

time sudo config replace -d ./config_db.json
...
real	2m51.588s
user	2m23.777s
sys	0m25.300s
Full:

time sudo config replace ./config_db.json
...
real	14m53.772s
user	12m2.376s
sys	2m8.908s
With Patch:
Dry Run:

time sudo config replace -d ./config_db.json
...
real	0m59.602s
user	0m56.434s
sys	0m2.110s
Full:

time sudo config replace ./config_db.json
...
real	1m54.303s
user	0m58.482s
sys	0m2.545s
So that's roughly 3x improvement for dry-run, and 7.5x improvement for full commit. There is room for improvement on the full commit due to a sleep(1) being used between each patch because of a race condition found in the prior code (that was hidden due to a costly sanity check that has been removed).

Work item tracking
How I did it
Gathered profiling data using cProfile and evaluated where the largest gains could be had.

How to verify it
This patch is standalone as it will not cause any issues in other projects which use sonic-yang-mgmt or libyang, however the performance benefits are in sonic-utilities. Apply both this commit and the sonic-utilities PR to a local branch, build and run sonic-utilities tests. Then create a full image, load it onto a DUT (with default configuration), and use the attached
config_db.json to attempt a config replace operation (tested on Dell S5248F).

Which release branch to backport (provide reason below if selected)
 202411
Tested branch (Please provide the tested image version)
master as of 20250521

Description for the changelog
sonic-yang-mgmt: Generic Config Updater - performance dependencies

Fixes #22372
loadData currently logs LOG_ERR "Data Loading Failed" to syslog on every exception (log-and-throw antipattern) before raising. This is undesirable for callers that use loadData speculatively to test many candidate configs for validity, e.g. generic_config_updater patch sorter (sonic-utilities) FullConfigMoveValidator — every forward leafref during the search emits a LOG_ERR to syslog even though the caller handles the exception and uses it as a prune signal.

Add a quiet=False kwarg. When quiet=True, suppress the informational "Try to load Data" line and the LOG_ERR "Data Loading Failed" line, but still raise SonicYangException so the caller sees the failure.

Default quiet=False preserves existing behavior for all current callers (including config apply-patch final validation, db_migrator upgrades, sonic-cfggen, and unit tests).

Paired with sonic-utilities change that makes patch_sorter.FullConfigMoveValidator pass quiet=True.

<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "fixes #xxxx", or
 "closes #xxxx" or "resolves #xxxx"

 Please provide the following information:
-->

#### Why I did it

 On T0 devices, a single `config apply-patch` invocation leaks 100+ `Data Loading Failed` ERR lines to /var/log/syslog. These come from the GCU patch sorter's speculative `FullConfigMoveValidator`, which deliberately tests candidate moves that may transiently violate leafref constraints during the search — the sorter already handles the failure via the
returned `(False, error)` tuple. The ERR lines trip `loganalyzer` in sonic-mgmt baseline tests (e.g. `test_dhcp_relay_with_non_default_vrf`, `test_dhcp_relay_with_different_non_default_vrf`) and obscure real errors in support bundles.

 The root cause is `loadData`'s log-and-throw antipattern: it emits a LOG_ERR *and* raises, forcing log noise on callers that are expected to recover.

##### Work item tracking
- Microsoft ADO **(number only)**:

#### How I did it

 Added a `quiet=False` kwarg to `SonicYangExtMixin.loadData`. When `True`, guard the informational `"Try to load Data"` sysLog and the `LOG_ERR "Data Loading Failed"` sysLog behind `if not quiet:`. `SonicYangException` is still raised on failure, so nothing about the control flow changes — only the syslog side-effect is suppressed. Default `quiet=False`
preserves behavior for every current caller.

#### How to verify it

 1. Build `python3-sonic-yang-mgmt` wheel from this branch and install on a T0 DUT.
 2. Pair with the sonic-utilities PR that threads `quiet=True` from `FullConfigMoveValidator` → `validate_config_db_config` → `loadData`.
 3. Run `sonic-mgmt` generic_config_updater tests and/or `dhcp_server/test_dhcp_server_port_based_customize_options` on a T0 and count `"Data Loading Failed"` lines in `/var/log/syslog` across the window.

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

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

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [x] 202511

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>

#### A picture of a cute animal (not mandatory but encouraged)
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants