Skip to content

[sonic-py-common] Add shared BGP ASN validation - #29447

Merged
qiluo-msft merged 2 commits into
sonic-net:masterfrom
ashutosh-agrawal:fix/bgp-common-validators
Sep 18, 2026
Merged

qiluo-msft merged 2 commits into
sonic-net:masterfrom
ashutosh-agrawal:fix/bgp-common-validators

Conversation

@ashutosh-agrawal

@ashutosh-agrawal ashutosh-agrawal commented Sep 9, 2026

Copy link
Copy Markdown
Member

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
  • Microsoft ADO (number only):

How I did it

Added a common validate_asn() helper to sonic-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:

How to verify it

Run:

PYTHONPATH=src/sonic-py-common pytest -q --noconftest src/sonic-py-common/tests/test_bgp.py

Result: 22 passed.

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

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

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:

Tested branch

  • master
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • 202608
  • N/A

Test result

  • master: 22 passed

Description for the changelog

Add a shared sonic-py-common helper 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)

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@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).

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@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).

@ashutosh-agrawal

Copy link
Copy Markdown
Member Author

/azpw run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ 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

Retrying failed(or canceled) stages in build 1221391:

✅Stage Test:

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

@qiluo-msft
qiluo-msft merged commit e0de879 into sonic-net:master Sep 18, 2026
31 checks passed
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