Skip to content

[action] [PR:28248] [yang-mgmt] Treat empty CONFIG DB leaf-list (['']) as empty so libyang3 accepts empty pattern-constrained leaf-lists#28308

Merged
mssonicbld merged 1 commit into
sonic-net:202605from
mssonicbld:cherry/202605/28248
Jul 14, 2026
Merged

[action] [PR:28248] [yang-mgmt] Treat empty CONFIG DB leaf-list (['']) as empty so libyang3 accepts empty pattern-constrained leaf-lists#28308
mssonicbld merged 1 commit into
sonic-net:202605from
mssonicbld:cherry/202605/28248

Conversation

@mssonicbld

Copy link
Copy Markdown
Collaborator

Why I did it

config apply-patch, config replace and config rollback fail on master for any configuration that contains an empty pattern-constrained leaf-list. BGP_ALLOWED_PREFIXES is the common trigger, because a deployment often populates only prefixes_v4 or only prefixes_v6, leaving the other leaf-list empty.

An empty leaf-list is stored in CONFIG DB as field@ = "". The Python ConfigDBConnector deserialises that empty string into a single empty-string element (['']), which is the CONFIG DB representation of "no elements", not a real element. Before the libyang1 to libyang3 port (#26584) the '' sentinel was tolerated by the validation library. libyang3 validates the '' element against the leaf type's pattern (for example the ipv4-prefix pattern of BGP_ALLOWED_PREFIXES.prefixes_v4) and rejects the whole config:

Unsatisfied pattern - "" does not conform to "(([0-9]| ... )/(([0-9])|([1-2][0-9])|(3[0-2]))( (le|ge) ...)?"
Data path: .../BGP_ALLOWED_PREFIXES_LIST[deployment='DEPLOYMENT_ID'][id='0']/prefixes_v4

This is a read-side (config-to-YANG validation) regression. #26584 did add a guard for the sibling case of an empty leaf-list that has a schema default "", but missed the pattern-typed, no-default leaf-list case (['']), which is exactly BGP_ALLOWED_PREFIXES.

This fixes the read-side regression behind sonic-mgmt test generic_config_updater/test_bgp_prefix.py (tracked by sonic-mgmt issue 25549). It is complementary to, and does not replace, the separate write-side effort that avoids writing prefixes_v4@ = "" into CONFIG DB in the first place (sonic-buildimage issue 27818, sonic-utilities PR 4478). Even with that write-side fix, existing configs and other tables can still present an empty leaf-list, so the validation layer should accept it.

Work item tracking
  • Microsoft ADO (number only): 38183186

How I did it

In the CONFIG DB to YANG translation in src/sonic-yang-mgmt/sonic_yang_ext.py (the leaf-list branch of _findYangTypedValue), drop the empty-string sentinel so an empty leaf-list is represented as an empty list [], which libyang3 accepts. The drop is gated on the leaf-list having no schema default (not list(leaf.defaults())), so the existing empty-with-default handling introduced by #26584 is left byte-for-byte unchanged.

Added a regression unit test (test_empty_leaflist_collapses_to_empty) that loads BGP_ALLOWED_PREFIXES with an empty prefixes_v4 leaf-list and asserts the config validates and the leaf-list collapses to [].

How to verify it

Unit test (sonic-yang-mgmt suite): with the fix the new test passes and the full suite is green; reverting only the two changed lines makes just test_empty_leaflist_collapses_to_empty fail with the Unsatisfied pattern - "" error above.

End-to-end on a KVM t1 testbed (vms-kvm-t1-lag), baseline master image built after #26584 (so it carries the regression), matched before/after with only sonic_yang_ext.py swapped:

DUT state generic_config_updater/test_bgp_prefix.py::test_bgp_prefix_tc1_suite
before (unpatched baseline) 2 failed, 2 errors — config apply-patch returns non-zero, teardown config rollback failed
after (fix applied) 2 passed

Also verified the mechanism directly: with BGP_ALLOWED_PREFIXES|DEPLOYMENT_ID|0 holding prefixes_v4@ = "", a subsequent valid config apply-patch fails with the Unsatisfied pattern - "" error before the fix and succeeds after it.

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

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608

Tested branch (Please provide the tested image version)

  • master — SONiC.master.1145536-931dbfb70 (build 2026-06-22)

Description for the changelog

[yang-mgmt] Treat an empty CONFIG DB leaf-list (['']) as empty so libyang3 does not reject empty pattern-constrained leaf-lists such as BGP_ALLOWED_PREFIXES.

Link to config_db schema for YANG module changes

No YANG model change. BGP_ALLOWED_PREFIXES schema: https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#bgp_allowed_prefixes

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

🦔

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

…g3 accepts empty pattern-constrained leaf-lists

#### Why I did it

`config apply-patch`, `config replace` and `config rollback` fail on master for any configuration that contains an empty pattern-constrained leaf-list. `BGP_ALLOWED_PREFIXES` is the common trigger, because a deployment often populates only `prefixes_v4` or only `prefixes_v6`, leaving the other leaf-list empty.

An empty leaf-list is stored in CONFIG DB as `field@ = ""`. The Python `ConfigDBConnector` deserialises that empty string into a single empty-string element (`['']`), which is the CONFIG DB representation of "no elements", not a real element. Before the libyang1 to libyang3 port ([sonic-net#26584](sonic-net#26584)) the `''` sentinel was tolerated by the validation library. libyang3 validates the `''` element against the leaf type's pattern (for example the ipv4-prefix pattern of `BGP_ALLOWED_PREFIXES.prefixes_v4`) and rejects the whole config:

    Unsatisfied pattern - "" does not conform to "(([0-9]| ... )/(([0-9])|([1-2][0-9])|(3[0-2]))( (le|ge) ...)?"
    Data path: .../BGP_ALLOWED_PREFIXES_LIST[deployment='DEPLOYMENT_ID'][id='0']/prefixes_v4

This is a read-side (config-to-YANG validation) regression. [sonic-net#26584](sonic-net#26584) did add a guard for the sibling case of an empty leaf-list that has a schema `default ""`, but missed the pattern-typed, no-default leaf-list case (`['']`), which is exactly `BGP_ALLOWED_PREFIXES`.

This fixes the read-side regression behind sonic-mgmt test `generic_config_updater/test_bgp_prefix.py` (tracked by [sonic-mgmt issue 25549](sonic-net/sonic-mgmt#25549)). It is complementary to, and does not replace, the separate write-side effort that avoids writing `prefixes_v4@ = ""` into CONFIG DB in the first place ([sonic-buildimage issue 27818](sonic-net#27818), [sonic-utilities PR 4478](sonic-net/sonic-utilities#4478)). Even with that write-side fix, existing configs and other tables can still present an empty leaf-list, so the validation layer should accept it.

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

#### How I did it

In the CONFIG DB to YANG translation in `src/sonic-yang-mgmt/sonic_yang_ext.py` (the leaf-list branch of `_findYangTypedValue`), drop the empty-string sentinel so an empty leaf-list is represented as an empty list `[]`, which libyang3 accepts. The drop is gated on the leaf-list having no schema default (`not list(leaf.defaults())`), so the existing empty-with-default handling introduced by [sonic-net#26584](sonic-net#26584) is left byte-for-byte unchanged.

Added a regression unit test (`test_empty_leaflist_collapses_to_empty`) that loads `BGP_ALLOWED_PREFIXES` with an empty `prefixes_v4` leaf-list and asserts the config validates and the leaf-list collapses to `[]`.

#### How to verify it

Unit test (sonic-yang-mgmt suite): with the fix the new test passes and the full suite is green; reverting only the two changed lines makes just `test_empty_leaflist_collapses_to_empty` fail with the `Unsatisfied pattern - ""` error above.

End-to-end on a KVM t1 testbed (`vms-kvm-t1-lag`), baseline master image built after [sonic-net#26584](sonic-net#26584) (so it carries the regression), matched before/after with only `sonic_yang_ext.py` swapped:

| DUT state | `generic_config_updater/test_bgp_prefix.py::test_bgp_prefix_tc1_suite` |
|---|---|
| before (unpatched baseline) | 2 failed, 2 errors — `config apply-patch` returns non-zero, teardown `config rollback failed` |
| after (fix applied) | 2 passed |

Also verified the mechanism directly: with `BGP_ALLOWED_PREFIXES|DEPLOYMENT_ID|0` holding `prefixes_v4@ = ""`, a subsequent valid `config apply-patch` fails with the `Unsatisfied pattern - ""` error before the fix and succeeds after it.

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

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511
- [ ] 202512
- [ ] 202605
- [ ] 202608

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

- [x] master — `SONiC.master.1145536-931dbfb70` (build 2026-06-22)

#### Description for the changelog

[yang-mgmt] Treat an empty CONFIG DB leaf-list (`['']`) as empty so libyang3 does not reject empty pattern-constrained leaf-lists such as BGP_ALLOWED_PREFIXES.

#### Link to config_db schema for YANG module changes

No YANG model change. `BGP_ALLOWED_PREFIXES` schema: https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#bgp_allowed_prefixes

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

🦔

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

Copy link
Copy Markdown
Collaborator Author

Original PR: #28248

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

This cherry pick PR has been opened for more than 3 days. The mssonicbld will attempt to retry.

---Powered by SONiC BuildBot

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Retrying failed(or canceled) stages in build 1160048:

✅Stage Build:

  • Job marvell_prestera_armhf: retried.

✅Stage Test:

  • Job impacted-area-kvmtest-t1-lag-vpp by Elastictest: retried.
  • Job impacted-area-kvmtest-dualtor by Elastictest: retried.

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

@vaibhavhd The cherry pick PR didn't pass PR checker after retry. Left a comment in original PR #28248 to notify author.

---Powered by SONiC BuildBot

@deepak-singhal0408

Copy link
Copy Markdown
Contributor

CI Failure Analysis — Build 1160048

Both failures are not induced by this cherry-pick (which only touches src/sonic-yang-mgmt/sonic_yang_ext.py + its test). This build ran on 2026-07-12 against a stale 202605 base.

1. Build marvell_prestera_armhf

FAILED tests/sonic_package_manager/test_registry.py::test_get_registry_for
make: *** sonic_utilities-1.2-py3-none-any.whl  Error 1

The armhf slave freshly resolved the unpinned docker-image-py>=0.1.10 to the newly released 0.2.0, and the then-pinned sonic-utilities still had the uppercase 'Azure/sonic' registry test, which is not a valid lowercase Docker Hub reference under 0.2.0 → identity assertion fails. Unrelated to yang-mgmt. Already fixed on 202605 via submodule bump sonic-buildimage PR 28385 (carries sonic-utilities PR 4679, which makes test_get_registry_for version-agnostic).

2. Elastictest impacted-area-kvmtest-t1-lag-vpp

lldp/test_lldp_syncd.py ||| 2 failed  (RUN_TEST_CASE_FAILED)

lldp/test_lldp_syncd.py has no relationship to a sonic_yang_ext.py empty-leaf-list parser change — environmental/flaky, not this PR.

Recommendation

Re-trigger CI. 202605 now includes bump PR 28385, so a fresh build rebuilds the armhf sonic-utilities wheel with the fixed registry test, and the unrelated LLDP flake should clear on re-run. No code change needed.

@deepak-singhal0408

Copy link
Copy Markdown
Contributor

/azpw run Azure.sonic-buildimage

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Retrying failed(or canceled) stages in build 1160048:

✅Stage Build:

  • Job marvell_prestera_armhf: retried.

✅Stage Test:

  • Job impacted-area-kvmtest-t1-lag-vpp by Elastictest: retried.

@mssonicbld
mssonicbld merged commit 4fbeb85 into sonic-net:202605 Jul 14, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants