[sonic-py-common] Add shared BGP ASN validation - #29447
Merged
qiluo-msft merged 2 commits intoSep 18, 2026
Merged
Conversation
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
Collaborator
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
qiluo-msft
approved these changes
Sep 15, 2026
Member
Author
|
/azpw run |
Collaborator
|
Retrying failed(or canceled) jobs... |
Collaborator
|
Retrying failed(or canceled) stages in build 1221391: ✅Stage Test:
|
This was referenced Sep 17, 2026
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.
Why I did it
Several Python components need to apply the same validation when processing BGP ASNs. Keeping those checks in each component makes it easy for their behavior to drift.
Work item tracking
How I did it
Added a common
validate_asn()helper tosonic-py-common.The helper accepts decimal strings and integer values, rejects booleans and other representations, and checks the 32-bit BGP ASN range. Handling of missing values or component-specific sentinel values remains with the caller.
Added unit coverage for accepted values, range boundaries, invalid types, and invalid decimal representations.
Current consumers being updated to use this helper:
DEVICE_METADATABGP ASN before caching it.sonic-cfggenfilter for BGP isolation templates.frrcfgd.How to verify it
Run:
PYTHONPATH=src/sonic-py-common pytest -q --noconftest src/sonic-py-common/tests/test_bgp.pyResult: 22 passed.
Which release branch to backport (provide reason below if selected)
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:
Tested branch
Test result
22 passedDescription for the changelog
Add a shared
sonic-py-commonhelper for validating BGP ASNs.Link to config_db schema for YANG module changes
N/A
A picture of a cute animal (not mandatory but encouraged)