Skip to content

Commit

Permalink
Merge pull request #88 from gechiang/202205
Browse files Browse the repository at this point in the history
Revert "Change the default behavior of show ip bgp network (#3447)"
  • Loading branch information
gechiang authored Aug 8, 2024
2 parents 2578ea4 + 764c587 commit 37c4179
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
30 changes: 13 additions & 17 deletions show/bgp_frr_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
def bgp():
"""Show IPv4 BGP (Border Gateway Protocol) information"""
if device_info.is_supervisor():
subcommand = sys.argv[3]
if subcommand not in "network":
# the command will be executed directly by rexec if it is not "show ip bgp network"
click.echo("Since the current device is a chassis supervisor, " +
"this command will be executed remotely on all linecards")
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
sys.exit(proc.returncode)
# if the device is a chassis, the command need to be executed by rexec
click.echo("Since the current device is a chassis supervisor, " +
"this command will be executed remotely on all linecards")
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
sys.exit(proc.returncode)
pass


# 'summary' subcommand ("show ip bgp summary")
Expand Down Expand Up @@ -93,7 +92,7 @@ def neighbors(ipaddress, info_type, namespace):
@bgp.command()
@click.argument('ipaddress',
metavar='[<ipv4-address>|<ipv4-prefix>]',
required=True if device_info.is_supervisor() else False)
required=False)
@click.argument('info_type',
metavar='[bestpath|json|longer-prefixes|multipath]',
type=click.Choice(
Expand All @@ -104,22 +103,19 @@ def neighbors(ipaddress, info_type, namespace):
'namespace',
type=str,
show_default=True,
required=False,
required=True if multi_asic.is_multi_asic is True else False,
help='Namespace name or all',
default="all",
default=multi_asic.DEFAULT_NAMESPACE,
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def network(ipaddress, info_type, namespace):
"""Show IP (IPv4) BGP network"""

if device_info.is_supervisor():
# the command will be executed by rexec
click.echo("Since the current device is a chassis supervisor, " +
"this command will be executed remotely on all linecards")
proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)])
sys.exit(proc.returncode)

namespace = namespace.strip()
if multi_asic.is_multi_asic():
if namespace == multi_asic.DEFAULT_NAMESPACE:
ctx = click.get_current_context()
ctx.fail('-n/--namespace option required. provide namespace from list {}'
.format(multi_asic.get_namespace_list()))
if namespace != "all" and namespace not in multi_asic.get_namespace_list():
ctx = click.get_current_context()
ctx.fail('invalid namespace {}. provide namespace from list {}'
Expand Down
6 changes: 3 additions & 3 deletions tests/bgp_commands_input/bgp_network_test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ def mock_show_bgp_network_multi_asic(param):
'rc': 0,
'rc_output': bgp_v6_network_longer_prefixes
},
'bgp_v4_network_default_multi_asic': {
'bgp_v4_network_multi_asic': {
'args': [],
'rc': 0,
'rc_output': bgp_v4_network_all_asic
'rc': 2,
'rc_err_msg': multi_asic_bgp_network_err
},
'bgp_v4_network_asic0': {
'args': ['-nasic0'],
Expand Down
16 changes: 0 additions & 16 deletions tests/remote_show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def setup_class(cls):
pass

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

@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True))
@mock.patch("sys.argv", ["show", "ip", "bgp", "summary"])
def test_show_ip_bgp_error_rexec(self, setup_bgp_commands):
show = setup_bgp_commands
runner = CliRunner()
Expand All @@ -57,17 +55,3 @@ def test_show_ip_bgp_error_rexec(self, setup_bgp_commands):
subprocess.run = _old_subprocess_run
assert result.exit_code == 1
assert MULTI_LC_ERR_OUTPUT == result.output

@mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True))
@mock.patch("sys.argv", ["show", "ip", "bgp", "network", "10.0.0.0/24"])
def test_show_ip_bgp_network_rexec(self, setup_bgp_commands):
show = setup_bgp_commands
runner = CliRunner()

_old_subprocess_run = subprocess.run
subprocess.run = mock_rexec_command
result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["network", "10.0.0.0/24"])
print(result.output)
subprocess.run = _old_subprocess_run
assert result.exit_code == 0
assert MULTI_LC_REXEC_OUTPUT == result.output
2 changes: 1 addition & 1 deletion tests/show_bgp_network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def setup_class(cls):

@pytest.mark.parametrize(
'setup_multi_asic_bgp_instance, test_vector',
[('bgp_v4_network_all_asic', 'bgp_v4_network_default_multi_asic'),
[('bgp_v4_network', 'bgp_v4_network_multi_asic'),
('bgp_v6_network', 'bgp_v6_network_multi_asic'),
('bgp_v4_network_asic0', 'bgp_v4_network_asic0'),
('bgp_v4_network_ip_address_asic0', 'bgp_v4_network_ip_address_asic0'),
Expand Down

0 comments on commit 37c4179

Please sign in to comment.