Skip to content

[202511][cherry-pick] Fix show ip route json and show ipv6 route json when there is no IPv4 or IPv6 route#4363

Merged
vmittal-msft merged 1 commit intosonic-net:202511from
PriyanshTratiya:cherry-pick-4177-to-202511
Mar 17, 2026
Merged

[202511][cherry-pick] Fix show ip route json and show ipv6 route json when there is no IPv4 or IPv6 route#4363
vmittal-msft merged 1 commit intosonic-net:202511from
PriyanshTratiya:cherry-pick-4177-to-202511

Conversation

@PriyanshTratiya
Copy link

Manual Cherry Pick: #4177

dependent on: #4362

MSFT ADO: 36173805

What I did

I change the output format from "" to "{}" of show ip route json and show ipv6 route json when there is no IPv4 or IPv6 route.

The reason why I did this is because "" is not a valid json string. Any application (such as route_check.py) uses the output of this command as a json string will encounter a JSON parsing error when the output is empty.

How I did it

I restricted the early termination in bgp_common.show_routes when the combined route is empty to the non-json case only.

How to verify it

  • Run the new code on a device with IPv4/IPv6 only routes
  • Run "show ip route json" or "show ipv6 route json"
  • Verify that the command prints "{}"

Previous command output (if the output of a command-line utility has changed)

admin@vlab-01:~$ show ip route json
admin@vlab-01:~$

New command output (if the output of a command-line utility has changed)

admin@vlab-01:~$ show ip route json
{}
admin@vlab-01:~$

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PriyanshTratiya PriyanshTratiya changed the title Cherry pick 4177 to 202511 [202511][cherry-pick] Fix show ip route json and show ipv6 route json when there is no IPv4 or IPv6 route Mar 17, 2026
…IPv4 or IPv6 route (sonic-net#4177)

* remove early return

Signed-off-by: BYGX-wcr <[email protected]>

* add unit tests for IP4 only and IP6 only scenarios

Signed-off-by: BYGX-wcr <[email protected]>

* fix incorrect UT data format

Signed-off-by: BYGX-wcr <[email protected]>

* fix UT data

Signed-off-by: BYGX-wcr <[email protected]>

* add early return for non-json case

Signed-off-by: BYGX-wcr <[email protected]>

---------

Signed-off-by: BYGX-wcr <[email protected]>
Signed-off-by: Priyansh Tratiya <[email protected]>
@PriyanshTratiya PriyanshTratiya force-pushed the cherry-pick-4177-to-202511 branch from c214895 to ac0d5d4 Compare March 17, 2026 00:38
@mssonicbld
Copy link
Collaborator

/azp run

@PriyanshTratiya PriyanshTratiya marked this pull request as ready for review March 17, 2026 00:38
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vmittal-msft vmittal-msft merged commit fd161e5 into sonic-net:202511 Mar 17, 2026
9 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.

4 participants