From 9579a8c368d45844d23aeac8fa39d50954d819e7 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 15:20:58 +0000 Subject: [PATCH 01/16] enable direct exec of show ip bgp on supervisor and enable -n all for show ip bgp network --- README.md | 7 +++++++ show/bgp_frr_v4.py | 36 +++++++++++++++++++++++++++++------- show/main.py | 6 +++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f63b0832a2..91146bc9d0 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ A convenient alternative is to let the SONiC build system configure a build envi ``` python3 setup.py bdist_wheel ``` +Note: This command by default will not update the wheel package in target/. To specify the destination location of wheel package, use "-d" option. #### To run unit tests @@ -73,6 +74,12 @@ python3 setup.py bdist_wheel python3 setup.py test ``` +#### To install the package on a SONiC machine +``` +sudo pip uninstall sonic-utilities +sudo pip install YOUR_WHEEL_PACKAGE +``` +Note: Don't use "--force-reinstall". ### sonic-utilities-data diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index 6343e8b7b2..4ff34f1164 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -1,11 +1,13 @@ import click +import sys -from sonic_py_common import multi_asic +from sonic_py_common import multi_asic, device_info from show.main import ip import utilities_common.bgp_util as bgp_util import utilities_common.cli as clicommon import utilities_common.constants as constants import utilities_common.multi_asic as multi_asic_util +import rcli.rexec ############################################################################### # @@ -17,6 +19,11 @@ @ip.group(cls=clicommon.AliasedGroup) def bgp(): """Show IPv4 BGP (Border Gateway Protocol) information""" + if device_info.is_supervisor(): + # 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") + rcli.rexec.cli("all", " ".join(sys.argv)) + sys.exit(0) pass @@ -102,10 +109,15 @@ def neighbors(ipaddress, info_type, namespace): def network(ipaddress, info_type, namespace): """Show IP (IPv4) BGP network""" - if multi_asic.is_multi_asic() and namespace not in multi_asic.get_namespace_list(): - ctx = click.get_current_context() - ctx.fail('-n/--namespace option required. provide namespace from list {}'\ - .format(multi_asic.get_namespace_list())) + 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 {}'\ + .format(multi_asic.get_namespace_list())) command = 'show ip bgp' if ipaddress is not None: @@ -125,5 +137,15 @@ def network(ipaddress, info_type, namespace): if info_type is not None: command += ' {}'.format(info_type) - output = bgp_util.run_bgp_show_command(command, namespace) - click.echo(output.rstrip('\n')) + if namespace == "all": + if multi_asic.is_multi_asic(): + for ns in multi_asic.get_namespace_list(): + click.echo("======== namespace {} ========".format(ns)) + output = bgp_util.run_bgp_show_command(command, ns) + click.echo(output.rstrip('\n')) + else: + output = bgp_util.run_bgp_show_command(command, "") + click.echo(output.rstrip('\n')) + else: + output = bgp_util.run_bgp_show_command(command, namespace) + click.echo(output.rstrip('\n')) diff --git a/show/main.py b/show/main.py index a3a72c70e7..31c4f94087 100755 --- a/show/main.py +++ b/show/main.py @@ -1187,7 +1187,11 @@ def protocol(verbose): ip.add_command(bgp) from .bgp_frr_v6 import bgp ipv6.add_command(bgp) - +elif device_info.is_chassis(): + from .bgp_frr_v4 import bgp + ip.add_command(bgp) + from .bgp_frr_v6 import bgp + ipv6.add_command(bgp) # # 'link-local-mode' subcommand ("show ipv6 link-local-mode") # From 9cf9ccf11b139245645036ac2d92b8384a499a22 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 15:21:32 +0000 Subject: [PATCH 02/16] add unit test for remote show ip bgp and show ip bgp -n all --- .../bgp_network_test_vector.py | 110 ++++++++++++++++++ tests/conftest.py | 6 + tests/remote_show_test.py | 66 +++++++++++ tests/show_bgp_network_test.py | 3 +- 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 tests/remote_show_test.py diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index da93e8e8e8..d4eb946eb3 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -311,6 +311,108 @@ Last update: Thu Apr 22 02:13:30 2021 """ +bgp_v4_network_all = \ +""" +======== namespace asic0 ======== +BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 +Default local pref 100, local AS 65100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +* i0.0.0.0/0 10.1.0.2 100 0 65200 6666 6667 i +* i 10.1.0.0 100 0 65200 6666 6667 i +*= 10.0.0.5 0 65200 6666 6667 i +*> 10.0.0.1 0 65200 6666 6667 i +* i8.0.0.0/32 10.1.0.2 0 100 0 i +* i 10.1.0.0 0 100 0 i +* 0.0.0.0 0 32768 ? +*> 0.0.0.0 0 32768 i +*=i8.0.0.1/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*=i8.0.0.2/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*=i8.0.0.3/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*>i8.0.0.4/32 10.1.0.0 0 100 0 i +*>i8.0.0.5/32 10.1.0.2 0 100 0 i +* i10.0.0.0/31 10.1.0.2 0 100 0 ? +* i 10.1.0.0 0 100 0 ? +*> 0.0.0.0 0 32768 ? +* i10.0.0.4/31 10.1.0.2 0 100 0 ? +* i 10.1.0.0 0 100 0 ? +*> 0.0.0.0 0 32768 ? +*=i10.0.0.8/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.12/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.32/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.34/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.36/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.38/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.40/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.42/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.44/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +======== namespace asic1 ======== +BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 +Default local pref 100, local AS 65100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +* i0.0.0.0/0 10.1.0.2 100 0 65200 6666 6667 i +* i 10.1.0.0 100 0 65200 6666 6667 i +*= 10.0.0.5 0 65200 6666 6667 i +*> 10.0.0.1 0 65200 6666 6667 i +* i8.0.0.0/32 10.1.0.2 0 100 0 i +* i 10.1.0.0 0 100 0 i +* 0.0.0.0 0 32768 ? +*> 0.0.0.0 0 32768 i +*=i8.0.0.1/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*=i8.0.0.2/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*=i8.0.0.3/32 10.1.0.2 0 100 0 i +*>i 10.1.0.0 0 100 0 i +*>i8.0.0.4/32 10.1.0.0 0 100 0 i +*>i8.0.0.5/32 10.1.0.2 0 100 0 i +* i10.0.0.0/31 10.1.0.2 0 100 0 ? +* i 10.1.0.0 0 100 0 ? +*> 0.0.0.0 0 32768 ? +* i10.0.0.4/31 10.1.0.2 0 100 0 ? +* i 10.1.0.0 0 100 0 ? +*> 0.0.0.0 0 32768 ? +*=i10.0.0.8/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.12/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.32/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.34/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.36/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.38/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.40/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.42/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +*=i10.0.0.44/31 10.1.0.2 0 100 0 ? +*>i 10.1.0.0 0 100 0 ? +""" + bgp_v6_network_asic0 = \ """ BGP table version is 12849, local router ID is 10.1.0.32, vrf id 0 @@ -429,6 +531,9 @@ def mock_show_bgp_network_multi_asic(param): return bgp_v6_network_ip_address_asic0 elif param == 'bgp_v6_network_bestpath_asic0': return bgp_v6_network_ip_address_asic0_bestpath + elif param == "bgp_v4_network_all": + # this is mocking the output of a single LC + return bgp_v4_network_asic0 else: return '' @@ -499,6 +604,11 @@ def mock_show_bgp_network_multi_asic(param): 'rc': 0, 'rc_output': bgp_v4_network_bestpath_asic0 }, + 'bgp_v4_network_all': { + 'args': ['-n all'], + 'rc': 0, + 'rc_output': bgp_v4_network_all + }, 'bgp_v6_network_multi_asic': { 'args': [], 'rc': 2, diff --git a/tests/conftest.py b/tests/conftest.py index 72b28515bb..73de86bdf6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -386,6 +386,12 @@ def mock_run_show_summ_bgp_command_no_ext_neigh_on_asic1( else: return "" + def mock_multi_asic_list(): + return ["asic0", "asic1"] + + # mock multi-asic list + multi_asic.get_namespace_list = mock_multi_asic_list + _old_run_bgp_command = bgp_util.run_bgp_command if request.param == 'ip_route_for_int_ip': bgp_util.run_bgp_command = mock_run_bgp_command_for_static diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py new file mode 100644 index 0000000000..162e15fd33 --- /dev/null +++ b/tests/remote_show_test.py @@ -0,0 +1,66 @@ +import importlib +import pytest +import mock +import paramiko +from io import BytesIO, StringIO +from click.testing import CliRunner + +from rcli import rexec + +def mock_exec_command(): + + mock_stdout = BytesIO(b"""hello world""") + mock_stderr = BytesIO() + return '', mock_stdout, None + +def mock_exec_error_cmd(): + mock_stdout = BytesIO() + mock_stderr = BytesIO(b"""Error""") + return '', mock_stdout, mock_stderr + +MULTI_LC_REXEC_OUTPUT = '''======== LINE-CARD0 output: ======== +hello world +======== LINE-CARD1 output: ======== +hello world +''' + +MULTI_LC_ERR_OUTPUT = '''======== LINE-CARD0 output: ======== +Error +======== LINE-CARD1 output: ======== +Error +''' + +class TestRexecBgpNetwork(object): + @classmethod + def setup_class(cls): + pass + + @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) + @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) + @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) + @mock.patch("rcli_utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) + @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) + @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_command())) + def test_show_ip_bgp_rexec(self, setup_bgp_commands): + show = setup_bgp_commands + runner = CliRunner() + + result = runner.invoke(show.commands["ip"].commands["bgp"]) + print(result.output) + assert result.exit_code == 0, result.output + assert MULTI_LC_REXEC_OUTPUT == result.output + + @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) + @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) + @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) + @mock.patch("rcli_utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) + @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) + @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_error_cmd())) + def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): + show = setup_bgp_commands + runner = CliRunner() + + result = runner.invoke(show.commands["ip"].commands["bgp"]) + print(result.output) + assert result.exit_code == 0, result.output + assert MULTI_LC_ERR_OUTPUT == result.output \ No newline at end of file diff --git a/tests/show_bgp_network_test.py b/tests/show_bgp_network_test.py index f610199538..f1aefab5af 100644 --- a/tests/show_bgp_network_test.py +++ b/tests/show_bgp_network_test.py @@ -84,7 +84,8 @@ def setup_class(cls): ('bgp_v4_network_bestpath_asic0', 'bgp_v4_network_bestpath_asic0'), ('bgp_v6_network_asic0', 'bgp_v6_network_asic0'), ('bgp_v6_network_ip_address_asic0', 'bgp_v6_network_ip_address_asic0'), - ('bgp_v6_network_bestpath_asic0', 'bgp_v6_network_bestpath_asic0')], + ('bgp_v6_network_bestpath_asic0', 'bgp_v6_network_bestpath_asic0'), + ('bgp_v4_network_all', 'bgp_v4_network_all')], indirect=['setup_multi_asic_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, setup_multi_asic_bgp_instance): From 729e715f0b8f349ba8c86b65d74d2dc51d56eb46 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 16:50:25 +0000 Subject: [PATCH 03/16] fix for pre-commit check --- show/bgp_frr_v4.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index 4ff34f1164..b9333aea34 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -21,7 +21,8 @@ def bgp(): """Show IPv4 BGP (Border Gateway Protocol) information""" if device_info.is_supervisor(): # 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") + click.echo("Since the current device is a chassis supervisor, " + + "this command will be executed remotely on all linecards") rcli.rexec.cli("all", " ".join(sys.argv)) sys.exit(0) pass @@ -112,11 +113,11 @@ def network(ipaddress, info_type, namespace): 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 {}'\ + 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 {}'\ + ctx.fail('invalid namespace. provide namespace from list {}' .format(multi_asic.get_namespace_list())) command = 'show ip bgp' From a15c3b3dd76add4ac842f32e45d6d73047276d14 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 17:43:55 +0000 Subject: [PATCH 04/16] fix test suites --- tests/bgp_commands_input/bgp_network_test_vector.py | 8 ++++---- tests/conftest.py | 3 ++- tests/remote_show_test.py | 4 ++-- tests/show_bgp_network_test.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index d4eb946eb3..76b8e2e9e4 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -311,7 +311,7 @@ Last update: Thu Apr 22 02:13:30 2021 """ -bgp_v4_network_all = \ +bgp_v4_network_all_asic = \ """ ======== namespace asic0 ======== BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 @@ -531,7 +531,7 @@ def mock_show_bgp_network_multi_asic(param): return bgp_v6_network_ip_address_asic0 elif param == 'bgp_v6_network_bestpath_asic0': return bgp_v6_network_ip_address_asic0_bestpath - elif param == "bgp_v4_network_all": + elif param == "bgp_v4_network_all_asic": # this is mocking the output of a single LC return bgp_v4_network_asic0 else: @@ -604,10 +604,10 @@ def mock_show_bgp_network_multi_asic(param): 'rc': 0, 'rc_output': bgp_v4_network_bestpath_asic0 }, - 'bgp_v4_network_all': { + 'bgp_v4_network_all_asic': { 'args': ['-n all'], 'rc': 0, - 'rc_output': bgp_v4_network_all + 'rc_output': bgp_v4_network_all_asic }, 'bgp_v6_network_multi_asic': { 'args': [], diff --git a/tests/conftest.py b/tests/conftest.py index 73de86bdf6..1eca132fd5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -390,7 +390,8 @@ def mock_multi_asic_list(): return ["asic0", "asic1"] # mock multi-asic list - multi_asic.get_namespace_list = mock_multi_asic_list + if request.param.endswith("all_asic"): + multi_asic.get_namespace_list = mock_multi_asic_list _old_run_bgp_command = bgp_util.run_bgp_command if request.param == 'ip_route_for_int_ip': diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 162e15fd33..0462d9e63e 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -38,7 +38,7 @@ def setup_class(cls): @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) - @mock.patch("rcli_utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) + @mock.patch("rcli.utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_command())) def test_show_ip_bgp_rexec(self, setup_bgp_commands): @@ -53,7 +53,7 @@ def test_show_ip_bgp_rexec(self, setup_bgp_commands): @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) - @mock.patch("rcli_utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) + @mock.patch("rcli.utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_error_cmd())) def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): diff --git a/tests/show_bgp_network_test.py b/tests/show_bgp_network_test.py index f1aefab5af..8c2d7fc9a2 100644 --- a/tests/show_bgp_network_test.py +++ b/tests/show_bgp_network_test.py @@ -85,7 +85,7 @@ def setup_class(cls): ('bgp_v6_network_asic0', 'bgp_v6_network_asic0'), ('bgp_v6_network_ip_address_asic0', 'bgp_v6_network_ip_address_asic0'), ('bgp_v6_network_bestpath_asic0', 'bgp_v6_network_bestpath_asic0'), - ('bgp_v4_network_all', 'bgp_v4_network_all')], + ('bgp_v4_network_all_asic', 'bgp_v4_network_all_asic')], indirect=['setup_multi_asic_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, setup_multi_asic_bgp_instance): From 146c6b453ec5d0912eb9d5d9fa644b8534d4c44b Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 19:14:04 +0000 Subject: [PATCH 05/16] fix for unit test suite --- show/bgp_frr_v4.py | 4 ++-- show/main.py | 2 +- tests/remote_show_test.py | 18 ++++++------------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index b9333aea34..9be1ad4d26 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -117,8 +117,8 @@ def network(ipaddress, info_type, namespace): .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 {}' - .format(multi_asic.get_namespace_list())) + ctx.fail('invalid namespace {}. provide namespace from list {}' + .format(namespace, multi_asic.get_namespace_list())) command = 'show ip bgp' if ipaddress is not None: diff --git a/show/main.py b/show/main.py index 31c4f94087..9efc778be2 100755 --- a/show/main.py +++ b/show/main.py @@ -1187,7 +1187,7 @@ def protocol(verbose): ip.add_command(bgp) from .bgp_frr_v6 import bgp ipv6.add_command(bgp) -elif device_info.is_chassis(): +elif device_info.is_supervisor(): from .bgp_frr_v4 import bgp ip.add_command(bgp) from .bgp_frr_v6 import bgp diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 0462d9e63e..adc10a80e7 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -1,16 +1,10 @@ -import importlib -import pytest import mock import paramiko -from io import BytesIO, StringIO +from io import BytesIO from click.testing import CliRunner -from rcli import rexec - def mock_exec_command(): - mock_stdout = BytesIO(b"""hello world""") - mock_stderr = BytesIO() return '', mock_stdout, None def mock_exec_error_cmd(): @@ -44,8 +38,8 @@ def setup_class(cls): def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - - result = runner.invoke(show.commands["ip"].commands["bgp"]) + + result = runner.invoke(show.cli.commands["ip"].commands["bgp"]) print(result.output) assert result.exit_code == 0, result.output assert MULTI_LC_REXEC_OUTPUT == result.output @@ -59,8 +53,8 @@ def test_show_ip_bgp_rexec(self, setup_bgp_commands): def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - - result = runner.invoke(show.commands["ip"].commands["bgp"]) + + result = runner.invoke(show.cli.commands["ip"].commands["bgp"]) print(result.output) assert result.exit_code == 0, result.output - assert MULTI_LC_ERR_OUTPUT == result.output \ No newline at end of file + assert MULTI_LC_ERR_OUTPUT == result.output From 2f101b546cf3e431a92ac8b7f19a48ea93802c7f Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 21:07:47 +0000 Subject: [PATCH 06/16] fix for test suites --- show/bgp_frr_v4.py | 1 + tests/bgp_commands_input/bgp_network_test_vector.py | 2 +- tests/conftest.py | 2 +- tests/remote_show_test.py | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index 9be1ad4d26..b58805bcff 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -110,6 +110,7 @@ def neighbors(ipaddress, info_type, namespace): def network(ipaddress, info_type, namespace): """Show IP (IPv4) BGP network""" + namespace = namespace.strip() if multi_asic.is_multi_asic(): if namespace == multi_asic.DEFAULT_NAMESPACE: ctx = click.get_current_context() diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index 76b8e2e9e4..5e59b9fdc8 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -605,7 +605,7 @@ def mock_show_bgp_network_multi_asic(param): 'rc_output': bgp_v4_network_bestpath_asic0 }, 'bgp_v4_network_all_asic': { - 'args': ['-n all'], + 'args': ['-nall'], 'rc': 0, 'rc_output': bgp_v4_network_all_asic }, diff --git a/tests/conftest.py b/tests/conftest.py index 1eca132fd5..5dd31d523a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -390,7 +390,7 @@ def mock_multi_asic_list(): return ["asic0", "asic1"] # mock multi-asic list - if request.param.endswith("all_asic"): + if request.param == "bgp_v4_network_all_asic": multi_asic.get_namespace_list = mock_multi_asic_list _old_run_bgp_command = bgp_util.run_bgp_command diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index adc10a80e7..e5dd7168db 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -39,7 +39,7 @@ def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - result = runner.invoke(show.cli.commands["ip"].commands["bgp"]) + result = runner.invoke(show.cli.commands["ip"].commands["bgp"].commands["summary"]) print(result.output) assert result.exit_code == 0, result.output assert MULTI_LC_REXEC_OUTPUT == result.output @@ -54,7 +54,7 @@ def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - result = runner.invoke(show.cli.commands["ip"].commands["bgp"]) + result = runner.invoke(show.cli.commands["ip"].commands["bgp"].commands["summary"]) print(result.output) assert result.exit_code == 0, result.output assert MULTI_LC_ERR_OUTPUT == result.output From 069e047e61737f98b5538062c40992069a2336fb Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 22:42:55 +0000 Subject: [PATCH 07/16] fix output mismatch for bgp_v4_network_all_asic test vector --- show/bgp_frr_v4.py | 2 +- tests/bgp_commands_input/bgp_network_test_vector.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index b58805bcff..84a0104070 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -142,7 +142,7 @@ def network(ipaddress, info_type, namespace): if namespace == "all": if multi_asic.is_multi_asic(): for ns in multi_asic.get_namespace_list(): - click.echo("======== namespace {} ========".format(ns)) + click.echo("\n======== namespace {} ========".format(ns)) output = bgp_util.run_bgp_show_command(command, ns) click.echo(output.rstrip('\n')) else: diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index 5e59b9fdc8..d471d4c95f 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -314,6 +314,7 @@ bgp_v4_network_all_asic = \ """ ======== namespace asic0 ======== + BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 Default local pref 100, local AS 65100 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, @@ -362,7 +363,9 @@ *>i 10.1.0.0 0 100 0 ? *=i10.0.0.44/31 10.1.0.2 0 100 0 ? *>i 10.1.0.0 0 100 0 ? + ======== namespace asic1 ======== + BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 Default local pref 100, local AS 65100 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, From da871c28aeaa0c336cedf772dd1e8adcc86fa3df Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 11 Jul 2024 23:51:05 +0000 Subject: [PATCH 08/16] fix remote show test --- tests/remote_show_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index e5dd7168db..7486a952eb 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -39,7 +39,7 @@ def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - result = runner.invoke(show.cli.commands["ip"].commands["bgp"].commands["summary"]) + result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) print(result.output) assert result.exit_code == 0, result.output assert MULTI_LC_REXEC_OUTPUT == result.output @@ -54,7 +54,7 @@ def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() - result = runner.invoke(show.cli.commands["ip"].commands["bgp"].commands["summary"]) + result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) print(result.output) assert result.exit_code == 0, result.output assert MULTI_LC_ERR_OUTPUT == result.output From 74cd5d9f64bea34df5220b3e18a5da71c0f83de8 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 00:58:27 +0000 Subject: [PATCH 09/16] fix rexec in show ip bgp and the corresponding tests --- show/bgp_frr_v4.py | 5 +++-- tests/remote_show_test.py | 41 +++++++++++++-------------------------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/show/bgp_frr_v4.py b/show/bgp_frr_v4.py index 84a0104070..30fb7ef88f 100644 --- a/show/bgp_frr_v4.py +++ b/show/bgp_frr_v4.py @@ -1,5 +1,6 @@ import click import sys +import subprocess from sonic_py_common import multi_asic, device_info from show.main import ip @@ -23,8 +24,8 @@ def bgp(): # 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") - rcli.rexec.cli("all", " ".join(sys.argv)) - sys.exit(0) + proc = subprocess.run(["rexec", "all"] + ["-c", " ".join(sys.argv)]) + sys.exit(proc.returncode) pass diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 7486a952eb..95190af0de 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -1,28 +1,21 @@ import mock -import paramiko +import subprocess from io import BytesIO from click.testing import CliRunner -def mock_exec_command(): +def mock_rexec_command(): mock_stdout = BytesIO(b"""hello world""") - return '', mock_stdout, None + print(mock_stdout.getvalue().decode()) + return subprocess.CompletedProcess(args=[], returncode=0, stdout=mock_stdout, stderr=BytesIO()) -def mock_exec_error_cmd(): - mock_stdout = BytesIO() +def mock_rexec_error_cmd(): mock_stderr = BytesIO(b"""Error""") - return '', mock_stdout, mock_stderr + print(mock_stderr.getvalue().decode()) + return subprocess.CompletedProcess(args=[], returncode=1, stdout=BytesIO(), stderr=mock_stderr) -MULTI_LC_REXEC_OUTPUT = '''======== LINE-CARD0 output: ======== -hello world -======== LINE-CARD1 output: ======== -hello world -''' +MULTI_LC_REXEC_OUTPUT = '''hello world''' -MULTI_LC_ERR_OUTPUT = '''======== LINE-CARD0 output: ======== -Error -======== LINE-CARD1 output: ======== -Error -''' +MULTI_LC_ERR_OUTPUT = '''Error''' class TestRexecBgpNetwork(object): @classmethod @@ -30,31 +23,23 @@ def setup_class(cls): pass @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) - @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) - @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) - @mock.patch("rcli.utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) - @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) - @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_command())) def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() + subprocess.run = mock_rexec_command result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) print(result.output) - assert result.exit_code == 0, result.output + assert result.exit_code == 0 assert MULTI_LC_REXEC_OUTPUT == result.output @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) - @mock.patch("os.getlogin", mock.MagicMock(return_value="admin")) - @mock.patch("rcli.utils.get_password", mock.MagicMock(return_value="dummy")) - @mock.patch("rcli.utils.get_all_linecards", mock.MagicMock(return_value=["LINE-CARD0", "LINE-CARD1"])) - @mock.patch.object(paramiko.SSHClient, 'connect', mock.MagicMock()) - @mock.patch.object(paramiko.SSHClient, 'exec_command', mock.MagicMock(return_value=mock_exec_error_cmd())) def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() + subprocess.run = mock_rexec_error_cmd result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) print(result.output) - assert result.exit_code == 0, result.output + assert result.exit_code == 1 assert MULTI_LC_ERR_OUTPUT == result.output From 3d816d8df7fb7714b6413c7beae73df5171a94c3 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 03:12:45 +0000 Subject: [PATCH 10/16] add mechanism to reset subprocess.run --- tests/remote_show_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 95190af0de..c30cc5f721 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -3,16 +3,19 @@ from io import BytesIO from click.testing import CliRunner + def mock_rexec_command(): mock_stdout = BytesIO(b"""hello world""") print(mock_stdout.getvalue().decode()) return subprocess.CompletedProcess(args=[], returncode=0, stdout=mock_stdout, stderr=BytesIO()) def mock_rexec_error_cmd(): + mock_stderr = BytesIO(b"""Error""") print(mock_stderr.getvalue().decode()) return subprocess.CompletedProcess(args=[], returncode=1, stdout=BytesIO(), stderr=mock_stderr) + MULTI_LC_REXEC_OUTPUT = '''hello world''' MULTI_LC_ERR_OUTPUT = '''Error''' @@ -27,9 +30,11 @@ def test_show_ip_bgp_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=["summary"]) print(result.output) + subprocess.run = _old_subprocess_run assert result.exit_code == 0 assert MULTI_LC_REXEC_OUTPUT == result.output @@ -38,8 +43,10 @@ def test_show_ip_bgp_error_rexec(self, setup_bgp_commands): show = setup_bgp_commands runner = CliRunner() + _old_subprocess_run = subprocess.run subprocess.run = mock_rexec_error_cmd result = runner.invoke(show.cli.commands["ip"].commands["bgp"], args=["summary"]) print(result.output) + subprocess.run = _old_subprocess_run assert result.exit_code == 1 assert MULTI_LC_ERR_OUTPUT == result.output From 71c17c06f0bfe8c9f6f494bebefd7d7f38111151 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 17:27:30 +0000 Subject: [PATCH 11/16] twist to try --- tests/remote_show_test.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index c30cc5f721..0f1ece7917 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -4,21 +4,22 @@ from click.testing import CliRunner -def mock_rexec_command(): +def mock_rexec_command(*args): mock_stdout = BytesIO(b"""hello world""") print(mock_stdout.getvalue().decode()) return subprocess.CompletedProcess(args=[], returncode=0, stdout=mock_stdout, stderr=BytesIO()) -def mock_rexec_error_cmd(): - +def mock_rexec_error_cmd(*args): mock_stderr = BytesIO(b"""Error""") print(mock_stderr.getvalue().decode()) return subprocess.CompletedProcess(args=[], returncode=1, stdout=BytesIO(), stderr=mock_stderr) -MULTI_LC_REXEC_OUTPUT = '''hello world''' +MULTI_LC_REXEC_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards +hello world''' -MULTI_LC_ERR_OUTPUT = '''Error''' +MULTI_LC_ERR_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards +Error''' class TestRexecBgpNetwork(object): @classmethod From 80b57fb42647eca53c0435ee2181183f50687865 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 18:02:41 +0000 Subject: [PATCH 12/16] twist expected outputs --- tests/remote_show_test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 0f1ece7917..c7733c7097 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -9,6 +9,7 @@ def mock_rexec_command(*args): print(mock_stdout.getvalue().decode()) return subprocess.CompletedProcess(args=[], returncode=0, stdout=mock_stdout, stderr=BytesIO()) + def mock_rexec_error_cmd(*args): mock_stderr = BytesIO(b"""Error""") print(mock_stderr.getvalue().decode()) @@ -16,10 +17,12 @@ def mock_rexec_error_cmd(*args): MULTI_LC_REXEC_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards -hello world''' +hello world +''' MULTI_LC_ERR_OUTPUT = '''Since the current device is a chassis supervisor, this command will be executed remotely on all linecards -Error''' +Error +''' class TestRexecBgpNetwork(object): @classmethod From 2f946f80730cefcaf70d80eb9963ea5bf485dc25 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 20:47:49 +0000 Subject: [PATCH 13/16] increase test coverage --- tests/bgp_commands_input/bgp_network_test_vector.py | 13 +++++++++++++ tests/remote_show_test.py | 7 +++++++ tests/show_bgp_network_test.py | 6 ++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index d471d4c95f..972891ca0d 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -227,6 +227,9 @@ multi_asic_bgp_network_err = \ """Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1']""" +multi_asic_bgp_network_err = \ +"""Error: invalid namespace asic_unknown. provide namespace from list ['asic0', 'asic1']""" + bgp_v4_network_asic0 = \ """ BGP table version is 11256, local router ID is 10.1.0.32, vrf id 0 @@ -562,6 +565,11 @@ def mock_show_bgp_network_multi_asic(param): 'rc': 1, 'rc_output': bgp_v4_network_longer_prefixes_error }, + 'bgp_v4_network_all_asic_on_single_asic': { + 'args': ['-nall'], + 'rc': 0, + 'rc_output': bgp_v4_network + }, 'bgp_v6_network': { 'args': [], 'rc': 0, @@ -612,6 +620,11 @@ def mock_show_bgp_network_multi_asic(param): 'rc': 0, 'rc_output': bgp_v4_network_all_asic }, + 'bgp_v4_network_asic_unknown': { + 'args': ['-nasic_unkown'], + 'rc': 2, + 'rc_err_msg': multi_asic_bgp_network_err + }, 'bgp_v6_network_multi_asic': { 'args': [], 'rc': 2, diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index c7733c7097..8564bb5f9d 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -29,6 +29,13 @@ class TestRexecBgpNetwork(object): def setup_class(cls): pass + @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) + @mock.patch("show.main.get_routing_stack", mock.MagicMock(return_value="")) + def test_bgp_setup_in_show_main(self): + import show.main as main + assert main.ip.commands["bgp"] is not None + assert main.ipv6.commands["bgp"] is not None + @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands diff --git a/tests/show_bgp_network_test.py b/tests/show_bgp_network_test.py index 8c2d7fc9a2..b92b732a09 100644 --- a/tests/show_bgp_network_test.py +++ b/tests/show_bgp_network_test.py @@ -57,7 +57,8 @@ def setup_class(cls): ('bgp_v4_network_bestpath', 'bgp_v4_network_bestpath'), ('bgp_v6_network_longer_prefixes', 'bgp_v6_network_longer_prefixes'), ('bgp_v4_network', 'bgp_v4_network_longer_prefixes_error'), - ('bgp_v4_network', 'bgp_v6_network_longer_prefixes_error')], + ('bgp_v4_network', 'bgp_v6_network_longer_prefixes_error') + ('bgp_v4_network', 'bgp_v4_network_all_asic_on_single_asic')], indirect=['setup_single_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, setup_single_bgp_instance): @@ -85,7 +86,8 @@ def setup_class(cls): ('bgp_v6_network_asic0', 'bgp_v6_network_asic0'), ('bgp_v6_network_ip_address_asic0', 'bgp_v6_network_ip_address_asic0'), ('bgp_v6_network_bestpath_asic0', 'bgp_v6_network_bestpath_asic0'), - ('bgp_v4_network_all_asic', 'bgp_v4_network_all_asic')], + ('bgp_v4_network_all_asic', 'bgp_v4_network_all_asic'), + ('bgp_v4_network', 'bgp_v4_network_asic_unknown'),], indirect=['setup_multi_asic_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, setup_multi_asic_bgp_instance): From c5a382910b9dce7cc4a2a2b5dcea749b1c0328be Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 21:02:26 +0000 Subject: [PATCH 14/16] small fix --- tests/show_bgp_network_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/show_bgp_network_test.py b/tests/show_bgp_network_test.py index b92b732a09..d3f24c8571 100644 --- a/tests/show_bgp_network_test.py +++ b/tests/show_bgp_network_test.py @@ -57,7 +57,7 @@ def setup_class(cls): ('bgp_v4_network_bestpath', 'bgp_v4_network_bestpath'), ('bgp_v6_network_longer_prefixes', 'bgp_v6_network_longer_prefixes'), ('bgp_v4_network', 'bgp_v4_network_longer_prefixes_error'), - ('bgp_v4_network', 'bgp_v6_network_longer_prefixes_error') + ('bgp_v4_network', 'bgp_v6_network_longer_prefixes_error'), ('bgp_v4_network', 'bgp_v4_network_all_asic_on_single_asic')], indirect=['setup_single_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, @@ -87,7 +87,7 @@ def setup_class(cls): ('bgp_v6_network_ip_address_asic0', 'bgp_v6_network_ip_address_asic0'), ('bgp_v6_network_bestpath_asic0', 'bgp_v6_network_bestpath_asic0'), ('bgp_v4_network_all_asic', 'bgp_v4_network_all_asic'), - ('bgp_v4_network', 'bgp_v4_network_asic_unknown'),], + ('bgp_v4_network', 'bgp_v4_network_asic_unknown')], indirect=['setup_multi_asic_bgp_instance']) def test_bgp_network(self, setup_bgp_commands, test_vector, setup_multi_asic_bgp_instance): From 7352a97a208274984e582643f22917b4f0f6fcbe Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 21:55:48 +0000 Subject: [PATCH 15/16] small fix --- tests/bgp_commands_input/bgp_network_test_vector.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bgp_commands_input/bgp_network_test_vector.py b/tests/bgp_commands_input/bgp_network_test_vector.py index 972891ca0d..f2ab8b06b8 100644 --- a/tests/bgp_commands_input/bgp_network_test_vector.py +++ b/tests/bgp_commands_input/bgp_network_test_vector.py @@ -227,7 +227,7 @@ multi_asic_bgp_network_err = \ """Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1']""" -multi_asic_bgp_network_err = \ +multi_asic_bgp_network_asic_unknown_err = \ """Error: invalid namespace asic_unknown. provide namespace from list ['asic0', 'asic1']""" bgp_v4_network_asic0 = \ @@ -621,9 +621,9 @@ def mock_show_bgp_network_multi_asic(param): 'rc_output': bgp_v4_network_all_asic }, 'bgp_v4_network_asic_unknown': { - 'args': ['-nasic_unkown'], + 'args': ['-nasic_unknown'], 'rc': 2, - 'rc_err_msg': multi_asic_bgp_network_err + 'rc_err_msg': multi_asic_bgp_network_asic_unknown_err }, 'bgp_v6_network_multi_asic': { 'args': [], From 17bf9d0fe33cbbedf22ff2d4dba15aaad944e7d6 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Fri, 12 Jul 2024 22:27:05 +0000 Subject: [PATCH 16/16] remove test for show.main --- tests/remote_show_test.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/remote_show_test.py b/tests/remote_show_test.py index 8564bb5f9d..c7733c7097 100644 --- a/tests/remote_show_test.py +++ b/tests/remote_show_test.py @@ -29,13 +29,6 @@ class TestRexecBgpNetwork(object): def setup_class(cls): pass - @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) - @mock.patch("show.main.get_routing_stack", mock.MagicMock(return_value="")) - def test_bgp_setup_in_show_main(self): - import show.main as main - assert main.ip.commands["bgp"] is not None - assert main.ipv6.commands["bgp"] is not None - @mock.patch("sonic_py_common.device_info.is_supervisor", mock.MagicMock(return_value=True)) def test_show_ip_bgp_rexec(self, setup_bgp_commands): show = setup_bgp_commands