Skip to content

Move create-only to yang - #28737

Open
bradleymoon-nexthop wants to merge 3 commits into
sonic-net:masterfrom
nexthop-ai:move-create-only-to-yang
Open

bradleymoon-nexthop wants to merge 3 commits into
sonic-net:masterfrom
nexthop-ai:move-create-only-to-yang

Conversation

@bradleymoon-nexthop

@bradleymoon-nexthop bradleymoon-nexthop commented Jul 30, 2026

Copy link
Copy Markdown

Why I did it

Currently, the Generic Config Updater (GCU) in sonic-utilities (specifically inside patch_sorter.py) relies on a static, hardcoded list of create-only fields to prevent users from modifying immutable attributes. This approach is rigid, hard to scale, and divorces schema properties from the actual YANG validation layer.

To resolve this, we are transitioning to a declarative, schema-driven approach by moving the create-only configuration metadata out of hardcoded scripts and directly into YANG models as declarative annotations (ext:create-only, see sonic-net/sonic-mgmt-common#234 and sonic-net/sonic-utilities#4733).

How I did it

  • Updated the custom YANG extension template sonic-extension.yang.j2 (and sample test models) to declare the ext:create-only extension.
  • Annotated the relevant leaves/containers across 8 YANG models with the ext:create-only decorator:
    • sonic-port.yang (leaf lanes)
    • sonic-loopback-interface.yang (leaf vrf_name)
    • sonic-scheduler.yang (leaves: type, weight, cir, pir, cbs, pbs, meter_type)
    • sonic-mirror-session.yang (container MIRROR_SESSION)
    • sonic-bgp-neighbor.yang (leaves on BGP_NEIGHBOR_LIST uses sites)
    • sonic-bgp-monitor.yang (leaves on BGP_MONITORS_LIST uses sites)
    • sonic-bgp-peerrange.yang (container BGP_PEER_RANGE)
    • sonic-bgp-sentinel.yang (container BGP_SENTINELS)
    • Note: BGP-related annotations are attached via refine at individual uses sites rather than on the shared groupings in sonic-bgp-common.yang. This ensures that unrelated tables like BGP_PEER_GROUP, BGP_INTERNAL_NEIGHBOR, and BGP_VOQ_CHASSIS_NEIGHBOR do not inherit these constraints.
  • Added get_create_only_fields() method to sonic_yang_ext.py in sonic-yang-mgmt to dynamically walk the compiled YANG models using the libyang schema tree and discover the annotated elements, replacing the static GCU list.
  • Implemented unit tests in src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py:
    • test_get_create_only_fields_matches_expected_set: Asserts that get_create_only_fields() on the installed models produces exactly the 26 expected patterns matching the original hardcoded fallback list.
    • test_get_create_only_fields_direct_and_refine: Tests discovery mechanism on fixture models covering both direct leaf annotations and refine-carried annotations.

How to verify it

  • Run the newly added unit tests inside the sonic-yang-mgmt test suite during image build or manually:
    pytest src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py
    Ensure all 26 patterns are dynamically discovered and match the expected golden set exactly.

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

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

Signed-off-by: bradleymoon-nexthop <bradleymoon@nexthop.ai>
@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

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

Keep the upstream module description and add sonic-extension for
ext:create-only on lanes.

Signed-off-by: Bradley Moon  <bradleymoon@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

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

CI cannot fetch 9d57664 from sonic-net/sonic-mgmt-common. Keep
buildimage independent until sonic-mgmt-common#234 merges.

Signed-off-by: Bradley Moon  <bradleymoon@nexthop.ai>
@azure-pipelines

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

@yijingyan2

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

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.

3 participants