Skip to content

Commit 84cb00a

Browse files
authored
Change the default behavior of show ip bgp network (sonic-net#3447)
* show/bgp_frr_v4.py: change the default behavior of "show ip bgp network" - after change, show ip bgp network will have "all" as the default value of namespace option - after change, ip-address/ip-prefix is a required argument when executing show ip bgp network on a chassis supervisor * tests/remote_show_test.py update unit tests to comply with the new behaviors * tests/show_bgp_network_test.py: update a test vector to make it comply with the new default behavior * tests/bgp_commands_input/bgp_network_test_vector.py: update a test vector to comply with the new default behavior
1 parent 9b24421 commit 84cb00a

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

show/bgp_frr_v4.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
def bgp():
2121
"""Show IPv4 BGP (Border Gateway Protocol) information"""
2222
if device_info.is_supervisor():
23-
# if the device is a chassis, the command need to be executed by rexec
24-
click.echo("Since the current device is a chassis supervisor, " +
25-
"this command will be executed remotely on all linecards")
26-
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
27-
sys.exit(proc.returncode)
28-
pass
23+
subcommand = sys.argv[3]
24+
if subcommand not in "network":
25+
# the command will be executed directly by rexec if it is not "show ip bgp network"
26+
click.echo("Since the current device is a chassis supervisor, " +
27+
"this command will be executed remotely on all linecards")
28+
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
29+
sys.exit(proc.returncode)
2930

3031

3132
# 'summary' subcommand ("show ip bgp summary")
@@ -92,7 +93,7 @@ def neighbors(ipaddress, info_type, namespace):
9293
@bgp.command()
9394
@click.argument('ipaddress',
9495
metavar='[<ipv4-address>|<ipv4-prefix>]',
95-
required=False)
96+
required=True if device_info.is_supervisor() else False)
9697
@click.argument('info_type',
9798
metavar='[bestpath|json|longer-prefixes|multipath]',
9899
type=click.Choice(
@@ -103,19 +104,22 @@ def neighbors(ipaddress, info_type, namespace):
103104
'namespace',
104105
type=str,
105106
show_default=True,
106-
required=True if multi_asic.is_multi_asic is True else False,
107+
required=False,
107108
help='Namespace name or all',
108-
default=multi_asic.DEFAULT_NAMESPACE,
109+
default="all",
109110
callback=multi_asic_util.multi_asic_namespace_validation_callback)
110111
def network(ipaddress, info_type, namespace):
111112
"""Show IP (IPv4) BGP network"""
112113

114+
if device_info.is_supervisor():
115+
# the command will be executed by rexec
116+
click.echo("Since the current device is a chassis supervisor, " +
117+
"this command will be executed remotely on all linecards")
118+
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
119+
sys.exit(proc.returncode)
120+
113121
namespace = namespace.strip()
114122
if multi_asic.is_multi_asic():
115-
if namespace == multi_asic.DEFAULT_NAMESPACE:
116-
ctx = click.get_current_context()
117-
ctx.fail('-n/--namespace option required. provide namespace from list {}'
118-
.format(multi_asic.get_namespace_list()))
119123
if namespace != "all" and namespace not in multi_asic.get_namespace_list():
120124
ctx = click.get_current_context()
121125
ctx.fail('invalid namespace {}. provide namespace from list {}'

tests/bgp_commands_input/bgp_network_test_vector.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ def mock_show_bgp_network_multi_asic(param):
595595
'rc': 0,
596596
'rc_output': bgp_v6_network_longer_prefixes
597597
},
598-
'bgp_v4_network_multi_asic': {
598+
'bgp_v4_network_default_multi_asic': {
599599
'args': [],
600-
'rc': 2,
601-
'rc_err_msg': multi_asic_bgp_network_err
600+
'rc': 0,
601+
'rc_output': bgp_v4_network_all_asic
602602
},
603603
'bgp_v4_network_asic0': {
604604
'args': ['-nasic0'],

tests/remote_show_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def setup_class(cls):
3131
pass
3232

3333
@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True))
34+
@mock.patch("sys.argv", ["show", "ip", "bgp", "summary"])
3435
def test_show_ip_bgp_rexec(self, setup_bgp_commands):
3536
show = setup_bgp_commands
3637
runner = CliRunner()
@@ -44,6 +45,7 @@ def test_show_ip_bgp_rexec(self, setup_bgp_commands):
4445
assert MULTI_LC_REXEC_OUTPUT == result.output
4546

4647
@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True))
48+
@mock.patch("sys.argv", ["show", "ip", "bgp", "summary"])
4749
def test_show_ip_bgp_error_rexec(self, setup_bgp_commands):
4850
show = setup_bgp_commands
4951
runner = CliRunner()
@@ -55,3 +57,17 @@ def test_show_ip_bgp_error_rexec(self, setup_bgp_commands):
5557
subprocess.run = _old_subprocess_run
5658
assert result.exit_code == 1
5759
assert MULTI_LC_ERR_OUTPUT == result.output
60+
61+
@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True))
62+
@mock.patch("sys.argv", ["show", "ip", "bgp", "network", "10.0.0.0/24"])
63+
def test_show_ip_bgp_network_rexec(self, setup_bgp_commands):
64+
show = setup_bgp_commands
65+
runner = CliRunner()
66+
67+
_old_subprocess_run = subprocess.run
68+
subprocess.run = mock_rexec_command
69+
result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["network", "10.0.0.0/24"])
70+
print(result.output)
71+
subprocess.run = _old_subprocess_run
72+
assert result.exit_code == 0
73+
assert MULTI_LC_REXEC_OUTPUT == result.output

tests/show_bgp_network_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def setup_class(cls):
7878

7979
@pytest.mark.parametrize(
8080
'setup_multi_asic_bgp_instance, test_vector',
81-
[('bgp_v4_network', 'bgp_v4_network_multi_asic'),
81+
[('bgp_v4_network_all_asic', 'bgp_v4_network_default_multi_asic'),
8282
('bgp_v6_network', 'bgp_v6_network_multi_asic'),
8383
('bgp_v4_network_asic0', 'bgp_v4_network_asic0'),
8484
('bgp_v4_network_ip_address_asic0', 'bgp_v4_network_ip_address_asic0'),

0 commit comments

Comments
 (0)