Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def show_routes(args, namespace, display, verbose, ipver):
return

# Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace
if found_other_parms:
if found_other_parms and not found_json:
print("{}:".format(ns))
print(output)
continue
Expand All @@ -429,7 +429,7 @@ def show_routes(args, namespace, display, verbose, ipver):
else:
print_ip_routes(combined_route, filter_by_ip)
else:
new_string = json.dumps(combined_route,sort_keys=True, indent=4)
new_string = json.dumps(combined_route, sort_keys=True, indent=4)
print(new_string)

'''
Expand Down
28 changes: 28 additions & 0 deletions tests/ip_show_routes_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import pytest

Expand Down Expand Up @@ -141,3 +142,30 @@ def test_show_ipv6_route_err(
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_ipv6_route_err_expected_output + "\n"

@pytest.mark.parametrize('setup_single_bgp_instance',
['ip_route'], indirect=['setup_single_bgp_instance'])
def test_show_ip_route_bgp_json(
self,
setup_ip_route_commands,
setup_single_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["bgp", "json"])
print("{}".format(result.output))
assert result.exit_code == 0

try:
parsed = json.loads(result.output)
assert isinstance(parsed, dict)
except json.JSONDecodeError as e:
pytest.fail(f"Output is not valid JSON: {e}")

bgp_routes_found = False
for route_data in parsed.values():
if isinstance(route_data, list):
for entry in route_data:
if entry.get("protocol") == "bgp":
bgp_routes_found = True
break
assert bgp_routes_found, "BGP routes should be present in filtered output"
Loading