From fe5211007cb52c9e0a2530802a158b8a91d94be9 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:20:53 -0700 Subject: [PATCH 01/37] Update main.py --- show/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/show/main.py b/show/main.py index 0fce8037ea..97c425475e 100755 --- a/show/main.py +++ b/show/main.py @@ -19,6 +19,7 @@ from datetime import datetime import utilities_common.constants as constants from utilities_common.general import load_db_config +import utilities_common.bgp_util as bgp_util # mock the redis for unit test purposes # try: @@ -1387,8 +1388,12 @@ def ports(portname, verbose): @click.option('--verbose', is_flag=True, help="Enable verbose output") def bgp(verbose): """Show BGP running configuration""" - cmd = 'sudo {} -c "show running-config"'.format(constants.RVTYSH_COMMAND) - run_command(cmd, display_cmd=verbose) + ns_list = multi_asic.get_namespace_list() + output = "" + for ns in ns_list: + output += "------------Showing running config bgp on {}------------".format(ns) + output += bgp_utils.run_bgp_show_command("show runningconfiguration bgp") + output += "--------------------------------------------------------" # 'interfaces' subcommand ("show runningconfiguration interfaces") From 92816b050d36a5430f8c5fcfd13f428c22dc4800 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:27:29 -0700 Subject: [PATCH 02/37] remove import bgp_utils --- show/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index 97c425475e..7b5388b753 100755 --- a/show/main.py +++ b/show/main.py @@ -19,7 +19,6 @@ from datetime import datetime import utilities_common.constants as constants from utilities_common.general import load_db_config -import utilities_common.bgp_util as bgp_util # mock the redis for unit test purposes # try: @@ -1391,8 +1390,12 @@ def bgp(verbose): ns_list = multi_asic.get_namespace_list() output = "" for ns in ns_list: - output += "------------Showing running config bgp on {}------------".format(ns) - output += bgp_utils.run_bgp_show_command("show runningconfiguration bgp") + output += "------------Showing running config bgp on {}------------".format(ns) + ns_id = '' + if ns is not multi_asic.DEFAULT_NAMESPACE: + ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) + cmd = 'sudo {} {} -c "show runningconfiguration bgp"'.format(vtysh_shell_cmd, ns_id) + run_command(cmd, display_cmd=verbose) output += "--------------------------------------------------------" From 269b53e183de61ccbbb753501ceac43e1c838b42 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:36:39 -0700 Subject: [PATCH 03/37] Update main.py --- show/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index 7b5388b753..be84a105dd 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,8 +1385,13 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -def bgp(verbose): +@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all') + +def bgp(verbose, namespace): """Show BGP running configuration""" + 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())) ns_list = multi_asic.get_namespace_list() output = "" for ns in ns_list: From 5564920db9b61cec7cbd45d6bfdedbf20e5ddb31 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 14:40:28 -0700 Subject: [PATCH 04/37] fix indent and constants.RVTYSH_COMMAND --- show/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index be84a105dd..e9e513a849 100755 --- a/show/main.py +++ b/show/main.py @@ -1386,7 +1386,6 @@ def ports(portname, verbose): @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") @click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all') - def bgp(verbose, namespace): """Show BGP running configuration""" if multi_asic.is_multi_asic() and namespace not in multi_asic.get_namespace_list(): @@ -1398,8 +1397,8 @@ def bgp(verbose, namespace): output += "------------Showing running config bgp on {}------------".format(ns) ns_id = '' if ns is not multi_asic.DEFAULT_NAMESPACE: - ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) - cmd = 'sudo {} {} -c "show runningconfiguration bgp"'.format(vtysh_shell_cmd, ns_id) + ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) + cmd = 'sudo {} {} -c "show runningconfiguration bgp"'.format(constants.RVTYSH_COMMAND, ns_id) run_command(cmd, display_cmd=verbose) output += "--------------------------------------------------------" From 7e6b0b513610106697eb23b62603bc6d2a405f92 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 15:42:01 -0700 Subject: [PATCH 05/37] refine output, also rctysh doesnt take whole cmd have to use 'show run bgp' instead only --- show/main.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/show/main.py b/show/main.py index e9e513a849..9764eee1d6 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,22 +1385,25 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all') -def bgp(verbose, namespace): +@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, help='Namespace name or all') +def bgp(namespace, verbose): """Show BGP running configuration""" - 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())) - ns_list = multi_asic.get_namespace_list() output = "" - for ns in ns_list: - output += "------------Showing running config bgp on {}------------".format(ns) - ns_id = '' - if ns is not multi_asic.DEFAULT_NAMESPACE: - ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) - cmd = 'sudo {} {} -c "show runningconfiguration bgp"'.format(constants.RVTYSH_COMMAND, ns_id) - run_command(cmd, display_cmd=verbose) - output += "--------------------------------------------------------" + if namespace: + output += "\n------------Showing running config bgp on {}------------\n".format(namespace) + ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) + cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) + output += run_command(cmd, display_cmd = False, return_cmd=True) + else: + ns_list = multi_asic.get_namespace_list() + for ns in ns_list: + output += "\n------------Showing running config bgp on {}------------\n".format(ns) + ns_id = '' + if ns is not multi_asic.DEFAULT_NAMESPACE: + ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) + cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) + output += run_command(cmd, display_cmd = False, return_cmd=True) + print(output) # 'interfaces' subcommand ("show runningconfiguration interfaces") From 62eac7865284f8a9c6b83a1eac6a39045fc07299 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 17:45:11 -0700 Subject: [PATCH 06/37] support single-asic case --- show/main.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/show/main.py b/show/main.py index 9764eee1d6..c433d760d0 100755 --- a/show/main.py +++ b/show/main.py @@ -1390,19 +1390,21 @@ def bgp(namespace, verbose): """Show BGP running configuration""" output = "" if namespace: - output += "\n------------Showing running config bgp on {}------------\n".format(namespace) - ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) - cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) - output += run_command(cmd, display_cmd = False, return_cmd=True) - else: - ns_list = multi_asic.get_namespace_list() - for ns in ns_list: - output += "\n------------Showing running config bgp on {}------------\n".format(ns) - ns_id = '' - if ns is not multi_asic.DEFAULT_NAMESPACE: + if namespace == 'all': + ns_list = multi_asic.get_namespace_list() + for ns in ns_list: + output += "\n------------Showing running config bgp on {}------------\n".format(ns) ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) + cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) + output += run_command(cmd, display_cmd = False, return_cmd=True) + else: + output += "\n------------Showing running config bgp on {}------------\n".format(namespace) + ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) + else: + cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) + output += run_command(cmd, display_cmd = False, return_cmd=True) print(output) From 3646e2f5eb244eea1e3d5a007008fb456abf55d5 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 18:03:58 -0700 Subject: [PATCH 07/37] Update main.py --- show/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/show/main.py b/show/main.py index c433d760d0..b27217f742 100755 --- a/show/main.py +++ b/show/main.py @@ -1403,11 +1403,17 @@ def bgp(namespace, verbose): cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) else: - cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) - output += run_command(cmd, display_cmd = False, return_cmd=True) + try: + if multi_asic.is_multi_asic: + ctx = click.get_current_context() + ctx.fail("-n/--namespace option required. provide namespace from list {}, or give '-n all'".format(multi_asic.get_namespace_list())) + finally: + cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) + output += run_command(cmd, display_cmd = False, return_cmd=True) print(output) + # 'interfaces' subcommand ("show runningconfiguration interfaces") @runningconfiguration.command() @click.argument('interfacename', required=False) From 322aa45c34d0d6704c0e82d6821edfa369372f10 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 6 Oct 2022 18:20:16 -0700 Subject: [PATCH 08/37] Update main.py --- show/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index b27217f742..688b9a5401 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,7 +1385,9 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, help='Namespace name or all') +@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, + help='Namespace name or all', + callback=multi_asic_util.multi_asic_namespace_validation_callback) def bgp(namespace, verbose): """Show BGP running configuration""" output = "" From c6b27a9eebf818190813942f04166c9ff2fd3919 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 7 Oct 2022 10:36:55 -0700 Subject: [PATCH 09/37] fix bug multi_asic.is_multi_asic --- utilities_common/multi_asic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities_common/multi_asic.py b/utilities_common/multi_asic.py index 7e704befe7..75600d24be 100644 --- a/utilities_common/multi_asic.py +++ b/utilities_common/multi_asic.py @@ -112,7 +112,7 @@ def multi_asic_display_default_option(): ] def multi_asic_namespace_validation_callback(ctx, param, value): - if not multi_asic.is_multi_asic: + if not multi_asic.is_multi_asic(): click.echo("-n/--namespace is not available for single asic") ctx.abort() return value From a3a300fbde93ae3af0b552160210eb6c91cc50d5 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:17:30 -0700 Subject: [PATCH 10/37] remove 'callback' argument in option '-n' as it's not working properly --- show/main.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/show/main.py b/show/main.py index 688b9a5401..f460b0fea7 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,12 +1385,18 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, - help='Namespace name or all', - callback=multi_asic_util.multi_asic_namespace_validation_callback) +@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, help='Namespace name or all') def bgp(namespace, verbose): """Show BGP running configuration""" + if multi_asic.is_multi_asic() and (namespace not in multi_asic.get_namespace_list() or namespace != 'all'): + ctx = click.get_current_context() + ctx.fail("-n/--namespace option required. provide namespace from list {}, or give '-n all'".format(multi_asic.get_namespace_list())) + if not multi_asic.is_multi_asic() and namespace: + ctx = click.get_current_context() + ctx.fail("-n/--namespace is not available for single asic") + output = "" + #sigle-asic duts will not enter this condition, they cannot take '-n' option if namespace: if namespace == 'all': ns_list = multi_asic.get_namespace_list() @@ -1404,18 +1410,13 @@ def bgp(namespace, verbose): ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) + # multi-asic duts will not enter this condition, they have to be given '-n' option else: - try: - if multi_asic.is_multi_asic: - ctx = click.get_current_context() - ctx.fail("-n/--namespace option required. provide namespace from list {}, or give '-n all'".format(multi_asic.get_namespace_list())) - finally: - cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) - output += run_command(cmd, display_cmd = False, return_cmd=True) + cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) + output += run_command(cmd, display_cmd = False, return_cmd=True) print(output) - # 'interfaces' subcommand ("show runningconfiguration interfaces") @runningconfiguration.command() @click.argument('interfacename', required=False) From c2ad10a17ccfbeeea6f346161cc649b449333b0d Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:28:20 -0700 Subject: [PATCH 11/37] Update multi_asic.py --- utilities_common/multi_asic.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utilities_common/multi_asic.py b/utilities_common/multi_asic.py index 75600d24be..478623661a 100644 --- a/utilities_common/multi_asic.py +++ b/utilities_common/multi_asic.py @@ -112,7 +112,18 @@ def multi_asic_display_default_option(): ] def multi_asic_namespace_validation_callback(ctx, param, value): - if not multi_asic.is_multi_asic(): + # TODO: this condition has a bug: it should be either "multi_asic.is_multi_asic()" + # or "self.is_multi_asic", but changing it to correct version will lead to the + # following cli not working on single-asic: + # show ip(v6) bgp neighbors/network, show starm_control add/del + # e.g. + # admin@str2-7050cx3-acs-02:/usr$ show ip bgp neighbor -n asic0 + # -n/--namespace is not available for single asic + # Aborted! + # admin@str2-7050cx3-acs-02:/usr$ show ip bgp neighbor + # -n/--namespace is not available for single asic + # Aborted! + if not multi_asic.is_multi_asic: click.echo("-n/--namespace is not available for single asic") ctx.abort() return value From 3dd0302e42e244e0a75fba7cf3bef83d1ce40dd8 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 7 Oct 2022 11:33:28 -0700 Subject: [PATCH 12/37] refine help message --- show/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index f460b0fea7..2150f4efec 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,7 +1385,8 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, help='Namespace name or all') +@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, + help='Option needed for multi-asic only - provide namespace name or all') def bgp(namespace, verbose): """Show BGP running configuration""" if multi_asic.is_multi_asic() and (namespace not in multi_asic.get_namespace_list() or namespace != 'all'): From 0555e40aa7059d0503e59f73227132985fb4bd93 Mon Sep 17 00:00:00 2001 From: wenyiz2021 Date: Thu, 17 Nov 2022 21:55:48 +0000 Subject: [PATCH 13/37] ok --- tests/portstat_test.py | 32 ++ tests/show_run_bgp_test.py | 36 ++ .../show_run_bgp_test_vector.py | 512 ++++++++++++++++++ 3 files changed, 580 insertions(+) create mode 100644 tests/show_run_bgp_test.py create mode 100644 tests/show_run_commands_input/show_run_bgp_test_vector.py diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 2a70d0befc..2855cef58e 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -505,3 +505,35 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() + +multi_asic_intf_counters_reminder = """\ +Reminder: Please execute 'show interface counters -d all' to include internal links +""" + +class TestShowIntCountersMasic(object): + @classmethod + def setup_class(cls): + print("SETUP") + from .mock_tables import mock_multi_asic + importlib.reload(mock_multi_asic) + from .mock_tables import dbconnector + dbconnector.load_namespace_config() + + + def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): + runner = CliRunner() + result = runner.invoke(show.cli.commands["interface"].commands["counters"]) + print("result = {}".format(result.output)) + assert result.exit_code == 0 + assert multi_asic_intf_counters_reminder in result.output + + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ['UTILITIES_UNIT_TESTING'] = "0" + from .mock_tables import mock_single_asic + importlib.reload(mock_single_asic) + from .mock_tables import dbconnector + dbconnector.load_database_config() + diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py new file mode 100644 index 0000000000..c5db6f09f2 --- /dev/null +++ b/tests/show_run_bgp_test.py @@ -0,0 +1,36 @@ + +import os + +import pytest + +from click.testing import CliRunner + +from utilities_common import multi_asic +from utilities_common import constants + +from unittest.mock import patch + +from sonic_py_common import device_info +from .show_run_commands_input.show_run_bgp_test_vector import * + +class TestShowRunCommands(object): + @classmethod + def setup_class(cls): + print("SETUP") + from .mock_tables import dbconnector + + @pytest.mark.parametrize('setup_single_bgp_instance', 'test_vector', + [' '], indirect=['setup_single_bgp_instance']) + def test_show_run_bgp_single( + self, + setup_bgp_commands, + setup_single_bgp_instance): + show = setup_bgp_commands + runner = CliRunner() + exec_cmd = show.cli.commands["runningconfiguration"].commands["bgp"] + input = testData['test_vector'] + result = runner.invoke(exec_cmd, input['args']) + print("{}".format(result.output)) + import pdb; pdb.set_trace() + assert result.exit_code == 0 + assert result.output == show_run_bgp_sasic diff --git a/tests/show_run_commands_input/show_run_bgp_test_vector.py b/tests/show_run_commands_input/show_run_bgp_test_vector.py new file mode 100644 index 0000000000..1aa70ea13e --- /dev/null +++ b/tests/show_run_commands_input/show_run_bgp_test_vector.py @@ -0,0 +1,512 @@ +show_run_bgp_sasic = \ +""" +Building configuration... + +Current configuration: +! +frr version 8.2.2 +frr defaults traditional +hostname str2-7050cx3-acs-02 +log syslog informational +log facility local4 +agentx +no service integrated-vtysh-config +! +password zebra +enable password zebra +! +router bgp 65100 + bgp router-id 10.1.0.32 + bgp log-neighbor-changes + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + bgp graceful-restart restart-time 240 + bgp graceful-restart select-defer-time 45 + bgp graceful-restart + bgp graceful-restart preserve-fw-state + bgp bestpath as-path multipath-relax + neighbor BGPSLBPassive peer-group + neighbor BGPSLBPassive remote-as 65432 + neighbor BGPSLBPassive passive + neighbor BGPSLBPassive ebgp-multihop 255 + neighbor BGPSLBPassive update-source 10.1.0.32 + neighbor BGPVac peer-group + neighbor BGPVac remote-as 65432 + neighbor BGPVac passive + neighbor BGPVac ebgp-multihop 255 + neighbor BGPVac update-source 10.1.0.32 + neighbor PEER_V4 peer-group + neighbor PEER_V6 peer-group + neighbor 10.0.0.57 remote-as 64600 + neighbor 10.0.0.57 peer-group PEER_V4 + neighbor 10.0.0.57 description ARISTA01T1 + neighbor 10.0.0.57 timers 3 10 + neighbor 10.0.0.57 timers connect 10 + neighbor 10.0.0.59 remote-as 64600 + neighbor 10.0.0.59 peer-group PEER_V4 + neighbor 10.0.0.59 description ARISTA02T1 + neighbor 10.0.0.59 timers 3 10 + neighbor 10.0.0.59 timers connect 10 + neighbor 10.0.0.61 remote-as 64600 + neighbor 10.0.0.61 peer-group PEER_V4 + neighbor 10.0.0.61 description ARISTA03T1 + neighbor 10.0.0.61 timers 3 10 + neighbor 10.0.0.61 timers connect 10 + neighbor 10.0.0.63 remote-as 64600 + neighbor 10.0.0.63 peer-group PEER_V4 + neighbor 10.0.0.63 description ARISTA04T1 + neighbor 10.0.0.63 timers 3 10 + neighbor 10.0.0.63 timers connect 10 + neighbor fc00::72 remote-as 64600 + neighbor fc00::72 peer-group PEER_V6 + neighbor fc00::72 description ARISTA01T1 + neighbor fc00::72 timers 3 10 + neighbor fc00::72 timers connect 10 + neighbor fc00::76 remote-as 64600 + neighbor fc00::76 peer-group PEER_V6 + neighbor fc00::76 description ARISTA02T1 + neighbor fc00::76 timers 3 10 + neighbor fc00::76 timers connect 10 + neighbor fc00::7a remote-as 64600 + neighbor fc00::7a peer-group PEER_V6 + neighbor fc00::7a description ARISTA03T1 + neighbor fc00::7a timers 3 10 + neighbor fc00::7a timers connect 10 + neighbor fc00::7e remote-as 64600 + neighbor fc00::7e peer-group PEER_V6 + neighbor fc00::7e description ARISTA04T1 + neighbor fc00::7e timers 3 10 + neighbor fc00::7e timers connect 10 + bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive + bgp listen range 192.168.0.0/21 peer-group BGPVac + ! + address-family ipv4 unicast + network 10.1.0.32/32 + network 192.168.0.0/21 + neighbor BGPSLBPassive activate + neighbor BGPSLBPassive soft-reconfiguration inbound + neighbor BGPSLBPassive route-map FROM_BGP_SPEAKER in + neighbor BGPSLBPassive route-map TO_BGP_SPEAKER out + neighbor BGPVac activate + neighbor BGPVac soft-reconfiguration inbound + neighbor BGPVac route-map FROM_BGP_SPEAKER in + neighbor BGPVac route-map TO_BGP_SPEAKER out + neighbor PEER_V4 soft-reconfiguration inbound + neighbor PEER_V4 allowas-in 1 + neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in + neighbor PEER_V4 route-map TO_BGP_PEER_V4 out + neighbor 10.0.0.57 activate + neighbor 10.0.0.59 activate + neighbor 10.0.0.61 activate + neighbor 10.0.0.63 activate + maximum-paths 64 + exit-address-family + ! + address-family ipv6 unicast + network fc00:1::/64 + network fc02:1000::/64 + neighbor BGPSLBPassive activate + neighbor BGPVac activate + neighbor PEER_V6 soft-reconfiguration inbound + neighbor PEER_V6 allowas-in 1 + neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in + neighbor PEER_V6 route-map TO_BGP_PEER_V6 out + neighbor fc00::72 activate + neighbor fc00::76 activate + neighbor fc00::7a activate + neighbor fc00::7e activate + maximum-paths 64 + exit-address-family +exit +! +ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/21 +! +ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc02:1000::/64 +! +bgp community-list standard allow_list_default_community seq 5 permit no-export +bgp community-list standard allow_list_default_community seq 10 permit 5060:12345 +! +route-map ALLOW_LIST_DEPLOYMENT_ID_0_V4 permit 65535 + set community 5060:12345 additive +exit +! +route-map ALLOW_LIST_DEPLOYMENT_ID_0_V6 permit 65535 + set community 5060:12345 additive +exit +! +route-map FROM_BGP_PEER_V4 permit 10 + call ALLOW_LIST_DEPLOYMENT_ID_0_V4 + on-match next +exit +! +route-map FROM_BGP_PEER_V4 permit 11 + match community allow_list_default_community +exit +! +route-map FROM_BGP_PEER_V4 permit 100 +exit +! +route-map FROM_BGP_PEER_V6 permit 1 + on-match next + set ipv6 next-hop prefer-global +exit +! +route-map FROM_BGP_PEER_V6 permit 10 + call ALLOW_LIST_DEPLOYMENT_ID_0_V6 + on-match next +exit +! +route-map FROM_BGP_PEER_V6 permit 11 + match community allow_list_default_community +exit +! +route-map FROM_BGP_PEER_V6 permit 100 +exit +! +route-map TO_BGP_PEER_V4 permit 100 +exit +! +route-map TO_BGP_PEER_V6 permit 100 +exit +! +route-map FROM_BGP_SPEAKER permit 10 +exit +! +route-map TO_BGP_SPEAKER deny 1 +exit +! +route-map RM_SET_SRC permit 10 +exit +! +route-map RM_SET_SRC6 permit 10 +exit +! +end +""" + + +show_run_bgp_invalid_sasic_with_namespace = \ +""" +-n/--namespace is not available for single asic +""" + + +show_run_bgp_masic_asic0 = \ +""" +------------Showing running config bgp on asic0------------ +Building configuration... + +Current configuration: +! +frr version 7.2.1-sonic +frr defaults traditional +hostname svcstr-n3164-acs-1 +log syslog informational +log facility local4 +no service integrated-vtysh-config +! +enable password zebra +password zebra +! +router bgp 65100 + bgp router-id 10.1.0.32 + bgp log-neighbor-changes + no bgp default ipv4-unicast + bgp graceful-restart restart-time 240 + bgp graceful-restart + bgp graceful-restart preserve-fw-state + bgp bestpath as-path multipath-relax + neighbor INTERNAL_PEER_V4 peer-group + neighbor INTERNAL_PEER_V6 peer-group + neighbor TIER2_V4 peer-group + neighbor TIER2_V6 peer-group + neighbor 10.1.0.0 remote-as 65100 + neighbor 10.1.0.0 peer-group INTERNAL_PEER_V4 + neighbor 10.1.0.0 description ASIC4 + neighbor 10.1.0.0 timers 3 10 + neighbor 10.1.0.0 timers connect 10 + neighbor 10.1.0.2 remote-as 65100 + neighbor 10.1.0.2 peer-group INTERNAL_PEER_V4 + neighbor 10.1.0.2 description ASIC5 + neighbor 10.1.0.2 timers 3 10 + neighbor 10.1.0.2 timers connect 10 + neighbor 2603:10e2:400:1::1 remote-as 65100 + neighbor 2603:10e2:400:1::1 peer-group INTERNAL_PEER_V6 + neighbor 2603:10e2:400:1::1 description ASIC4 + neighbor 2603:10e2:400:1::1 timers 3 10 + neighbor 2603:10e2:400:1::1 timers connect 10 + neighbor 2603:10e2:400:1::5 remote-as 65100 + neighbor 2603:10e2:400:1::5 peer-group INTERNAL_PEER_V6 + neighbor 2603:10e2:400:1::5 description ASIC5 + neighbor 2603:10e2:400:1::5 timers 3 10 + neighbor 2603:10e2:400:1::5 timers connect 10 + neighbor 10.0.0.1 remote-as 65200 + neighbor 10.0.0.1 peer-group TIER2_V4 + neighbor 10.0.0.1 description ARISTA01T2 + neighbor 10.0.0.5 remote-as 65200 + neighbor 10.0.0.5 peer-group TIER2_V4 + neighbor 10.0.0.5 description ARISTA03T2 + neighbor fc00::2 remote-as 65200 + neighbor fc00::2 peer-group TIER2_V6 + neighbor fc00::2 description ARISTA01T2 + neighbor fc00::6 remote-as 65200 + neighbor fc00::6 peer-group TIER2_V6 + neighbor fc00::6 description ARISTA03T2 + ! + address-family ipv4 unicast + network 8.0.0.0/32 route-map HIDE_INTERNAL + network 10.1.0.32/32 + redistribute connected route-map HIDE_INTERNAL + neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out + neighbor TIER2_V4 activate + neighbor TIER2_V4 soft-reconfiguration inbound + neighbor TIER2_V4 maximum-prefix 12000 90 warning-only + neighbor TIER2_V4 route-map FROM_TIER2_V4 in + neighbor TIER2_V4 route-map TO_TIER2_V4 out + neighbor 10.1.0.0 activate + neighbor 10.1.0.0 allowas-in 1 + neighbor 10.1.0.2 activate + neighbor 10.1.0.2 allowas-in 1 + maximum-paths 64 + exit-address-family + ! + address-family ipv6 unicast + network 2603:10e2:400::/128 route-map HIDE_INTERNAL + network fc00:1::/64 + redistribute connected route-map HIDE_INTERNAL + neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out + neighbor TIER2_V6 activate + neighbor TIER2_V6 soft-reconfiguration inbound + neighbor TIER2_V6 maximum-prefix 8000 90 warning-only + neighbor TIER2_V6 route-map FROM_TIER2_V6 in + neighbor TIER2_V6 route-map TO_TIER2_V6 out + neighbor 2603:10e2:400:1::1 activate + neighbor 2603:10e2:400:1::1 allowas-in 1 + neighbor 2603:10e2:400:1::5 activate + neighbor 2603:10e2:400:1::5 allowas-in 1 + maximum-paths 64 + exit-address-family +! +ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 +! +ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 +! +bgp community-list standard UPSTREAM_PREFIX permit 8075:54000 +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 + on-match next + set ipv6 next-hop prefer-global +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map FROM_TIER2_V4 permit 100 + set community 8075:54000 additive +! +route-map FROM_TIER2_V6 permit 100 + on-match next + set ipv6 next-hop prefer-global +! +route-map FROM_TIER2_V6 permit 200 + set community 8075:54000 additive +! +route-map HIDE_INTERNAL permit 10 + on-match next + set community no-export +! +route-map HIDE_INTERNAL permit 20 + set community 8075:9306 additive +! +route-map RM_SET_SRC permit 10 +! +route-map RM_SET_SRC6 permit 10 +! +route-map TO_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map TO_TIER2_V4 deny 100 + match community UPSTREAM_PREFIX +! +route-map TO_TIER2_V4 permit 10000 +! +route-map TO_TIER2_V6 deny 100 + match community UPSTREAM_PREFIX +! +route-map TO_TIER2_V6 permit 10000 +! +line vty +! +end +""" + +show_run_bgp_masic_asic1 = \ +""" +------------Showing running config bgp on asic1------------ +Building configuration... + +Current configuration: +! +frr version 7.2.1-sonic +frr defaults traditional +hostname svcstr-n3164-acs-1 +log syslog informational +log facility local4 +no service integrated-vtysh-config +! +enable password zebra +password zebra +! +router bgp 65100 + bgp router-id 10.1.0.32 + bgp log-neighbor-changes + no bgp default ipv4-unicast + bgp graceful-restart restart-time 240 + bgp graceful-restart + bgp graceful-restart preserve-fw-state + bgp bestpath as-path multipath-relax + neighbor INTERNAL_PEER_V4 peer-group + neighbor INTERNAL_PEER_V6 peer-group + neighbor TIER2_V4 peer-group + neighbor TIER2_V6 peer-group + neighbor 10.1.0.4 remote-as 65100 + neighbor 10.1.0.4 peer-group INTERNAL_PEER_V4 + neighbor 10.1.0.4 description ASIC4 + neighbor 10.1.0.4 timers 3 10 + neighbor 10.1.0.4 timers connect 10 + neighbor 10.1.0.6 remote-as 65100 + neighbor 10.1.0.6 peer-group INTERNAL_PEER_V4 + neighbor 10.1.0.6 description ASIC5 + neighbor 10.1.0.6 timers 3 10 + neighbor 10.1.0.6 timers connect 10 + neighbor 2603:10e2:400:1::9 remote-as 65100 + neighbor 2603:10e2:400:1::9 peer-group INTERNAL_PEER_V6 + neighbor 2603:10e2:400:1::9 description ASIC4 + neighbor 2603:10e2:400:1::9 timers 3 10 + neighbor 2603:10e2:400:1::9 timers connect 10 + neighbor 2603:10e2:400:1::d remote-as 65100 + neighbor 2603:10e2:400:1::d peer-group INTERNAL_PEER_V6 + neighbor 2603:10e2:400:1::d description ASIC5 + neighbor 2603:10e2:400:1::d timers 3 10 + neighbor 2603:10e2:400:1::d timers connect 10 + neighbor 10.0.0.9 remote-as 65200 + neighbor 10.0.0.9 peer-group TIER2_V4 + neighbor 10.0.0.9 description ARISTA05T2 + neighbor 10.0.0.13 remote-as 65200 + neighbor 10.0.0.13 peer-group TIER2_V4 + neighbor 10.0.0.13 description ARISTA07T2 + neighbor fc00::a remote-as 65200 + neighbor fc00::a peer-group TIER2_V6 + neighbor fc00::a description ARISTA05T2 + neighbor fc00::e remote-as 65200 + neighbor fc00::e peer-group TIER2_V6 + neighbor fc00::e description ARISTA07T2 + ! + address-family ipv4 unicast + network 8.0.0.1/32 route-map HIDE_INTERNAL + network 10.1.0.32/32 + redistribute connected route-map HIDE_INTERNAL + neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in + neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out + neighbor TIER2_V4 activate + neighbor TIER2_V4 soft-reconfiguration inbound + neighbor TIER2_V4 maximum-prefix 12000 90 warning-only + neighbor TIER2_V4 route-map FROM_TIER2_V4 in + neighbor TIER2_V4 route-map TO_TIER2_V4 out + neighbor 10.1.0.4 activate + neighbor 10.1.0.4 allowas-in 1 + neighbor 10.1.0.6 activate + neighbor 10.1.0.6 allowas-in 1 + maximum-paths 64 + exit-address-family + ! + address-family ipv6 unicast + network 2603:10e2:400::1/128 route-map HIDE_INTERNAL + network fc00:1::/64 + redistribute connected route-map HIDE_INTERNAL + neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound + neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in + neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out + neighbor TIER2_V6 activate + neighbor TIER2_V6 soft-reconfiguration inbound + neighbor TIER2_V6 maximum-prefix 8000 90 warning-only + neighbor TIER2_V6 route-map FROM_TIER2_V6 in + neighbor TIER2_V6 route-map TO_TIER2_V6 out + neighbor 2603:10e2:400:1::9 activate + neighbor 2603:10e2:400:1::9 allowas-in 1 + neighbor 2603:10e2:400:1::d activate + neighbor 2603:10e2:400:1::d allowas-in 1 + maximum-paths 64 + exit-address-family +! +ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 +! +ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 +! +bgp community-list standard UPSTREAM_PREFIX permit 8075:54000 +! +route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 + on-match next + set ipv6 next-hop prefer-global +! +route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map FROM_TIER2_V4 permit 100 + set community 8075:54000 additive +! +route-map FROM_TIER2_V6 permit 100 + on-match next + set ipv6 next-hop prefer-global +! +route-map FROM_TIER2_V6 permit 200 + set community 8075:54000 additive +! +route-map HIDE_INTERNAL permit 10 + on-match next + set community no-export +! +route-map HIDE_INTERNAL permit 20 + set community 8075:9306 additive +! +route-map RM_SET_SRC permit 10 +! +route-map RM_SET_SRC6 permit 10 +! +route-map TO_BGP_INTERNAL_PEER_V4 permit 100 +! +route-map TO_BGP_INTERNAL_PEER_V6 permit 100 +! +route-map TO_TIER2_V4 deny 100 + match community UPSTREAM_PREFIX +! +route-map TO_TIER2_V4 permit 10000 +! +route-map TO_TIER2_V6 deny 100 + match community UPSTREAM_PREFIX +! +route-map TO_TIER2_V6 permit 10000 +! +line vty +! +end +""" + +show_run_bgp_invalid_masic_no_namespace = \ +""" +Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1', 'asic2', 'asic3', 'asic4', 'asic5'], or give '-n all' +""" + +show_run_bgp_invalid_masic_wrong_namespace = \ +""" +Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1', 'asic2', 'asic3', 'asic4', 'asic5'], or give '-n all' +""" From fe1685598499825a0c7767aa001666519b7aee1a Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:13:37 -0800 Subject: [PATCH 14/37] remove unrelated change for show int counters --- tests/portstat_test.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 2855cef58e..2a70d0befc 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -505,35 +505,3 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() - -multi_asic_intf_counters_reminder = """\ -Reminder: Please execute 'show interface counters -d all' to include internal links -""" - -class TestShowIntCountersMasic(object): - @classmethod - def setup_class(cls): - print("SETUP") - from .mock_tables import mock_multi_asic - importlib.reload(mock_multi_asic) - from .mock_tables import dbconnector - dbconnector.load_namespace_config() - - - def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): - runner = CliRunner() - result = runner.invoke(show.cli.commands["interface"].commands["counters"]) - print("result = {}".format(result.output)) - assert result.exit_code == 0 - assert multi_asic_intf_counters_reminder in result.output - - - @classmethod - def teardown_class(cls): - print("TEARDOWN") - os.environ['UTILITIES_UNIT_TESTING'] = "0" - from .mock_tables import mock_single_asic - importlib.reload(mock_single_asic) - from .mock_tables import dbconnector - dbconnector.load_database_config() - From cffba1cf6c8f89bd90effbc9a1c85530a56fb31e Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:48:27 -0800 Subject: [PATCH 15/37] multi-asic can run without -n and show all --- show/main.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/show/main.py b/show/main.py index 2150f4efec..46d0123b06 100755 --- a/show/main.py +++ b/show/main.py @@ -1385,21 +1385,28 @@ def ports(portname, verbose): # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") -@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, - help='Option needed for multi-asic only - provide namespace name or all') +@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False, + help='Option needed for multi-asic only: provide namespace name', + callback=multi_asic_util.multi_asic_namespace_validation_callback) def bgp(namespace, verbose): - """Show BGP running configuration""" - if multi_asic.is_multi_asic() and (namespace not in multi_asic.get_namespace_list() or namespace != 'all'): - ctx = click.get_current_context() - ctx.fail("-n/--namespace option required. provide namespace from list {}, or give '-n all'".format(multi_asic.get_namespace_list())) + """ + Show BGP running configuration + Note: + multi-asic can run 'show run bgp' and show from all asics, or 'show run bgp -n ' + single-asic only run 'show run bgp', '-n' is not available + """ + + if multi_asic.is_multi_asic(): + if namespace and namespace not in multi_asic.get_namespace_list(): + ctx = click.get_current_context() + ctx.fail("invalid value for -n/--namespace option. provide namespace from list {}".format(multi_asic.get_namespace_list())) if not multi_asic.is_multi_asic() and namespace: - ctx = click.get_current_context() + ctx = click.get_current_context() ctx.fail("-n/--namespace is not available for single asic") output = "" - #sigle-asic duts will not enter this condition, they cannot take '-n' option - if namespace: - if namespace == 'all': + if multi_asic.is_multi_asic(): + if not namespace: ns_list = multi_asic.get_namespace_list() for ns in ns_list: output += "\n------------Showing running config bgp on {}------------\n".format(ns) @@ -1411,7 +1418,6 @@ def bgp(namespace, verbose): ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) - # multi-asic duts will not enter this condition, they have to be given '-n' option else: cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) output += run_command(cmd, display_cmd = False, return_cmd=True) From f900faac3d9108e6276217271ffec7069f51d0f8 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:49:37 -0800 Subject: [PATCH 16/37] fix typo --- utilities_common/multi_asic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities_common/multi_asic.py b/utilities_common/multi_asic.py index 478623661a..f01bb83d31 100644 --- a/utilities_common/multi_asic.py +++ b/utilities_common/multi_asic.py @@ -115,7 +115,7 @@ def multi_asic_namespace_validation_callback(ctx, param, value): # TODO: this condition has a bug: it should be either "multi_asic.is_multi_asic()" # or "self.is_multi_asic", but changing it to correct version will lead to the # following cli not working on single-asic: - # show ip(v6) bgp neighbors/network, show starm_control add/del + # show ip(v6) bgp neighbors/network, show storm_control add/del # e.g. # admin@str2-7050cx3-acs-02:/usr$ show ip bgp neighbor -n asic0 # -n/--namespace is not available for single asic From 377740d63ecec999028f8ce418e05c5cecb14654 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:50:11 -0800 Subject: [PATCH 17/37] remove debug breakpoint --- tests/show_run_bgp_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index c5db6f09f2..77f7b701e9 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -1,4 +1,3 @@ - import os import pytest @@ -31,6 +30,5 @@ def test_show_run_bgp_single( input = testData['test_vector'] result = runner.invoke(exec_cmd, input['args']) print("{}".format(result.output)) - import pdb; pdb.set_trace() assert result.exit_code == 0 assert result.output == show_run_bgp_sasic From e6a166c071cf319ff4887f54be8c44e98afc89e4 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 14:57:53 -0800 Subject: [PATCH 18/37] unit test --- tests/show_run_bgp_test.py | 97 ++++++++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 9 deletions(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 77f7b701e9..8ead934a1e 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -10,24 +10,103 @@ from unittest.mock import patch from sonic_py_common import device_info -from .show_run_commands_input.show_run_bgp_test_vector import * +import show.main as show + + +show_run_bgp_sasic = \ +""" +Building configuration... +Current configuration: +! +frr version 8.2.2 +frr defaults traditional +hostname str2-7050cx3-acs-02 +log syslog informational +log facility local4 +agentx +no service integrated-vtysh-config +! +password zebra +enable password zebra +! +router bgp 65100 + bgp router-id 10.1.0.32 + bgp log-neighbor-changes + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + bgp graceful-restart restart-time 240 + bgp graceful-restart select-defer-time 45 + bgp graceful-restart + bgp graceful-restart preserve-fw-state + bgp bestpath as-path multipath-relax + neighbor BGPSLBPassive peer-group + neighbor BGPSLBPassive remote-as 65432 + neighbor BGPSLBPassive passive + neighbor BGPSLBPassive ebgp-multihop 255 + neighbor BGPSLBPassive update-source 10.1.0.32 + neighbor BGPVac peer-group + neighbor BGPVac remote-as 65432 + neighbor BGPVac passive + neighbor BGPVac ebgp-multihop 255 + neighbor BGPVac update-source 10.1.0.32 + neighbor PEER_V4 peer-group + neighbor PEER_V6 peer-group + neighbor 10.0.0.57 remote-as 64600 + neighbor 10.0.0.57 peer-group PEER_V4 + neighbor 10.0.0.57 description ARISTA01T1 + neighbor 10.0.0.57 timers 3 10 + neighbor 10.0.0.57 timers connect 10 + neighbor 10.0.0.59 remote-as 64600 + neighbor 10.0.0.59 peer-group PEER_V4 + neighbor 10.0.0.59 description ARISTA02T1 + neighbor 10.0.0.59 timers 3 10 + neighbor 10.0.0.59 timers connect 10 + neighbor 10.0.0.61 remote-as 64600 + neighbor 10.0.0.61 peer-group PEER_V4 + neighbor 10.0.0.61 description ARISTA03T1 + neighbor 10.0.0.61 timers 3 10 + neighbor 10.0.0.61 timers connect 10 + neighbor 10.0.0.63 remote-as 64600 + neighbor 10.0.0.63 peer-group PEER_V4 + neighbor 10.0.0.63 description ARISTA04T1 + neighbor 10.0.0.63 timers 3 10 + neighbor 10.0.0.63 timers connect 10 + neighbor fc00::72 remote-as 64600 + neighbor fc00::72 peer-group PEER_V6 + neighbor fc00::72 description ARISTA01T1 + neighbor fc00::72 timers 3 10 + neighbor fc00::72 timers connect 10 + neighbor fc00::76 remote-as 64600 + neighbor fc00::76 peer-group PEER_V6 + neighbor fc00::76 description ARISTA02T1 + neighbor fc00::76 timers 3 10 + neighbor fc00::76 timers connect 10 + neighbor fc00::7a remote-as 64600 + neighbor fc00::7a peer-group PEER_V6 + neighbor fc00::7a description ARISTA03T1 + neighbor fc00::7a timers 3 10 + neighbor fc00::7a timers connect 10 + neighbor fc00::7e remote-as 64600 + neighbor fc00::7e peer-group PEER_V6 + neighbor fc00::7e description ARISTA04T1 + neighbor fc00::7e timers 3 10 + neighbor fc00::7e timers connect 10 + bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive + bgp listen range 192.168.0.0/21 peer-group BGPVac +""" class TestShowRunCommands(object): @classmethod def setup_class(cls): print("SETUP") + from .mock_tables import mock_single_asic + importlib.reload(mock_single_asic) from .mock_tables import dbconnector + dbconnector.load_namespace_config() - @pytest.mark.parametrize('setup_single_bgp_instance', 'test_vector', - [' '], indirect=['setup_single_bgp_instance']) - def test_show_run_bgp_single( - self, - setup_bgp_commands, - setup_single_bgp_instance): - show = setup_bgp_commands + def test_show_run_bgp_single(self): runner = CliRunner() exec_cmd = show.cli.commands["runningconfiguration"].commands["bgp"] - input = testData['test_vector'] result = runner.invoke(exec_cmd, input['args']) print("{}".format(result.output)) assert result.exit_code == 0 From ef4dda8c65fa3f54c9e72a21ce4f72f91dffe1de Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:45:31 -0800 Subject: [PATCH 19/37] add import importlib --- tests/show_run_bgp_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 8ead934a1e..bc7fa73218 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -1,7 +1,6 @@ import os - import pytest - +import importlib from click.testing import CliRunner from utilities_common import multi_asic From 74e86745487665666dd83f8a1e6546a90445f00f Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 30 Nov 2022 17:06:02 -0800 Subject: [PATCH 20/37] Update show_run_bgp_test.py --- tests/show_run_bgp_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index bc7fa73218..722c82cee7 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -106,7 +106,7 @@ def setup_class(cls): def test_show_run_bgp_single(self): runner = CliRunner() exec_cmd = show.cli.commands["runningconfiguration"].commands["bgp"] - result = runner.invoke(exec_cmd, input['args']) + result = runner.invoke(exec_cmd) print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_run_bgp_sasic From 2f11eac3e09e6f00f3aef6bfab561ff000b6c961 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 1 Dec 2022 10:40:03 -0800 Subject: [PATCH 21/37] add teardown --- tests/show_run_bgp_test.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 722c82cee7..4cf3a2ec87 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -110,3 +110,12 @@ def test_show_run_bgp_single(self): print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_run_bgp_sasic + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ['UTILITIES_UNIT_TESTING'] = "0" + from .mock_tables import mock_single_asic + importlib.reload(mock_single_asic) + from .mock_tables import dbconnector + dbconnector.load_database_config() From d16e67c8862e6ea92c239c157bf89abfab840c68 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:10:44 -0800 Subject: [PATCH 22/37] Update show_run_bgp_test.py --- tests/show_run_bgp_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 4cf3a2ec87..a7b54c5c83 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -105,8 +105,7 @@ def setup_class(cls): def test_show_run_bgp_single(self): runner = CliRunner() - exec_cmd = show.cli.commands["runningconfiguration"].commands["bgp"] - result = runner.invoke(exec_cmd) + result = runner.invoke(show.cli.commands["runningconfiguration"].commands["bgp"], []) print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_run_bgp_sasic From 66a51f2582477ae28738a3701530119b41698ead Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:46:07 -0800 Subject: [PATCH 23/37] Update main.py --- show/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index 46d0123b06..e591229fee 100755 --- a/show/main.py +++ b/show/main.py @@ -1411,15 +1411,15 @@ def bgp(namespace, verbose): for ns in ns_list: output += "\n------------Showing running config bgp on {}------------\n".format(ns) ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) - cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) + cmd = 'sudo {} {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) else: output += "\n------------Showing running config bgp on {}------------\n".format(namespace) ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) - cmd = 'sudo {} {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND, ns_id) + cmd = 'sudo {} {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND, ns_id) output += run_command(cmd, display_cmd = False, return_cmd=True) else: - cmd = 'sudo {} -c "show run bgp"'.format(constants.RVTYSH_COMMAND) + cmd = 'sudo {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND) output += run_command(cmd, display_cmd = False, return_cmd=True) print(output) From 823fe8782efe55ddc409bebbbe67abc771846a97 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:50:20 -0800 Subject: [PATCH 24/37] reuse bgp_util.run_bgp_command --- show/main.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/show/main.py b/show/main.py index e591229fee..11aedb8187 100755 --- a/show/main.py +++ b/show/main.py @@ -1382,6 +1382,7 @@ def ports(portname, verbose): run_command(cmd, display_cmd=verbose) + # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") @@ -1405,22 +1406,18 @@ def bgp(namespace, verbose): ctx.fail("-n/--namespace is not available for single asic") output = "" + import utilities_common.bgp_util as bgp_util if multi_asic.is_multi_asic(): if not namespace: ns_list = multi_asic.get_namespace_list() for ns in ns_list: output += "\n------------Showing running config bgp on {}------------\n".format(ns) - ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(ns)) - cmd = 'sudo {} {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND, ns_id) - output += run_command(cmd, display_cmd = False, return_cmd=True) + output += bgp_util.run_bgp_command(cmd, ns) else: output += "\n------------Showing running config bgp on {}------------\n".format(namespace) - ns_id = " -n {} ".format(multi_asic.get_asic_id_from_name(namespace)) - cmd = 'sudo {} {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND, ns_id) - output += run_command(cmd, display_cmd = False, return_cmd=True) + output += bgp_util.run_bgp_command(cmd, namespace) else: - cmd = 'sudo {} -c "show running-config bgp"'.format(constants.RVTYSH_COMMAND) - output += run_command(cmd, display_cmd = False, return_cmd=True) + output += bgp_util.run_bgp_command(cmd) print(output) From c1c7357c794968d8356e5808115968d284ef61dc Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:50:45 -0800 Subject: [PATCH 25/37] remove separate vector file --- .../show_run_bgp_test_vector.py | 512 ------------------ 1 file changed, 512 deletions(-) delete mode 100644 tests/show_run_commands_input/show_run_bgp_test_vector.py diff --git a/tests/show_run_commands_input/show_run_bgp_test_vector.py b/tests/show_run_commands_input/show_run_bgp_test_vector.py deleted file mode 100644 index 1aa70ea13e..0000000000 --- a/tests/show_run_commands_input/show_run_bgp_test_vector.py +++ /dev/null @@ -1,512 +0,0 @@ -show_run_bgp_sasic = \ -""" -Building configuration... - -Current configuration: -! -frr version 8.2.2 -frr defaults traditional -hostname str2-7050cx3-acs-02 -log syslog informational -log facility local4 -agentx -no service integrated-vtysh-config -! -password zebra -enable password zebra -! -router bgp 65100 - bgp router-id 10.1.0.32 - bgp log-neighbor-changes - no bgp ebgp-requires-policy - no bgp default ipv4-unicast - bgp graceful-restart restart-time 240 - bgp graceful-restart select-defer-time 45 - bgp graceful-restart - bgp graceful-restart preserve-fw-state - bgp bestpath as-path multipath-relax - neighbor BGPSLBPassive peer-group - neighbor BGPSLBPassive remote-as 65432 - neighbor BGPSLBPassive passive - neighbor BGPSLBPassive ebgp-multihop 255 - neighbor BGPSLBPassive update-source 10.1.0.32 - neighbor BGPVac peer-group - neighbor BGPVac remote-as 65432 - neighbor BGPVac passive - neighbor BGPVac ebgp-multihop 255 - neighbor BGPVac update-source 10.1.0.32 - neighbor PEER_V4 peer-group - neighbor PEER_V6 peer-group - neighbor 10.0.0.57 remote-as 64600 - neighbor 10.0.0.57 peer-group PEER_V4 - neighbor 10.0.0.57 description ARISTA01T1 - neighbor 10.0.0.57 timers 3 10 - neighbor 10.0.0.57 timers connect 10 - neighbor 10.0.0.59 remote-as 64600 - neighbor 10.0.0.59 peer-group PEER_V4 - neighbor 10.0.0.59 description ARISTA02T1 - neighbor 10.0.0.59 timers 3 10 - neighbor 10.0.0.59 timers connect 10 - neighbor 10.0.0.61 remote-as 64600 - neighbor 10.0.0.61 peer-group PEER_V4 - neighbor 10.0.0.61 description ARISTA03T1 - neighbor 10.0.0.61 timers 3 10 - neighbor 10.0.0.61 timers connect 10 - neighbor 10.0.0.63 remote-as 64600 - neighbor 10.0.0.63 peer-group PEER_V4 - neighbor 10.0.0.63 description ARISTA04T1 - neighbor 10.0.0.63 timers 3 10 - neighbor 10.0.0.63 timers connect 10 - neighbor fc00::72 remote-as 64600 - neighbor fc00::72 peer-group PEER_V6 - neighbor fc00::72 description ARISTA01T1 - neighbor fc00::72 timers 3 10 - neighbor fc00::72 timers connect 10 - neighbor fc00::76 remote-as 64600 - neighbor fc00::76 peer-group PEER_V6 - neighbor fc00::76 description ARISTA02T1 - neighbor fc00::76 timers 3 10 - neighbor fc00::76 timers connect 10 - neighbor fc00::7a remote-as 64600 - neighbor fc00::7a peer-group PEER_V6 - neighbor fc00::7a description ARISTA03T1 - neighbor fc00::7a timers 3 10 - neighbor fc00::7a timers connect 10 - neighbor fc00::7e remote-as 64600 - neighbor fc00::7e peer-group PEER_V6 - neighbor fc00::7e description ARISTA04T1 - neighbor fc00::7e timers 3 10 - neighbor fc00::7e timers connect 10 - bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive - bgp listen range 192.168.0.0/21 peer-group BGPVac - ! - address-family ipv4 unicast - network 10.1.0.32/32 - network 192.168.0.0/21 - neighbor BGPSLBPassive activate - neighbor BGPSLBPassive soft-reconfiguration inbound - neighbor BGPSLBPassive route-map FROM_BGP_SPEAKER in - neighbor BGPSLBPassive route-map TO_BGP_SPEAKER out - neighbor BGPVac activate - neighbor BGPVac soft-reconfiguration inbound - neighbor BGPVac route-map FROM_BGP_SPEAKER in - neighbor BGPVac route-map TO_BGP_SPEAKER out - neighbor PEER_V4 soft-reconfiguration inbound - neighbor PEER_V4 allowas-in 1 - neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in - neighbor PEER_V4 route-map TO_BGP_PEER_V4 out - neighbor 10.0.0.57 activate - neighbor 10.0.0.59 activate - neighbor 10.0.0.61 activate - neighbor 10.0.0.63 activate - maximum-paths 64 - exit-address-family - ! - address-family ipv6 unicast - network fc00:1::/64 - network fc02:1000::/64 - neighbor BGPSLBPassive activate - neighbor BGPVac activate - neighbor PEER_V6 soft-reconfiguration inbound - neighbor PEER_V6 allowas-in 1 - neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in - neighbor PEER_V6 route-map TO_BGP_PEER_V6 out - neighbor fc00::72 activate - neighbor fc00::76 activate - neighbor fc00::7a activate - neighbor fc00::7e activate - maximum-paths 64 - exit-address-family -exit -! -ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/21 -! -ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc02:1000::/64 -! -bgp community-list standard allow_list_default_community seq 5 permit no-export -bgp community-list standard allow_list_default_community seq 10 permit 5060:12345 -! -route-map ALLOW_LIST_DEPLOYMENT_ID_0_V4 permit 65535 - set community 5060:12345 additive -exit -! -route-map ALLOW_LIST_DEPLOYMENT_ID_0_V6 permit 65535 - set community 5060:12345 additive -exit -! -route-map FROM_BGP_PEER_V4 permit 10 - call ALLOW_LIST_DEPLOYMENT_ID_0_V4 - on-match next -exit -! -route-map FROM_BGP_PEER_V4 permit 11 - match community allow_list_default_community -exit -! -route-map FROM_BGP_PEER_V4 permit 100 -exit -! -route-map FROM_BGP_PEER_V6 permit 1 - on-match next - set ipv6 next-hop prefer-global -exit -! -route-map FROM_BGP_PEER_V6 permit 10 - call ALLOW_LIST_DEPLOYMENT_ID_0_V6 - on-match next -exit -! -route-map FROM_BGP_PEER_V6 permit 11 - match community allow_list_default_community -exit -! -route-map FROM_BGP_PEER_V6 permit 100 -exit -! -route-map TO_BGP_PEER_V4 permit 100 -exit -! -route-map TO_BGP_PEER_V6 permit 100 -exit -! -route-map FROM_BGP_SPEAKER permit 10 -exit -! -route-map TO_BGP_SPEAKER deny 1 -exit -! -route-map RM_SET_SRC permit 10 -exit -! -route-map RM_SET_SRC6 permit 10 -exit -! -end -""" - - -show_run_bgp_invalid_sasic_with_namespace = \ -""" --n/--namespace is not available for single asic -""" - - -show_run_bgp_masic_asic0 = \ -""" -------------Showing running config bgp on asic0------------ -Building configuration... - -Current configuration: -! -frr version 7.2.1-sonic -frr defaults traditional -hostname svcstr-n3164-acs-1 -log syslog informational -log facility local4 -no service integrated-vtysh-config -! -enable password zebra -password zebra -! -router bgp 65100 - bgp router-id 10.1.0.32 - bgp log-neighbor-changes - no bgp default ipv4-unicast - bgp graceful-restart restart-time 240 - bgp graceful-restart - bgp graceful-restart preserve-fw-state - bgp bestpath as-path multipath-relax - neighbor INTERNAL_PEER_V4 peer-group - neighbor INTERNAL_PEER_V6 peer-group - neighbor TIER2_V4 peer-group - neighbor TIER2_V6 peer-group - neighbor 10.1.0.0 remote-as 65100 - neighbor 10.1.0.0 peer-group INTERNAL_PEER_V4 - neighbor 10.1.0.0 description ASIC4 - neighbor 10.1.0.0 timers 3 10 - neighbor 10.1.0.0 timers connect 10 - neighbor 10.1.0.2 remote-as 65100 - neighbor 10.1.0.2 peer-group INTERNAL_PEER_V4 - neighbor 10.1.0.2 description ASIC5 - neighbor 10.1.0.2 timers 3 10 - neighbor 10.1.0.2 timers connect 10 - neighbor 2603:10e2:400:1::1 remote-as 65100 - neighbor 2603:10e2:400:1::1 peer-group INTERNAL_PEER_V6 - neighbor 2603:10e2:400:1::1 description ASIC4 - neighbor 2603:10e2:400:1::1 timers 3 10 - neighbor 2603:10e2:400:1::1 timers connect 10 - neighbor 2603:10e2:400:1::5 remote-as 65100 - neighbor 2603:10e2:400:1::5 peer-group INTERNAL_PEER_V6 - neighbor 2603:10e2:400:1::5 description ASIC5 - neighbor 2603:10e2:400:1::5 timers 3 10 - neighbor 2603:10e2:400:1::5 timers connect 10 - neighbor 10.0.0.1 remote-as 65200 - neighbor 10.0.0.1 peer-group TIER2_V4 - neighbor 10.0.0.1 description ARISTA01T2 - neighbor 10.0.0.5 remote-as 65200 - neighbor 10.0.0.5 peer-group TIER2_V4 - neighbor 10.0.0.5 description ARISTA03T2 - neighbor fc00::2 remote-as 65200 - neighbor fc00::2 peer-group TIER2_V6 - neighbor fc00::2 description ARISTA01T2 - neighbor fc00::6 remote-as 65200 - neighbor fc00::6 peer-group TIER2_V6 - neighbor fc00::6 description ARISTA03T2 - ! - address-family ipv4 unicast - network 8.0.0.0/32 route-map HIDE_INTERNAL - network 10.1.0.32/32 - redistribute connected route-map HIDE_INTERNAL - neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound - neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in - neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out - neighbor TIER2_V4 activate - neighbor TIER2_V4 soft-reconfiguration inbound - neighbor TIER2_V4 maximum-prefix 12000 90 warning-only - neighbor TIER2_V4 route-map FROM_TIER2_V4 in - neighbor TIER2_V4 route-map TO_TIER2_V4 out - neighbor 10.1.0.0 activate - neighbor 10.1.0.0 allowas-in 1 - neighbor 10.1.0.2 activate - neighbor 10.1.0.2 allowas-in 1 - maximum-paths 64 - exit-address-family - ! - address-family ipv6 unicast - network 2603:10e2:400::/128 route-map HIDE_INTERNAL - network fc00:1::/64 - redistribute connected route-map HIDE_INTERNAL - neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound - neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in - neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out - neighbor TIER2_V6 activate - neighbor TIER2_V6 soft-reconfiguration inbound - neighbor TIER2_V6 maximum-prefix 8000 90 warning-only - neighbor TIER2_V6 route-map FROM_TIER2_V6 in - neighbor TIER2_V6 route-map TO_TIER2_V6 out - neighbor 2603:10e2:400:1::1 activate - neighbor 2603:10e2:400:1::1 allowas-in 1 - neighbor 2603:10e2:400:1::5 activate - neighbor 2603:10e2:400:1::5 allowas-in 1 - maximum-paths 64 - exit-address-family -! -ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 -! -ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 -! -bgp community-list standard UPSTREAM_PREFIX permit 8075:54000 -! -route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 -! -route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 - on-match next - set ipv6 next-hop prefer-global -! -route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 -! -route-map FROM_TIER2_V4 permit 100 - set community 8075:54000 additive -! -route-map FROM_TIER2_V6 permit 100 - on-match next - set ipv6 next-hop prefer-global -! -route-map FROM_TIER2_V6 permit 200 - set community 8075:54000 additive -! -route-map HIDE_INTERNAL permit 10 - on-match next - set community no-export -! -route-map HIDE_INTERNAL permit 20 - set community 8075:9306 additive -! -route-map RM_SET_SRC permit 10 -! -route-map RM_SET_SRC6 permit 10 -! -route-map TO_BGP_INTERNAL_PEER_V4 permit 100 -! -route-map TO_BGP_INTERNAL_PEER_V6 permit 100 -! -route-map TO_TIER2_V4 deny 100 - match community UPSTREAM_PREFIX -! -route-map TO_TIER2_V4 permit 10000 -! -route-map TO_TIER2_V6 deny 100 - match community UPSTREAM_PREFIX -! -route-map TO_TIER2_V6 permit 10000 -! -line vty -! -end -""" - -show_run_bgp_masic_asic1 = \ -""" -------------Showing running config bgp on asic1------------ -Building configuration... - -Current configuration: -! -frr version 7.2.1-sonic -frr defaults traditional -hostname svcstr-n3164-acs-1 -log syslog informational -log facility local4 -no service integrated-vtysh-config -! -enable password zebra -password zebra -! -router bgp 65100 - bgp router-id 10.1.0.32 - bgp log-neighbor-changes - no bgp default ipv4-unicast - bgp graceful-restart restart-time 240 - bgp graceful-restart - bgp graceful-restart preserve-fw-state - bgp bestpath as-path multipath-relax - neighbor INTERNAL_PEER_V4 peer-group - neighbor INTERNAL_PEER_V6 peer-group - neighbor TIER2_V4 peer-group - neighbor TIER2_V6 peer-group - neighbor 10.1.0.4 remote-as 65100 - neighbor 10.1.0.4 peer-group INTERNAL_PEER_V4 - neighbor 10.1.0.4 description ASIC4 - neighbor 10.1.0.4 timers 3 10 - neighbor 10.1.0.4 timers connect 10 - neighbor 10.1.0.6 remote-as 65100 - neighbor 10.1.0.6 peer-group INTERNAL_PEER_V4 - neighbor 10.1.0.6 description ASIC5 - neighbor 10.1.0.6 timers 3 10 - neighbor 10.1.0.6 timers connect 10 - neighbor 2603:10e2:400:1::9 remote-as 65100 - neighbor 2603:10e2:400:1::9 peer-group INTERNAL_PEER_V6 - neighbor 2603:10e2:400:1::9 description ASIC4 - neighbor 2603:10e2:400:1::9 timers 3 10 - neighbor 2603:10e2:400:1::9 timers connect 10 - neighbor 2603:10e2:400:1::d remote-as 65100 - neighbor 2603:10e2:400:1::d peer-group INTERNAL_PEER_V6 - neighbor 2603:10e2:400:1::d description ASIC5 - neighbor 2603:10e2:400:1::d timers 3 10 - neighbor 2603:10e2:400:1::d timers connect 10 - neighbor 10.0.0.9 remote-as 65200 - neighbor 10.0.0.9 peer-group TIER2_V4 - neighbor 10.0.0.9 description ARISTA05T2 - neighbor 10.0.0.13 remote-as 65200 - neighbor 10.0.0.13 peer-group TIER2_V4 - neighbor 10.0.0.13 description ARISTA07T2 - neighbor fc00::a remote-as 65200 - neighbor fc00::a peer-group TIER2_V6 - neighbor fc00::a description ARISTA05T2 - neighbor fc00::e remote-as 65200 - neighbor fc00::e peer-group TIER2_V6 - neighbor fc00::e description ARISTA07T2 - ! - address-family ipv4 unicast - network 8.0.0.1/32 route-map HIDE_INTERNAL - network 10.1.0.32/32 - redistribute connected route-map HIDE_INTERNAL - neighbor INTERNAL_PEER_V4 soft-reconfiguration inbound - neighbor INTERNAL_PEER_V4 route-map FROM_BGP_INTERNAL_PEER_V4 in - neighbor INTERNAL_PEER_V4 route-map TO_BGP_INTERNAL_PEER_V4 out - neighbor TIER2_V4 activate - neighbor TIER2_V4 soft-reconfiguration inbound - neighbor TIER2_V4 maximum-prefix 12000 90 warning-only - neighbor TIER2_V4 route-map FROM_TIER2_V4 in - neighbor TIER2_V4 route-map TO_TIER2_V4 out - neighbor 10.1.0.4 activate - neighbor 10.1.0.4 allowas-in 1 - neighbor 10.1.0.6 activate - neighbor 10.1.0.6 allowas-in 1 - maximum-paths 64 - exit-address-family - ! - address-family ipv6 unicast - network 2603:10e2:400::1/128 route-map HIDE_INTERNAL - network fc00:1::/64 - redistribute connected route-map HIDE_INTERNAL - neighbor INTERNAL_PEER_V6 soft-reconfiguration inbound - neighbor INTERNAL_PEER_V6 route-map FROM_BGP_INTERNAL_PEER_V6 in - neighbor INTERNAL_PEER_V6 route-map TO_BGP_INTERNAL_PEER_V6 out - neighbor TIER2_V6 activate - neighbor TIER2_V6 soft-reconfiguration inbound - neighbor TIER2_V6 maximum-prefix 8000 90 warning-only - neighbor TIER2_V6 route-map FROM_TIER2_V6 in - neighbor TIER2_V6 route-map TO_TIER2_V6 out - neighbor 2603:10e2:400:1::9 activate - neighbor 2603:10e2:400:1::9 allowas-in 1 - neighbor 2603:10e2:400:1::d activate - neighbor 2603:10e2:400:1::d allowas-in 1 - maximum-paths 64 - exit-address-family -! -ip prefix-list PL_LoopbackV4 seq 5 permit 10.1.0.32/32 -! -ipv6 prefix-list PL_LoopbackV6 seq 5 permit fc00:1::/64 -! -bgp community-list standard UPSTREAM_PREFIX permit 8075:54000 -! -route-map FROM_BGP_INTERNAL_PEER_V4 permit 100 -! -route-map FROM_BGP_INTERNAL_PEER_V6 permit 1 - on-match next - set ipv6 next-hop prefer-global -! -route-map FROM_BGP_INTERNAL_PEER_V6 permit 100 -! -route-map FROM_TIER2_V4 permit 100 - set community 8075:54000 additive -! -route-map FROM_TIER2_V6 permit 100 - on-match next - set ipv6 next-hop prefer-global -! -route-map FROM_TIER2_V6 permit 200 - set community 8075:54000 additive -! -route-map HIDE_INTERNAL permit 10 - on-match next - set community no-export -! -route-map HIDE_INTERNAL permit 20 - set community 8075:9306 additive -! -route-map RM_SET_SRC permit 10 -! -route-map RM_SET_SRC6 permit 10 -! -route-map TO_BGP_INTERNAL_PEER_V4 permit 100 -! -route-map TO_BGP_INTERNAL_PEER_V6 permit 100 -! -route-map TO_TIER2_V4 deny 100 - match community UPSTREAM_PREFIX -! -route-map TO_TIER2_V4 permit 10000 -! -route-map TO_TIER2_V6 deny 100 - match community UPSTREAM_PREFIX -! -route-map TO_TIER2_V6 permit 10000 -! -line vty -! -end -""" - -show_run_bgp_invalid_masic_no_namespace = \ -""" -Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1', 'asic2', 'asic3', 'asic4', 'asic5'], or give '-n all' -""" - -show_run_bgp_invalid_masic_wrong_namespace = \ -""" -Error: -n/--namespace option required. provide namespace from list ['asic0', 'asic1', 'asic2', 'asic3', 'asic4', 'asic5'], or give '-n all' -""" From 533982b5940a03ba67b08be7295e0b9387fff113 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:57:53 -0800 Subject: [PATCH 26/37] mock for single asic --- tests/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 96b80df3e1..4dc6f0a5d1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -169,6 +169,9 @@ def setup_single_bgp_instance(request): elif request.param == 'v6': bgp_mocked_json = os.path.join( test_path, 'mock_tables', 'ipv6_bgp_summary.json') + elif request.param == 'show_run_bgp': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'show_run_bgp.txt') elif request.param == 'ip_route': bgp_mocked_json = 'ip_route.json' elif request.param == 'ip_specific_route': @@ -193,6 +196,13 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV return mock_frr_data return "" + def mock_show_run_bgp(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): + if os.path.isfile(bgp_mocked_json): + with open(bgp_mocked_json) as json_data: + mock_frr_data = json_data.read() + return mock_frr_data + return "" + def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND): if vtysh_cmd == "show ip route vrf all static": return config_int_ip_common.show_ip_route_with_static_expected_output @@ -239,6 +249,9 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT elif request.param == "show_bgp_summary_no_neigh": bgp_util.run_bgp_command = mock.MagicMock( return_value=mock_show_bgp_summary_no_neigh("", "")) + elif request.param.startswith('show_run_bgp'): + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_run_bgp(request)) else: bgp_util.run_bgp_command = mock.MagicMock( return_value=mock_show_bgp_summary("", "")) From c87888ae55c337e96c8a6e48a6a3c40d426e80bc Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 18:15:38 -0800 Subject: [PATCH 27/37] mock multi_asic for 'show run bgp' --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4dc6f0a5d1..5395ffd087 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -283,6 +283,8 @@ def setup_multi_asic_bgp_instance(request): m_asic_json_file = 'ip_special_recursive_route.json' elif request.param == 'ip_route_summary': m_asic_json_file = 'ip_route_summary.txt' + elif request.param == 'show_run_bgp': + m_asic_json_file = 'show_run_bgp.txt' elif request.param.startswith('bgp_v4_network') or \ request.param.startswith('bgp_v6_network') or \ request.param.startswith('bgp_v4_neighbor') or \ From 5950d0920dbcd6a250b343a28adb1a4d733239e6 Mon Sep 17 00:00:00 2001 From: Wenyi Zhang Date: Tue, 24 Jan 2023 02:49:34 +0000 Subject: [PATCH 28/37] mock tables for 'show run bgp', test changed --- tests/mock_tables/asic0/show_run_bgp.txt | 12 ++ tests/mock_tables/asic1/show_run_bgp.txt | 12 ++ tests/mock_tables/show_run_bgp.txt | 64 ++++++ tests/show_run_bgp_test.py | 251 +++++++++++++++-------- 4 files changed, 258 insertions(+), 81 deletions(-) create mode 100644 tests/mock_tables/asic0/show_run_bgp.txt create mode 100644 tests/mock_tables/asic1/show_run_bgp.txt create mode 100644 tests/mock_tables/show_run_bgp.txt diff --git a/tests/mock_tables/asic0/show_run_bgp.txt b/tests/mock_tables/asic0/show_run_bgp.txt new file mode 100644 index 0000000000..e5c9a9982c --- /dev/null +++ b/tests/mock_tables/asic0/show_run_bgp.txt @@ -0,0 +1,12 @@ +neighbor 10.0.0.1 remote-as 65200 +neighbor 10.0.0.1 peer-group TIER2_V4 +neighbor 10.0.0.1 description ARISTA01T2 +neighbor 10.0.0.5 remote-as 65200 +neighbor 10.0.0.5 peer-group TIER2_V4 +neighbor 10.0.0.5 description ARISTA03T2 +neighbor fc00::2 remote-as 65200 +neighbor fc00::2 peer-group TIER2_V6 +neighbor fc00::2 description ARISTA01T2 +neighbor fc00::6 remote-as 65200 +neighbor fc00::6 peer-group TIER2_V6 +neighbor fc00::6 description ARISTA03T2 diff --git a/tests/mock_tables/asic1/show_run_bgp.txt b/tests/mock_tables/asic1/show_run_bgp.txt new file mode 100644 index 0000000000..de81748cc6 --- /dev/null +++ b/tests/mock_tables/asic1/show_run_bgp.txt @@ -0,0 +1,12 @@ +neighbor 10.0.0.9 remote-as 65200 +neighbor 10.0.0.9 peer-group TIER2_V4 +neighbor 10.0.0.9 description ARISTA05T2 +neighbor 10.0.0.13 remote-as 65200 +neighbor 10.0.0.13 peer-group TIER2_V4 +neighbor 10.0.0.13 description ARISTA07T2 +neighbor fc00::a remote-as 65200 +neighbor fc00::a peer-group TIER2_V6 +neighbor fc00::a description ARISTA05T2 +neighbor fc00::e remote-as 65200 +neighbor fc00::e peer-group TIER2_V6 +neighbor fc00::e description ARISTA07T2 diff --git a/tests/mock_tables/show_run_bgp.txt b/tests/mock_tables/show_run_bgp.txt new file mode 100644 index 0000000000..9a3ae8b13e --- /dev/null +++ b/tests/mock_tables/show_run_bgp.txt @@ -0,0 +1,64 @@ +router bgp 65100 +bgp router-id 10.1.0.32 +bgp log-neighbor-changes +no bgp ebgp-requires-policy +no bgp default ipv4-unicast +bgp graceful-restart restart-time 240 +bgp graceful-restart select-defer-time 45 +bgp graceful-restart +bgp graceful-restart preserve-fw-state +bgp bestpath as-path multipath-relax +neighbor BGPSLBPassive peer-group +neighbor BGPSLBPassive remote-as 65432 +neighbor BGPSLBPassive passive +neighbor BGPSLBPassive ebgp-multihop 255 +neighbor BGPSLBPassive update-source 10.1.0.32 +neighbor BGPVac peer-group +neighbor BGPVac remote-as 65432 +neighbor BGPVac passive +neighbor BGPVac ebgp-multihop 255 +neighbor BGPVac update-source 10.1.0.32 +neighbor PEER_V4 peer-group +neighbor PEER_V6 peer-group +neighbor 10.0.0.57 remote-as 64600 +neighbor 10.0.0.57 peer-group PEER_V4 +neighbor 10.0.0.57 description ARISTA01T1 +neighbor 10.0.0.57 timers 3 10 +neighbor 10.0.0.57 timers connect 10 +neighbor 10.0.0.59 remote-as 64600 +neighbor 10.0.0.59 peer-group PEER_V4 +neighbor 10.0.0.59 description ARISTA02T1 +neighbor 10.0.0.59 timers 3 10 +neighbor 10.0.0.59 timers connect 10 +neighbor 10.0.0.61 remote-as 64600 +neighbor 10.0.0.61 peer-group PEER_V4 +neighbor 10.0.0.61 description ARISTA03T1 +neighbor 10.0.0.61 timers 3 10 +neighbor 10.0.0.61 timers connect 10 +neighbor 10.0.0.63 remote-as 64600 +neighbor 10.0.0.63 peer-group PEER_V4 +neighbor 10.0.0.63 description ARISTA04T1 +neighbor 10.0.0.63 timers 3 10 +neighbor 10.0.0.63 timers connect 10 +neighbor fc00::72 remote-as 64600 +neighbor fc00::72 peer-group PEER_V6 +neighbor fc00::72 description ARISTA01T1 +neighbor fc00::72 timers 3 10 +neighbor fc00::72 timers connect 10 +neighbor fc00::76 remote-as 64600 +neighbor fc00::76 peer-group PEER_V6 +neighbor fc00::76 description ARISTA02T1 +neighbor fc00::76 timers 3 10 +neighbor fc00::76 timers connect 10 +neighbor fc00::7a remote-as 64600 +neighbor fc00::7a peer-group PEER_V6 +neighbor fc00::7a description ARISTA03T1 +neighbor fc00::7a timers 3 10 +neighbor fc00::7a timers connect 10 +neighbor fc00::7e remote-as 64600 +neighbor fc00::7e peer-group PEER_V6 +neighbor fc00::7e description ARISTA04T1 +neighbor fc00::7e timers 3 10 +neighbor fc00::7e timers connect 10 +bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive +bgp listen range 192.168.0.0/21 peer-group BGPVac diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index a7b54c5c83..3e6fb09845 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -13,88 +13,124 @@ show_run_bgp_sasic = \ +"""router bgp 65100 +bgp router-id 10.1.0.32 +bgp log-neighbor-changes +no bgp ebgp-requires-policy +no bgp default ipv4-unicast +bgp graceful-restart restart-time 240 +bgp graceful-restart select-defer-time 45 +bgp graceful-restart +bgp graceful-restart preserve-fw-state +bgp bestpath as-path multipath-relax +neighbor BGPSLBPassive peer-group +neighbor BGPSLBPassive remote-as 65432 +neighbor BGPSLBPassive passive +neighbor BGPSLBPassive ebgp-multihop 255 +neighbor BGPSLBPassive update-source 10.1.0.32 +neighbor BGPVac peer-group +neighbor BGPVac remote-as 65432 +neighbor BGPVac passive +neighbor BGPVac ebgp-multihop 255 +neighbor BGPVac update-source 10.1.0.32 +neighbor PEER_V4 peer-group +neighbor PEER_V6 peer-group +neighbor 10.0.0.57 remote-as 64600 +neighbor 10.0.0.57 peer-group PEER_V4 +neighbor 10.0.0.57 description ARISTA01T1 +neighbor 10.0.0.57 timers 3 10 +neighbor 10.0.0.57 timers connect 10 +neighbor 10.0.0.59 remote-as 64600 +neighbor 10.0.0.59 peer-group PEER_V4 +neighbor 10.0.0.59 description ARISTA02T1 +neighbor 10.0.0.59 timers 3 10 +neighbor 10.0.0.59 timers connect 10 +neighbor 10.0.0.61 remote-as 64600 +neighbor 10.0.0.61 peer-group PEER_V4 +neighbor 10.0.0.61 description ARISTA03T1 +neighbor 10.0.0.61 timers 3 10 +neighbor 10.0.0.61 timers connect 10 +neighbor 10.0.0.63 remote-as 64600 +neighbor 10.0.0.63 peer-group PEER_V4 +neighbor 10.0.0.63 description ARISTA04T1 +neighbor 10.0.0.63 timers 3 10 +neighbor 10.0.0.63 timers connect 10 +neighbor fc00::72 remote-as 64600 +neighbor fc00::72 peer-group PEER_V6 +neighbor fc00::72 description ARISTA01T1 +neighbor fc00::72 timers 3 10 +neighbor fc00::72 timers connect 10 +neighbor fc00::76 remote-as 64600 +neighbor fc00::76 peer-group PEER_V6 +neighbor fc00::76 description ARISTA02T1 +neighbor fc00::76 timers 3 10 +neighbor fc00::76 timers connect 10 +neighbor fc00::7a remote-as 64600 +neighbor fc00::7a peer-group PEER_V6 +neighbor fc00::7a description ARISTA03T1 +neighbor fc00::7a timers 3 10 +neighbor fc00::7a timers connect 10 +neighbor fc00::7e remote-as 64600 +neighbor fc00::7e peer-group PEER_V6 +neighbor fc00::7e description ARISTA04T1 +neighbor fc00::7e timers 3 10 +neighbor fc00::7e timers connect 10 +bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive +bgp listen range 192.168.0.0/21 peer-group BGPVac + +""" + +show_run_bgp_masic = \ """ -Building configuration... -Current configuration: -! -frr version 8.2.2 -frr defaults traditional -hostname str2-7050cx3-acs-02 -log syslog informational -log facility local4 -agentx -no service integrated-vtysh-config -! -password zebra -enable password zebra -! -router bgp 65100 - bgp router-id 10.1.0.32 - bgp log-neighbor-changes - no bgp ebgp-requires-policy - no bgp default ipv4-unicast - bgp graceful-restart restart-time 240 - bgp graceful-restart select-defer-time 45 - bgp graceful-restart - bgp graceful-restart preserve-fw-state - bgp bestpath as-path multipath-relax - neighbor BGPSLBPassive peer-group - neighbor BGPSLBPassive remote-as 65432 - neighbor BGPSLBPassive passive - neighbor BGPSLBPassive ebgp-multihop 255 - neighbor BGPSLBPassive update-source 10.1.0.32 - neighbor BGPVac peer-group - neighbor BGPVac remote-as 65432 - neighbor BGPVac passive - neighbor BGPVac ebgp-multihop 255 - neighbor BGPVac update-source 10.1.0.32 - neighbor PEER_V4 peer-group - neighbor PEER_V6 peer-group - neighbor 10.0.0.57 remote-as 64600 - neighbor 10.0.0.57 peer-group PEER_V4 - neighbor 10.0.0.57 description ARISTA01T1 - neighbor 10.0.0.57 timers 3 10 - neighbor 10.0.0.57 timers connect 10 - neighbor 10.0.0.59 remote-as 64600 - neighbor 10.0.0.59 peer-group PEER_V4 - neighbor 10.0.0.59 description ARISTA02T1 - neighbor 10.0.0.59 timers 3 10 - neighbor 10.0.0.59 timers connect 10 - neighbor 10.0.0.61 remote-as 64600 - neighbor 10.0.0.61 peer-group PEER_V4 - neighbor 10.0.0.61 description ARISTA03T1 - neighbor 10.0.0.61 timers 3 10 - neighbor 10.0.0.61 timers connect 10 - neighbor 10.0.0.63 remote-as 64600 - neighbor 10.0.0.63 peer-group PEER_V4 - neighbor 10.0.0.63 description ARISTA04T1 - neighbor 10.0.0.63 timers 3 10 - neighbor 10.0.0.63 timers connect 10 - neighbor fc00::72 remote-as 64600 - neighbor fc00::72 peer-group PEER_V6 - neighbor fc00::72 description ARISTA01T1 - neighbor fc00::72 timers 3 10 - neighbor fc00::72 timers connect 10 - neighbor fc00::76 remote-as 64600 - neighbor fc00::76 peer-group PEER_V6 - neighbor fc00::76 description ARISTA02T1 - neighbor fc00::76 timers 3 10 - neighbor fc00::76 timers connect 10 - neighbor fc00::7a remote-as 64600 - neighbor fc00::7a peer-group PEER_V6 - neighbor fc00::7a description ARISTA03T1 - neighbor fc00::7a timers 3 10 - neighbor fc00::7a timers connect 10 - neighbor fc00::7e remote-as 64600 - neighbor fc00::7e peer-group PEER_V6 - neighbor fc00::7e description ARISTA04T1 - neighbor fc00::7e timers 3 10 - neighbor fc00::7e timers connect 10 - bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive - bgp listen range 192.168.0.0/21 peer-group BGPVac +------------Showing running config bgp on asic0------------ +neighbor 10.0.0.1 remote-as 65200 +neighbor 10.0.0.1 peer-group TIER2_V4 +neighbor 10.0.0.1 description ARISTA01T2 +neighbor 10.0.0.5 remote-as 65200 +neighbor 10.0.0.5 peer-group TIER2_V4 +neighbor 10.0.0.5 description ARISTA03T2 +neighbor fc00::2 remote-as 65200 +neighbor fc00::2 peer-group TIER2_V6 +neighbor fc00::2 description ARISTA01T2 +neighbor fc00::6 remote-as 65200 +neighbor fc00::6 peer-group TIER2_V6 +neighbor fc00::6 description ARISTA03T2 + +------------Showing running config bgp on asic1------------ +neighbor 10.0.0.9 remote-as 65200 +neighbor 10.0.0.9 peer-group TIER2_V4 +neighbor 10.0.0.9 description ARISTA05T2 +neighbor 10.0.0.13 remote-as 65200 +neighbor 10.0.0.13 peer-group TIER2_V4 +neighbor 10.0.0.13 description ARISTA07T2 +neighbor fc00::a remote-as 65200 +neighbor fc00::a peer-group TIER2_V6 +neighbor fc00::a description ARISTA05T2 +neighbor fc00::e remote-as 65200 +neighbor fc00::e peer-group TIER2_V6 +neighbor fc00::e description ARISTA07T2 + +""" + +show_run_bgp_masic_asic0 = \ +""" +------------Showing running config bgp on asic0------------ +neighbor 10.0.0.1 remote-as 65200 +neighbor 10.0.0.1 peer-group TIER2_V4 +neighbor 10.0.0.1 description ARISTA01T2 +neighbor 10.0.0.5 remote-as 65200 +neighbor 10.0.0.5 peer-group TIER2_V4 +neighbor 10.0.0.5 description ARISTA03T2 +neighbor fc00::2 remote-as 65200 +neighbor fc00::2 peer-group TIER2_V6 +neighbor fc00::2 description ARISTA01T2 +neighbor fc00::6 remote-as 65200 +neighbor fc00::6 peer-group TIER2_V6 +neighbor fc00::6 description ARISTA03T2 + """ -class TestShowRunCommands(object): +class TestShowRunBgpSingleAsic(object): @classmethod def setup_class(cls): print("SETUP") @@ -103,13 +139,20 @@ def setup_class(cls): from .mock_tables import dbconnector dbconnector.load_namespace_config() - def test_show_run_bgp_single(self): + @pytest.mark.parametrize('setup_single_bgp_instance', + [ + 'show_run_bgp', + ], + indirect=['setup_single_bgp_instance']) + + def test_show_run_bgp_single(self, + setup_single_bgp_instance): runner = CliRunner() result = runner.invoke(show.cli.commands["runningconfiguration"].commands["bgp"], []) print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_run_bgp_sasic - + @classmethod def teardown_class(cls): print("TEARDOWN") @@ -118,3 +161,49 @@ def teardown_class(cls): importlib.reload(mock_single_asic) from .mock_tables import dbconnector dbconnector.load_database_config() + + +class TestShowRunBgpMultiAsic(object): + @classmethod + def setup_class(cls): + print("SETUP") + from .mock_tables import mock_multi_asic + importlib.reload(mock_multi_asic) + from .mock_tables import dbconnector + dbconnector.load_namespace_config() + + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', + [ + 'show_run_bgp', + ], + indirect=['setup_multi_asic_bgp_instance']) + def test_show_run_bgp_all_asics(self, + setup_multi_asic_bgp_instance): + runner = CliRunner() + result = runner.invoke(show.cli.commands["runningconfiguration"].commands["bgp"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_run_bgp_masic + + + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', + [ + 'show_run_bgp', + ], + indirect=['setup_multi_asic_bgp_instance']) + + def test_show_run_bgp_asic0(self, + setup_multi_asic_bgp_instance): + runner = CliRunner() + result = runner.invoke(show.cli.commands["runningconfiguration"].commands["bgp"], ["-nasic0"]) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_run_bgp_masic_asic0 + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + from .mock_tables import mock_single_asic + importlib.reload(mock_single_asic) + from .mock_tables import dbconnector + dbconnector.load_database_config From e1cba3dcbe574d4b71c4824249e99965d3629c42 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 19:50:24 -0800 Subject: [PATCH 29/37] syntax --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5395ffd087..a079aa5653 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -196,7 +196,7 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV return mock_frr_data return "" - def mock_show_run_bgp(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): + def mock_show_run_bgp(request): if os.path.isfile(bgp_mocked_json): with open(bgp_mocked_json) as json_data: mock_frr_data = json_data.read() From d41987795d866875b98a57f65a84175d77974819 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:18:21 -0800 Subject: [PATCH 30/37] add cmd definition --- show/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/show/main.py b/show/main.py index 361293b7c6..22c33f5ac6 100755 --- a/show/main.py +++ b/show/main.py @@ -1456,6 +1456,7 @@ def bgp(namespace, verbose): ctx.fail("-n/--namespace is not available for single asic") output = "" + cmd = "show running-config bgp" import utilities_common.bgp_util as bgp_util if multi_asic.is_multi_asic(): if not namespace: From 4fa78f0251279e8134caa9772f3c74bbe63ce195 Mon Sep 17 00:00:00 2001 From: Wenyi Zhang Date: Tue, 24 Jan 2023 18:01:58 +0000 Subject: [PATCH 31/37] fix indent and spaces --- show/main.py | 1 - tests/show_run_bgp_test.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index 22c33f5ac6..ba33bd4b9a 100755 --- a/show/main.py +++ b/show/main.py @@ -1432,7 +1432,6 @@ def ports(portname, verbose): run_command(cmd, display_cmd=verbose) - # 'bgp' subcommand ("show runningconfiguration bgp") @runningconfiguration.command() @click.option('--verbose', is_flag=True, help="Enable verbose output") diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 3e6fb09845..6158f8639e 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -141,7 +141,7 @@ def setup_class(cls): @pytest.mark.parametrize('setup_single_bgp_instance', [ - 'show_run_bgp', + 'show_run_bgp', ], indirect=['setup_single_bgp_instance']) @@ -174,7 +174,7 @@ def setup_class(cls): @pytest.mark.parametrize('setup_multi_asic_bgp_instance', [ - 'show_run_bgp', + 'show_run_bgp', ], indirect=['setup_multi_asic_bgp_instance']) def test_show_run_bgp_all_asics(self, From 400fd00533fda6fc50dd91db3e1f8b1cadcd3070 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 24 Jan 2023 10:05:27 -0800 Subject: [PATCH 32/37] fix indent --- tests/show_run_bgp_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index 6158f8639e..aa3060afe3 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -188,7 +188,7 @@ def test_show_run_bgp_all_asics(self, @pytest.mark.parametrize('setup_multi_asic_bgp_instance', [ - 'show_run_bgp', + 'show_run_bgp', ], indirect=['setup_multi_asic_bgp_instance']) From 189f598081b4d0eb5b461d7e48682f473184cbbd Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:35:49 -0800 Subject: [PATCH 33/37] remove comments, raise issue instead --- utilities_common/multi_asic.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/utilities_common/multi_asic.py b/utilities_common/multi_asic.py index 48401f2053..9e213f67f1 100644 --- a/utilities_common/multi_asic.py +++ b/utilities_common/multi_asic.py @@ -114,17 +114,6 @@ def multi_asic_display_default_option(): ] def multi_asic_namespace_validation_callback(ctx, param, value): - # TODO: this condition has a bug: it should be either "multi_asic.is_multi_asic()" - # or "self.is_multi_asic", but changing it to correct version will lead to the - # following cli not working on single-asic: - # show ip(v6) bgp neighbors/network, show storm_control add/del - # e.g. - # admin@str2-7050cx3-acs-02:/usr$ show ip bgp neighbor -n asic0 - # -n/--namespace is not available for single asic - # Aborted! - # admin@str2-7050cx3-acs-02:/usr$ show ip bgp neighbor - # -n/--namespace is not available for single asic - # Aborted! if not multi_asic.is_multi_asic: click.echo("-n/--namespace is not available for single asic") ctx.abort() From e22605bcd870c6ae20e6c2301fab0ffd300ae07c Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:42:00 -0800 Subject: [PATCH 34/37] use run_bgp_show_command to run readonly vtysh --- show/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index ba33bd4b9a..aec9af8f1b 100755 --- a/show/main.py +++ b/show/main.py @@ -1462,12 +1462,12 @@ def bgp(namespace, verbose): ns_list = multi_asic.get_namespace_list() for ns in ns_list: output += "\n------------Showing running config bgp on {}------------\n".format(ns) - output += bgp_util.run_bgp_command(cmd, ns) + output += bgp_util.run_bgp_show_command(cmd, ns) else: output += "\n------------Showing running config bgp on {}------------\n".format(namespace) - output += bgp_util.run_bgp_command(cmd, namespace) + output += bgp_util.run_bgp_show_command(cmd, namespace) else: - output += bgp_util.run_bgp_command(cmd) + output += bgp_util.run_bgp_show_command(cmd) print(output) From 11e1d1a99a6b35bd86ba6232636674be853e948e Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:35:12 -0800 Subject: [PATCH 35/37] Update conftest.py --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index a079aa5653..bf4c2a401f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -285,6 +285,8 @@ def setup_multi_asic_bgp_instance(request): m_asic_json_file = 'ip_route_summary.txt' elif request.param == 'show_run_bgp': m_asic_json_file = 'show_run_bgp.txt' + elif request.param == 'show_not_running_bgp': + m_asic_json_file = 'show_not_running_bgp.txt' elif request.param.startswith('bgp_v4_network') or \ request.param.startswith('bgp_v6_network') or \ request.param.startswith('bgp_v4_neighbor') or \ From 3dc51293cf2d42e0412a757c101429320a20937d Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:37:11 -0800 Subject: [PATCH 36/37] add bgp not running tests --- tests/show_run_bgp_test.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/show_run_bgp_test.py b/tests/show_run_bgp_test.py index aa3060afe3..4d3ff843a0 100644 --- a/tests/show_run_bgp_test.py +++ b/tests/show_run_bgp_test.py @@ -130,6 +130,13 @@ """ +show_run_bgp_not_running = \ +""" +------------Showing running config bgp on asic0------------ +Error response from daemon: Container 70e3d3bafd1ab5faf796892acff3e2ccbea3dcd5dcfefcc34f25f7cc916b67bb is not running + +""" + class TestShowRunBgpSingleAsic(object): @classmethod def setup_class(cls): @@ -191,7 +198,6 @@ def test_show_run_bgp_all_asics(self, 'show_run_bgp', ], indirect=['setup_multi_asic_bgp_instance']) - def test_show_run_bgp_asic0(self, setup_multi_asic_bgp_instance): runner = CliRunner() @@ -199,7 +205,20 @@ def test_show_run_bgp_asic0(self, print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_run_bgp_masic_asic0 - + + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', + [ + 'show_not_running_bgp', + ], + indirect=['setup_multi_asic_bgp_instance']) + def test_bgp0_not_running(self, + setup_multi_asic_bgp_instance): + runner = CliRunner() + result = runner.invoke(show.cli.commands["runningconfiguration"].commands["bgp"], ["-nasic0"]) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_run_bgp_not_running + @classmethod def teardown_class(cls): print("TEARDOWN") From 3a5bc315fb4b47741118da79624f494c4a9da683 Mon Sep 17 00:00:00 2001 From: Wenyi Zhang Date: Tue, 31 Jan 2023 00:40:04 +0000 Subject: [PATCH 37/37] add mock table for not running bgp --- tests/mock_tables/asic0/show_not_running_bgp.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/mock_tables/asic0/show_not_running_bgp.txt diff --git a/tests/mock_tables/asic0/show_not_running_bgp.txt b/tests/mock_tables/asic0/show_not_running_bgp.txt new file mode 100644 index 0000000000..b156e857f1 --- /dev/null +++ b/tests/mock_tables/asic0/show_not_running_bgp.txt @@ -0,0 +1 @@ +Error response from daemon: Container 70e3d3bafd1ab5faf796892acff3e2ccbea3dcd5dcfefcc34f25f7cc916b67bb is not running