From 9213252c20c525d9c573cd255030ccecf2f262a2 Mon Sep 17 00:00:00 2001 From: Wenyi Zhang Date: Mon, 31 Oct 2022 21:55:19 +0000 Subject: [PATCH 01/43] 'show interfaces counters' on multi-asci platforms by default show external links' info only. There are cases when internal links have CRC errors but w/o '-d all' option of 'show int counters', internal links were missed checking. This commit is to error out in syslog if any TX_ERR or RX_ERR happened(non-zero) Signed-off-by: Wenyi Zhang --- show/interfaces/__init__.py | 2 +- utilities_common/cli.py | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 25cfd045e0..136eb05831 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -527,7 +527,7 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): if ctx.invoked_subcommand is None: cmd = "portstat" - + clicommon.masic_run_command_int_ext_and_alert(cmd) if printall: cmd += " -a" if period is not None: diff --git a/utilities_common/cli.py b/utilities_common/cli.py index 163ed9bed0..3fcac0ac42 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -10,6 +10,7 @@ import json import lazy_object_proxy import netaddr +import syslog from natsort import natsorted from sonic_py_common import multi_asic @@ -511,6 +512,44 @@ def run_command_in_alias_mode(command): sys.exit(rc) +def masic_run_command_int_ext_and_alert(command): + command += " -s all" + + proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) + + (out, err) = proc.communicate() + + if len(out) == 0: + return + + parsed_op = out.rstrip('\n') + item = re.split(' +', parsed_op) + cnt = 0 + link = "" + """ + IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR + ----------- ------- ------- -------- --------- -------- -------- -------- ------- ---------- --------- -------- -------- -------- + Ethernet0 D 0 0.00 B/s 0.00% 0 0 0 0 0.00 B/s 0.00% 0 0 0 + Ethernet4 U 0 0.00 B/s 0.00% 0 0 0 4,806 134.18 B/s 0.00% 0 0 0 +idx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + """ + for i in item: + if i.startswith('Ethernet'): + cnt = 0 + link = i + else: + cnt = cnt+1 + # headers will be ignored by following + if i.isdigit() and int(i) != 0: + if cnt == 6: + syslog.syslog(syslog.LOG_ERR, "TX_ERR {} found on link {}!".format(i, link)) + if cnt == 15: + syslog.syslog(syslog.LOG_ERR, "RX_ERR {} found on link {}!".format(i, link)) + else: + continue + return + + def run_command(command, display_cmd=False, ignore_error=False, return_cmd=False, interactive_mode=False): """ Run bash command. Default behavior is to print output to stdout. If the command returns a non-zero From 0ac1563880faf01cbb3a2e284b14a0765dae941e Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:07:05 -0700 Subject: [PATCH 02/43] Update cli.py --- utilities_common/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities_common/cli.py b/utilities_common/cli.py index 3fcac0ac42..e7732da0f1 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -543,7 +543,7 @@ def masic_run_command_int_ext_and_alert(command): if i.isdigit() and int(i) != 0: if cnt == 6: syslog.syslog(syslog.LOG_ERR, "TX_ERR {} found on link {}!".format(i, link)) - if cnt == 15: + if cnt == 13: syslog.syslog(syslog.LOG_ERR, "RX_ERR {} found on link {}!".format(i, link)) else: continue From f45a60b9cea52351ba6baea65ff0eb6f3777a0d4 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:16:36 -0700 Subject: [PATCH 03/43] fix semgrep -- exit from process --- utilities_common/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utilities_common/cli.py b/utilities_common/cli.py index e7732da0f1..83da5aec18 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -547,7 +547,9 @@ def masic_run_command_int_ext_and_alert(command): syslog.syslog(syslog.LOG_ERR, "RX_ERR {} found on link {}!".format(i, link)) else: continue - return + rc = proc.poll() + if rc != 0: + sys.exit(rc) def run_command(command, display_cmd=False, ignore_error=False, return_cmd=False, interactive_mode=False): From f738b2f6f9dadf188d67a9427a790921882c8243 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:24:10 -0700 Subject: [PATCH 04/43] remove masic_run_command_int_ext_and_alert --- utilities_common/cli.py | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/utilities_common/cli.py b/utilities_common/cli.py index 83da5aec18..163ed9bed0 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -10,7 +10,6 @@ import json import lazy_object_proxy import netaddr -import syslog from natsort import natsorted from sonic_py_common import multi_asic @@ -512,46 +511,6 @@ def run_command_in_alias_mode(command): sys.exit(rc) -def masic_run_command_int_ext_and_alert(command): - command += " -s all" - - proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) - - (out, err) = proc.communicate() - - if len(out) == 0: - return - - parsed_op = out.rstrip('\n') - item = re.split(' +', parsed_op) - cnt = 0 - link = "" - """ - IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR - ----------- ------- ------- -------- --------- -------- -------- -------- ------- ---------- --------- -------- -------- -------- - Ethernet0 D 0 0.00 B/s 0.00% 0 0 0 0 0.00 B/s 0.00% 0 0 0 - Ethernet4 U 0 0.00 B/s 0.00% 0 0 0 4,806 134.18 B/s 0.00% 0 0 0 -idx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - """ - for i in item: - if i.startswith('Ethernet'): - cnt = 0 - link = i - else: - cnt = cnt+1 - # headers will be ignored by following - if i.isdigit() and int(i) != 0: - if cnt == 6: - syslog.syslog(syslog.LOG_ERR, "TX_ERR {} found on link {}!".format(i, link)) - if cnt == 13: - syslog.syslog(syslog.LOG_ERR, "RX_ERR {} found on link {}!".format(i, link)) - else: - continue - rc = proc.poll() - if rc != 0: - sys.exit(rc) - - def run_command(command, display_cmd=False, ignore_error=False, return_cmd=False, interactive_mode=False): """ Run bash command. Default behavior is to print output to stdout. If the command returns a non-zero From ee01dcb1325a8910e203548a9b65a193b3695ffe Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:25:47 -0700 Subject: [PATCH 05/43] add reminder --- show/interfaces/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 136eb05831..b2b04a700b 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -538,7 +538,7 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) - + click.echo("\n\nReminder: Please check internal links for any CRC error with '-d all' option\n\n") clicommon.run_command(cmd, display_cmd=verbose) # 'errors' subcommand ("show interfaces counters errors") From d175262fdcc68ff135bd8cd37609221974cc0157 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:26:30 -0700 Subject: [PATCH 06/43] remove calling masic_run_command_int_ext_and_alert --- show/interfaces/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index b2b04a700b..4d8e8175cf 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -527,7 +527,6 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): if ctx.invoked_subcommand is None: cmd = "portstat" - clicommon.masic_run_command_int_ext_and_alert(cmd) if printall: cmd += " -a" if period is not None: From d29c6daedff8977031fb9dae1eadc92925c6bcba Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:17:18 -0700 Subject: [PATCH 07/43] Update __init__.py --- show/interfaces/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 4d8e8175cf..28531d2b33 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -527,6 +527,7 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): if ctx.invoked_subcommand is None: cmd = "portstat" + if printall: cmd += " -a" if period is not None: @@ -537,8 +538,10 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) - click.echo("\n\nReminder: Please check internal links for any CRC error with '-d all' option\n\n") + clicommon.run_command(cmd, display_cmd=verbose) + if multi_asic.is_multi_asic(): + click.echo("\n\nReminder: Please execute 'show interface counters -d all' to include internal links\n\n") # 'errors' subcommand ("show interfaces counters errors") @counters.command() From 0a5c728bdce7473f88fc296b21f4c336de195dc6 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:18:04 -0700 Subject: [PATCH 08/43] remove spaces --- show/interfaces/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 28531d2b33..0261e0a61f 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -538,7 +538,7 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) - + clicommon.run_command(cmd, display_cmd=verbose) if multi_asic.is_multi_asic(): click.echo("\n\nReminder: Please execute 'show interface counters -d all' to include internal links\n\n") From 9b8e8b22208109030b034038f5f9f1f98558b992 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:46:56 -0800 Subject: [PATCH 09/43] change prints before output --- show/interfaces/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 0261e0a61f..dee73d973a 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -538,10 +538,10 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) - - clicommon.run_command(cmd, display_cmd=verbose) if multi_asic.is_multi_asic(): click.echo("\n\nReminder: Please execute 'show interface counters -d all' to include internal links\n\n") + clicommon.run_command(cmd, display_cmd=verbose) + # 'errors' subcommand ("show interfaces counters errors") @counters.command() From de68e95081ef2cc8d7690eb63829078bd6309b72 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:53:47 -0800 Subject: [PATCH 10/43] unit tests --- tests/portstat_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 2a70d0befc..bb23c4c754 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -162,6 +162,18 @@ Ethernet-BP256 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A""" +multi_asic_intf_counters_reminder = """\ + + +Reminder: Please execute 'show interface counters -d all' to include internal links + + + IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR +--------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- +Ethernet0 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A +Ethernet4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A +""" + intf_invalid_asic_error = """ValueError: Unknown Namespace asic99""" intf_counters_detailed = """\ @@ -497,6 +509,12 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error + def test_multi_show_intf_counters_reminder(self): + return_code, result = get_result_and_return_code('show int counters') + print("return_code: {}".format(return_code)) + print("result = {}".format(result)) + assert return_code == 0 + assert result == multi_asic_intf_counters_reminder @classmethod def teardown_class(cls): print("TEARDOWN") From 034f6e4527bb7acc30080c3493bbad1212994d2a Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:54:27 -0800 Subject: [PATCH 11/43] add line --- tests/portstat_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index bb23c4c754..0b50235e5e 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -515,6 +515,7 @@ def test_multi_show_intf_counters_reminder(self): print("result = {}".format(result)) assert return_code == 0 assert result == multi_asic_intf_counters_reminder + @classmethod def teardown_class(cls): print("TEARDOWN") From 063acb4f0a4ff7ee972fc4687ebc97d164073c7b Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:03:45 -0800 Subject: [PATCH 12/43] change unit test to run CLI --- tests/portstat_test.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 0b50235e5e..d0088d1892 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -509,12 +509,14 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error - def test_multi_show_intf_counters_reminder(self): - return_code, result = get_result_and_return_code('show int counters') - print("return_code: {}".format(return_code)) - print("result = {}".format(result)) - assert return_code == 0 - assert result == multi_asic_intf_counters_reminder + def test_multi_show_intf_counters_reminder(self, setup_interf_counters_commands): + show = setup_interf_counters_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["int"].commands["counters"]) + print("result = {}".format(result.output)) + assert result.exit_code == 0 + assert result.output == multi_asic_intf_counters_reminder @classmethod def teardown_class(cls): From 88442c578049d917cb98539932eaf729f75ece7c Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:04:19 -0800 Subject: [PATCH 13/43] add fixture setup_interf_counters_commands --- tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index b48d0ef93f..0731cada14 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -310,7 +310,6 @@ def setup_bgp_commands(): @pytest.fixture def setup_ip_route_commands(): import show.main as show - return show @pytest.fixture @@ -318,3 +317,7 @@ def setup_fib_commands(): import show.main as show return show +@pytest.fixture +def setup_interf_counters_commands(): + import show.interfaces.__init__ as show + return show From 58cc31a53d46838718206151b65fdd79ec6b11e6 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:03:05 -0800 Subject: [PATCH 14/43] Update portstat_test.py --- tests/portstat_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index d0088d1892..a1923cc422 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -509,8 +509,8 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error - def test_multi_show_intf_counters_reminder(self, setup_interf_counters_commands): - show = setup_interf_counters_commands + def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): + show = setup_ip_route_commands runner = CliRunner() result = runner.invoke( show.cli.commands["int"].commands["counters"]) From 74f36652c2dbb1e6247965e54cc17911300f943f Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:33:28 -0800 Subject: [PATCH 15/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index a1923cc422..e03a37e8c5 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -513,7 +513,7 @@ def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): show = setup_ip_route_commands runner = CliRunner() result = runner.invoke( - show.cli.commands["int"].commands["counters"]) + show.cli.commands["interfaces"].commands["counters"]) print("result = {}".format(result.output)) assert result.exit_code == 0 assert result.output == multi_asic_intf_counters_reminder From e472894173c773c1a807eaddcbd50cba0d73f278 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:57:40 -0800 Subject: [PATCH 16/43] Delete conftest.py --- tests/conftest.py | 323 ---------------------------------------------- 1 file changed, 323 deletions(-) delete mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 0731cada14..0000000000 --- a/tests/conftest.py +++ /dev/null @@ -1,323 +0,0 @@ -import json -import os -import re -import sys -from unittest import mock - -import pytest -from sonic_py_common import device_info, multi_asic -from swsscommon.swsscommon import ConfigDBConnector - -from .mock_tables import dbconnector -from . import show_ip_route_common -from .bgp_commands_input.bgp_neighbor_test_vector import( - mock_show_bgp_neighbor_single_asic, - mock_show_bgp_neighbor_multi_asic, - ) -from .bgp_commands_input.bgp_network_test_vector import ( - mock_show_bgp_network_single_asic, - mock_show_bgp_network_multi_asic - ) -from . import config_int_ip_common -import utilities_common.constants as constants - -test_path = os.path.dirname(os.path.abspath(__file__)) -modules_path = os.path.dirname(test_path) -sys.path.insert(0, modules_path) - -generated_services_list = [ - 'ntp-config.service', - 'warmboot-finalizer.service', - 'watchdog-control.service', - 'rsyslog-config.service', - 'interfaces-config.service', - 'hostcfgd.service', - 'hostname-config.service', - 'topology.service', - 'updategraph.service', - 'config-setup.service', - 'caclmgrd.service', - 'procdockerstatsd.service', - 'pcie-check.service', - 'process-reboot-cause.service', - 'dhcp_relay.service', - 'snmp.service', - 'sflow.service', - 'bgp.service', - 'telemetry.service', - 'swss.service', - 'database.service', - 'database.service', - 'lldp.service', - 'lldp.service', - 'pmon.service', - 'radv.service', - 'mgmt-framework.service', - 'nat.service', - 'teamd.service', - 'syncd.service', - 'snmp.timer', - 'telemetry.timer'] - - -@pytest.fixture -def get_cmd_module(): - import config.main as config - import show.main as show - - return (config, show) - -def set_mock_apis(): - import config.main as config - cwd = os.path.dirname(os.path.realpath(__file__)) - config.asic_type = mock.MagicMock(return_value="broadcom") - config._get_device_type = mock.MagicMock(return_value="ToRRouter") - -@pytest.fixture -def setup_cbf_mock_apis(): - cwd = os.path.dirname(os.path.realpath(__file__)) - device_info.get_paths_to_platform_and_hwsku_dirs = mock.MagicMock( - return_value=( - os.path.join(cwd, "."), os.path.join(cwd, "cbf_config_input") - ) - ) - device_info.get_sonic_version_file = mock.MagicMock( - return_value=os.path.join(cwd, "qos_config_input/sonic_version.yml") - ) - -@pytest.fixture -def setup_qos_mock_apis(): - cwd = os.path.dirname(os.path.realpath(__file__)) - device_info.get_paths_to_platform_and_hwsku_dirs = mock.MagicMock( - return_value=( - os.path.join(cwd, "."), os.path.join(cwd, "qos_config_input") - ) - ) - device_info.get_sonic_version_file = mock.MagicMock( - return_value=os.path.join(cwd, "qos_config_input/sonic_version.yml") - ) - -@pytest.fixture -def setup_single_broadcom_asic(): - import config.main as config - import show.main as show - - set_mock_apis() - device_info.get_num_npus = mock.MagicMock(return_value=1) - config._get_sonic_generated_services = \ - mock.MagicMock(return_value=(generated_services_list, [])) - - -@pytest.fixture -def setup_multi_broadcom_masic(): - import config.main as config - import show.main as show - - set_mock_apis() - device_info.get_num_npus = mock.MagicMock(return_value=2) - multi_asic.get_num_asics = mock.MagicMock(return_value=2) - multi_asic.is_multi_asic= mock.MagicMock(return_value=True) - - yield - - device_info.get_num_npus = mock.MagicMock(return_value=1) - multi_asic.get_num_asics = mock.MagicMock(return_value=1) - multi_asic.is_multi_asic= mock.MagicMock(return_value=False) - - -@pytest.fixture -def setup_single_bgp_instance_chassis(request): - import utilities_common.bgp_util as bgp_util - - def mock_show_bgp_summary( - 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 "" - - if request.param == 'v4': - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', 'ipv4_bgp_summary_chassis.json') - elif request.param == 'v6': - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', 'ipv6_bgp_summary_chassis.json') - - bgp_util.run_bgp_command = mock.MagicMock( - return_value=mock_show_bgp_summary("", "")) - - -@pytest.fixture -def setup_t1_topo(): - dbconnector.topo = "t1" - yield - dbconnector.topo = None - - -@pytest.fixture -def setup_single_bgp_instance(request): - import utilities_common.bgp_util as bgp_util - if request.param == 'v4': - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', 'ipv4_bgp_summary.json') - elif request.param == 'v6': - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', 'ipv6_bgp_summary.json') - else: - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', 'dummy.json') - - def mock_show_bgp_summary(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 - elif vtysh_cmd == "show ipv6 route vrf all static": - return config_int_ip_common.show_ipv6_route_with_static_expected_output - else: - return "" - - def mock_run_show_ip_route_commands(request): - if request.param == 'ipv6_route_err': - return show_ip_route_common.show_ipv6_route_err_expected_output - elif request.param == 'ip_route': - return show_ip_route_common.show_ip_route_expected_output - elif request.param == 'ip_specific_route': - return show_ip_route_common.show_specific_ip_route_expected_output - elif request.param == 'ip_special_route': - return show_ip_route_common.show_special_ip_route_expected_output - elif request.param == 'ipv6_route': - return show_ip_route_common.show_ipv6_route_expected_output - elif request.param == 'ipv6_specific_route': - return show_ip_route_common.show_ipv6_route_single_json_expected_output - else: - return "" - - - if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\ - request.param == 'ip_specific_route', request.param == 'ip_special_route',\ - request.param == 'ipv6_route', request.param == 'ipv6_specific_route']): - bgp_util.run_bgp_command = mock.MagicMock( - return_value=mock_run_show_ip_route_commands(request)) - elif request.param.startswith('bgp_v4_neighbor') or \ - request.param.startswith('bgp_v6_neighbor'): - bgp_util.run_bgp_command = mock.MagicMock( - return_value=mock_show_bgp_neighbor_single_asic(request)) - elif request.param.startswith('bgp_v4_network') or \ - request.param.startswith('bgp_v6_network'): - bgp_util.run_bgp_command = mock.MagicMock( - return_value=mock_show_bgp_network_single_asic(request)) - elif request.param == 'ip_route_for_int_ip': - _old_run_bgp_command = bgp_util.run_bgp_command - bgp_util.run_bgp_command = mock_run_bgp_command_for_static - else: - bgp_util.run_bgp_command = mock.MagicMock( - return_value=mock_show_bgp_summary("", "")) - - yield - - if request.param == 'ip_route_for_int_ip': - bgp_util.run_bgp_command = _old_run_bgp_command - - -@pytest.fixture -def setup_multi_asic_bgp_instance(request): - import utilities_common.bgp_util as bgp_util - - if request.param == 'ip_route': - m_asic_json_file = 'ip_route.json' - elif request.param == 'ip_specific_route': - m_asic_json_file = 'ip_specific_route.json' - elif request.param == 'ipv6_specific_route': - m_asic_json_file = 'ipv6_specific_route.json' - elif request.param == 'ipv6_route': - m_asic_json_file = 'ipv6_route.json' - elif request.param == 'ip_special_route': - m_asic_json_file = 'ip_special_route.json' - elif request.param == 'ip_empty_route': - m_asic_json_file = 'ip_empty_route.json' - elif request.param == 'ip_specific_route_on_1_asic': - m_asic_json_file = 'ip_special_route_asic0_only.json' - elif request.param == 'ip_specific_recursive_route': - 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.startswith('bgp_v4_network') or \ - request.param.startswith('bgp_v6_network') or \ - request.param.startswith('bgp_v4_neighbor') or \ - request.param.startswith('bgp_v6_neighbor'): - m_asic_json_file = request.param - else: - m_asic_json_file = os.path.join( - test_path, 'mock_tables', 'dummy.json') - - def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND): - if bgp_namespace != 'test_ns': - return "" - if vtysh_cmd == "show ip route vrf all static": - return config_int_ip_common.show_ip_route_with_static_expected_output - elif vtysh_cmd == "show ipv6 route vrf all static": - return config_int_ip_common.show_ipv6_route_with_static_expected_output - else: - return "" - - def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): - if m_asic_json_file.startswith('bgp_v4_network') or \ - m_asic_json_file.startswith('bgp_v6_network'): - return mock_show_bgp_network_multi_asic(m_asic_json_file) - - if m_asic_json_file.startswith('bgp_v4_neighbor') or \ - m_asic_json_file.startswith('bgp_v6_neighbor'): - return mock_show_bgp_neighbor_multi_asic(m_asic_json_file, bgp_namespace) - - bgp_mocked_json = os.path.join( - test_path, 'mock_tables', bgp_namespace, m_asic_json_file) - 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 - else: - return "" - - _old_run_bgp_command = bgp_util.run_bgp_command - if request.param == 'ip_route_for_int_ip': - bgp_util.run_bgp_command = mock_run_bgp_command_for_static - else: - bgp_util.run_bgp_command = mock_run_bgp_command - - yield - - bgp_util.run_bgp_command = _old_run_bgp_command - -@pytest.fixture -def setup_bgp_commands(): - import show.main as show - from show.bgp_frr_v4 import bgp as bgpv4 - from show.bgp_frr_v6 import bgp as bgpv6 - - show.ip.add_command(bgpv4) - show.ipv6.add_command(bgpv6) - return show - - -@pytest.fixture -def setup_ip_route_commands(): - import show.main as show - return show - -@pytest.fixture -def setup_fib_commands(): - import show.main as show - return show - -@pytest.fixture -def setup_interf_counters_commands(): - import show.interfaces.__init__ as show - return show From ffc085ed43bcc403bc742b2de64abff15b31e66a Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:58:15 -0800 Subject: [PATCH 17/43] Update portstat_test.py --- tests/portstat_test.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index e03a37e8c5..cbc5c37cec 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -163,15 +163,7 @@ Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A""" multi_asic_intf_counters_reminder = """\ - - Reminder: Please execute 'show interface counters -d all' to include internal links - - - IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR ---------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- -Ethernet0 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A -Ethernet4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A """ intf_invalid_asic_error = """ValueError: Unknown Namespace asic99""" @@ -516,7 +508,7 @@ def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): show.cli.commands["interfaces"].commands["counters"]) print("result = {}".format(result.output)) assert result.exit_code == 0 - assert result.output == multi_asic_intf_counters_reminder + assert multi_asic_intf_counters_reminder in result.output @classmethod def teardown_class(cls): From e3a4efb3b03735b0e456a51d4bf67faa95e0bf18 Mon Sep 17 00:00:00 2001 From: Wenyi Zhang Date: Tue, 8 Nov 2022 23:09:36 +0000 Subject: [PATCH 18/43] Revert "Delete conftest.py" This reverts commit e472894173c773c1a807eaddcbd50cba0d73f278. --- tests/conftest.py | 323 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000..0731cada14 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,323 @@ +import json +import os +import re +import sys +from unittest import mock + +import pytest +from sonic_py_common import device_info, multi_asic +from swsscommon.swsscommon import ConfigDBConnector + +from .mock_tables import dbconnector +from . import show_ip_route_common +from .bgp_commands_input.bgp_neighbor_test_vector import( + mock_show_bgp_neighbor_single_asic, + mock_show_bgp_neighbor_multi_asic, + ) +from .bgp_commands_input.bgp_network_test_vector import ( + mock_show_bgp_network_single_asic, + mock_show_bgp_network_multi_asic + ) +from . import config_int_ip_common +import utilities_common.constants as constants + +test_path = os.path.dirname(os.path.abspath(__file__)) +modules_path = os.path.dirname(test_path) +sys.path.insert(0, modules_path) + +generated_services_list = [ + 'ntp-config.service', + 'warmboot-finalizer.service', + 'watchdog-control.service', + 'rsyslog-config.service', + 'interfaces-config.service', + 'hostcfgd.service', + 'hostname-config.service', + 'topology.service', + 'updategraph.service', + 'config-setup.service', + 'caclmgrd.service', + 'procdockerstatsd.service', + 'pcie-check.service', + 'process-reboot-cause.service', + 'dhcp_relay.service', + 'snmp.service', + 'sflow.service', + 'bgp.service', + 'telemetry.service', + 'swss.service', + 'database.service', + 'database.service', + 'lldp.service', + 'lldp.service', + 'pmon.service', + 'radv.service', + 'mgmt-framework.service', + 'nat.service', + 'teamd.service', + 'syncd.service', + 'snmp.timer', + 'telemetry.timer'] + + +@pytest.fixture +def get_cmd_module(): + import config.main as config + import show.main as show + + return (config, show) + +def set_mock_apis(): + import config.main as config + cwd = os.path.dirname(os.path.realpath(__file__)) + config.asic_type = mock.MagicMock(return_value="broadcom") + config._get_device_type = mock.MagicMock(return_value="ToRRouter") + +@pytest.fixture +def setup_cbf_mock_apis(): + cwd = os.path.dirname(os.path.realpath(__file__)) + device_info.get_paths_to_platform_and_hwsku_dirs = mock.MagicMock( + return_value=( + os.path.join(cwd, "."), os.path.join(cwd, "cbf_config_input") + ) + ) + device_info.get_sonic_version_file = mock.MagicMock( + return_value=os.path.join(cwd, "qos_config_input/sonic_version.yml") + ) + +@pytest.fixture +def setup_qos_mock_apis(): + cwd = os.path.dirname(os.path.realpath(__file__)) + device_info.get_paths_to_platform_and_hwsku_dirs = mock.MagicMock( + return_value=( + os.path.join(cwd, "."), os.path.join(cwd, "qos_config_input") + ) + ) + device_info.get_sonic_version_file = mock.MagicMock( + return_value=os.path.join(cwd, "qos_config_input/sonic_version.yml") + ) + +@pytest.fixture +def setup_single_broadcom_asic(): + import config.main as config + import show.main as show + + set_mock_apis() + device_info.get_num_npus = mock.MagicMock(return_value=1) + config._get_sonic_generated_services = \ + mock.MagicMock(return_value=(generated_services_list, [])) + + +@pytest.fixture +def setup_multi_broadcom_masic(): + import config.main as config + import show.main as show + + set_mock_apis() + device_info.get_num_npus = mock.MagicMock(return_value=2) + multi_asic.get_num_asics = mock.MagicMock(return_value=2) + multi_asic.is_multi_asic= mock.MagicMock(return_value=True) + + yield + + device_info.get_num_npus = mock.MagicMock(return_value=1) + multi_asic.get_num_asics = mock.MagicMock(return_value=1) + multi_asic.is_multi_asic= mock.MagicMock(return_value=False) + + +@pytest.fixture +def setup_single_bgp_instance_chassis(request): + import utilities_common.bgp_util as bgp_util + + def mock_show_bgp_summary( + 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 "" + + if request.param == 'v4': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv4_bgp_summary_chassis.json') + elif request.param == 'v6': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv6_bgp_summary_chassis.json') + + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_summary("", "")) + + +@pytest.fixture +def setup_t1_topo(): + dbconnector.topo = "t1" + yield + dbconnector.topo = None + + +@pytest.fixture +def setup_single_bgp_instance(request): + import utilities_common.bgp_util as bgp_util + if request.param == 'v4': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv4_bgp_summary.json') + elif request.param == 'v6': + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'ipv6_bgp_summary.json') + else: + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', 'dummy.json') + + def mock_show_bgp_summary(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 + elif vtysh_cmd == "show ipv6 route vrf all static": + return config_int_ip_common.show_ipv6_route_with_static_expected_output + else: + return "" + + def mock_run_show_ip_route_commands(request): + if request.param == 'ipv6_route_err': + return show_ip_route_common.show_ipv6_route_err_expected_output + elif request.param == 'ip_route': + return show_ip_route_common.show_ip_route_expected_output + elif request.param == 'ip_specific_route': + return show_ip_route_common.show_specific_ip_route_expected_output + elif request.param == 'ip_special_route': + return show_ip_route_common.show_special_ip_route_expected_output + elif request.param == 'ipv6_route': + return show_ip_route_common.show_ipv6_route_expected_output + elif request.param == 'ipv6_specific_route': + return show_ip_route_common.show_ipv6_route_single_json_expected_output + else: + return "" + + + if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\ + request.param == 'ip_specific_route', request.param == 'ip_special_route',\ + request.param == 'ipv6_route', request.param == 'ipv6_specific_route']): + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_run_show_ip_route_commands(request)) + elif request.param.startswith('bgp_v4_neighbor') or \ + request.param.startswith('bgp_v6_neighbor'): + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_neighbor_single_asic(request)) + elif request.param.startswith('bgp_v4_network') or \ + request.param.startswith('bgp_v6_network'): + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_network_single_asic(request)) + elif request.param == 'ip_route_for_int_ip': + _old_run_bgp_command = bgp_util.run_bgp_command + bgp_util.run_bgp_command = mock_run_bgp_command_for_static + else: + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_summary("", "")) + + yield + + if request.param == 'ip_route_for_int_ip': + bgp_util.run_bgp_command = _old_run_bgp_command + + +@pytest.fixture +def setup_multi_asic_bgp_instance(request): + import utilities_common.bgp_util as bgp_util + + if request.param == 'ip_route': + m_asic_json_file = 'ip_route.json' + elif request.param == 'ip_specific_route': + m_asic_json_file = 'ip_specific_route.json' + elif request.param == 'ipv6_specific_route': + m_asic_json_file = 'ipv6_specific_route.json' + elif request.param == 'ipv6_route': + m_asic_json_file = 'ipv6_route.json' + elif request.param == 'ip_special_route': + m_asic_json_file = 'ip_special_route.json' + elif request.param == 'ip_empty_route': + m_asic_json_file = 'ip_empty_route.json' + elif request.param == 'ip_specific_route_on_1_asic': + m_asic_json_file = 'ip_special_route_asic0_only.json' + elif request.param == 'ip_specific_recursive_route': + 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.startswith('bgp_v4_network') or \ + request.param.startswith('bgp_v6_network') or \ + request.param.startswith('bgp_v4_neighbor') or \ + request.param.startswith('bgp_v6_neighbor'): + m_asic_json_file = request.param + else: + m_asic_json_file = os.path.join( + test_path, 'mock_tables', 'dummy.json') + + def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND): + if bgp_namespace != 'test_ns': + return "" + if vtysh_cmd == "show ip route vrf all static": + return config_int_ip_common.show_ip_route_with_static_expected_output + elif vtysh_cmd == "show ipv6 route vrf all static": + return config_int_ip_common.show_ipv6_route_with_static_expected_output + else: + return "" + + def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): + if m_asic_json_file.startswith('bgp_v4_network') or \ + m_asic_json_file.startswith('bgp_v6_network'): + return mock_show_bgp_network_multi_asic(m_asic_json_file) + + if m_asic_json_file.startswith('bgp_v4_neighbor') or \ + m_asic_json_file.startswith('bgp_v6_neighbor'): + return mock_show_bgp_neighbor_multi_asic(m_asic_json_file, bgp_namespace) + + bgp_mocked_json = os.path.join( + test_path, 'mock_tables', bgp_namespace, m_asic_json_file) + 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 + else: + return "" + + _old_run_bgp_command = bgp_util.run_bgp_command + if request.param == 'ip_route_for_int_ip': + bgp_util.run_bgp_command = mock_run_bgp_command_for_static + else: + bgp_util.run_bgp_command = mock_run_bgp_command + + yield + + bgp_util.run_bgp_command = _old_run_bgp_command + +@pytest.fixture +def setup_bgp_commands(): + import show.main as show + from show.bgp_frr_v4 import bgp as bgpv4 + from show.bgp_frr_v6 import bgp as bgpv6 + + show.ip.add_command(bgpv4) + show.ipv6.add_command(bgpv6) + return show + + +@pytest.fixture +def setup_ip_route_commands(): + import show.main as show + return show + +@pytest.fixture +def setup_fib_commands(): + import show.main as show + return show + +@pytest.fixture +def setup_interf_counters_commands(): + import show.interfaces.__init__ as show + return show From b8d18464b08de94009a9e50cb824bb7783b15d53 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:08:57 -0800 Subject: [PATCH 19/43] refine unit test --- tests/portstat_test.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index cbc5c37cec..f784a11d6a 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -383,7 +383,12 @@ def teardown_class(cls): class TestMultiAsicPortStat(object): @classmethod def setup_class(cls): - print("SETUP") + print("SETUP") + from .mock_tables import mock_multi_asic + importlib.reload(mock_multi_asic) + from .mock_tables import dbconnector + dbconnector.load_namespace_config() + os.environ["PATH"] += os.pathsep + scripts_path os.environ["UTILITIES_UNIT_TESTING"] = "2" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" @@ -502,10 +507,14 @@ def test_multi_asic_invalid_asic(self): assert result == intf_invalid_asic_error def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): - show = setup_ip_route_commands runner = CliRunner() + db = Db() + obj = {'config_db':db.cfgdb, 'namespace':'asic0'} + result = runner.invoke( - show.cli.commands["interfaces"].commands["counters"]) + config.config.commands["interface"].commands["counters"], + [], obj=obj) + print("result = {}".format(result.output)) assert result.exit_code == 0 assert multi_asic_intf_counters_reminder in result.output From 9d6cc9984849961cfb733da69ba78a0c776e7eb8 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:32:35 -0800 Subject: [PATCH 20/43] add teardown --- tests/portstat_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index f784a11d6a..3ebedcf1cb 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -522,8 +522,14 @@ def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): @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() + os.environ["PATH"] = os.pathsep.join( os.environ["PATH"].split(os.pathsep)[:-1]) os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() + From ffb3569418b92b80a2eef3f8eb3888d05bb9e940 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 15 Nov 2022 14:39:44 -0800 Subject: [PATCH 21/43] separate class TestShowIntCountersMasic --- tests/portstat_test.py | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 3ebedcf1cb..85114e75d9 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -383,12 +383,7 @@ def teardown_class(cls): class TestMultiAsicPortStat(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() - + print("SETUP") os.environ["PATH"] += os.pathsep + scripts_path os.environ["UTILITIES_UNIT_TESTING"] = "2" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" @@ -506,30 +501,39 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join( + os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" + remove_tmp_cnstat_file() + + +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() - db = Db() - obj = {'config_db':db.cfgdb, 'namespace':'asic0'} - - result = runner.invoke( - config.config.commands["interface"].commands["counters"], - [], obj=obj) - + 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() - - os.environ["PATH"] = os.pathsep.join( - os.environ["PATH"].split(os.pathsep)[:-1]) - os.environ["UTILITIES_UNIT_TESTING"] = "0" - os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" - remove_tmp_cnstat_file() - From 14a0438514552cb8fba36a7433d501a00b1fd5a4 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:33:25 -0800 Subject: [PATCH 22/43] Update conftest.py --- tests/conftest.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0731cada14..07f7f81184 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -316,8 +316,3 @@ def setup_ip_route_commands(): def setup_fib_commands(): import show.main as show return show - -@pytest.fixture -def setup_interf_counters_commands(): - import show.interfaces.__init__ as show - return show From f0c9b9342787b26478da4ca3468d1ff88b8a8631 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 1 Dec 2022 14:54:00 -0800 Subject: [PATCH 23/43] move print to end --- show/interfaces/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 387ee68009..a0abaac95c 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -538,9 +538,10 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) + + clicommon.run_command(cmd, display_cmd=verbose) if multi_asic.is_multi_asic(): click.echo("\n\nReminder: Please execute 'show interface counters -d all' to include internal links\n\n") - clicommon.run_command(cmd, display_cmd=verbose) # 'errors' subcommand ("show interfaces counters errors") From 8df1ebe9e12b8a64cc7e974c10cc7f66e205fa87 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:01:22 -0800 Subject: [PATCH 24/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 85114e75d9..f09fe1a3cc 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -523,7 +523,7 @@ def setup_class(cls): def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): runner = CliRunner() - result = runner.invoke(show.cli.commands["interface"].commands["counters"]) + 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 From 074dea8a3a148634affac601cdb451e748e7c018 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 10:58:39 -0800 Subject: [PATCH 25/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index f09fe1a3cc..9c598941bb 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -1,6 +1,6 @@ import os import shutil - +import importlib from click.testing import CliRunner import clear.main as clear From b0d0209496ac210f76ddb153f7a4adf3f5e3706e Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:30:25 -0800 Subject: [PATCH 26/43] reuse existing class --- tests/portstat_test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 9c598941bb..8ef12be1e0 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -501,6 +501,13 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error + def test_multi_show_intf_counters_reminder(self): + runner = CliRunner() + result = runner.invoke(show.cli.commands["interfaces"].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") @@ -523,7 +530,7 @@ def setup_class(cls): def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): runner = CliRunner() - result = runner.invoke(show.cli.commands["interface"].commands["counters"], []) + result = runner.invoke(show.cli.commands["interfaces"].commands["counters"], []) print("result = {}".format(result.output)) assert result.exit_code == 0 assert multi_asic_intf_counters_reminder in result.output From 456821046ad9005ab19f6085e06a826e046f912d Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:31:14 -0800 Subject: [PATCH 27/43] remove new class --- tests/portstat_test.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 8ef12be1e0..338ae48993 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -1,6 +1,6 @@ import os import shutil -import importlib + from click.testing import CliRunner import clear.main as clear @@ -516,31 +516,4 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() - - -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["interfaces"].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 480ce00fdfac3ad42914fa394a7abd0f143ea397 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:52:53 -0800 Subject: [PATCH 28/43] Update portstat_test.py --- tests/portstat_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 338ae48993..3f25937650 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -241,6 +241,7 @@ def test_show_intf_counters(self): print(result.output) assert result.exit_code == 0 assert result.output == intf_counters_before_clear + assert multi_asic_intf_counters_reminder not in result.output return_code, result = get_result_and_return_code('portstat') print("return_code: {}".format(return_code)) From c0e2954efd8e7e86354a26ac65a8fbfabe652391 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 12:29:30 -0800 Subject: [PATCH 29/43] use new masic class as old one does not seem to mock correct multi-asic topo --- tests/portstat_test.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 3f25937650..6b3f7929f2 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -502,13 +502,6 @@ def test_multi_asic_invalid_asic(self): assert return_code == 1 assert result == intf_invalid_asic_error - def test_multi_show_intf_counters_reminder(self): - runner = CliRunner() - result = runner.invoke(show.cli.commands["interfaces"].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") @@ -518,3 +511,29 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() +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["interfaces"].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 d7a9e72a9d5ce71c3d8d9df69b32744210425137 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 12:46:07 -0800 Subject: [PATCH 30/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 6b3f7929f2..4bbcdedd91 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -1,6 +1,6 @@ import os import shutil - +import importlib from click.testing import CliRunner import clear.main as clear From 1b47b34c52333e538360b0116351900bc6a0de5a Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 14:58:46 -0800 Subject: [PATCH 31/43] Update portstat_test.py --- tests/portstat_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 4bbcdedd91..da00334384 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -523,6 +523,7 @@ def setup_class(cls): def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): runner = CliRunner() + import show.interfaces.__init__ as show result = runner.invoke(show.cli.commands["interfaces"].commands["counters"], []) print("result = {}".format(result.output)) assert result.exit_code == 0 From 062c16e51b4bbe3619b1140316b65aa728487d18 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:22:35 -0800 Subject: [PATCH 32/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index da00334384..99026a9dba 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -524,7 +524,7 @@ def setup_class(cls): def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): runner = CliRunner() import show.interfaces.__init__ as show - result = runner.invoke(show.cli.commands["interfaces"].commands["counters"], []) + result = runner.invoke(show.commands["interfaces"].commands["counters"], []) print("result = {}".format(result.output)) assert result.exit_code == 0 assert multi_asic_intf_counters_reminder in result.output From c63dde317e1778725fe7e1f04e2f63c89759a396 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:48:43 -0800 Subject: [PATCH 33/43] Update portstat_test.py --- tests/portstat_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 99026a9dba..a9bd992697 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -524,7 +524,7 @@ def setup_class(cls): def test_multi_show_intf_counters_reminder(self, setup_ip_route_commands): runner = CliRunner() import show.interfaces.__init__ as show - result = runner.invoke(show.commands["interfaces"].commands["counters"], []) + result = runner.invoke(show.interfaces.commands["counters"], []) print("result = {}".format(result.output)) assert result.exit_code == 0 assert multi_asic_intf_counters_reminder in result.output From 9a0c2cf51203b1f523b837eba750f98dd88bd02d Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:37:02 -0800 Subject: [PATCH 34/43] Update portstat_test.py --- tests/portstat_test.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index a9bd992697..919de6f8eb 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -1,6 +1,6 @@ import os import shutil -import importlib + from click.testing import CliRunner import clear.main as clear @@ -511,30 +511,3 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() -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() - import show.interfaces.__init__ as show - result = runner.invoke(show.interfaces.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 4d126ef62105d6583251f15b89353056748f207c Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:24:03 -0800 Subject: [PATCH 35/43] delete change in show/interfaces/__init__.py --- show/interfaces/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index a0abaac95c..710561a810 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -540,8 +540,6 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): cmd += " -n {}".format(namespace) clicommon.run_command(cmd, display_cmd=verbose) - if multi_asic.is_multi_asic(): - click.echo("\n\nReminder: Please execute 'show interface counters -d all' to include internal links\n\n") # 'errors' subcommand ("show interfaces counters errors") From 87b35deb42fb0b0da80ddf82e0c16221630629ba Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:24:27 -0800 Subject: [PATCH 36/43] remove line --- show/interfaces/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index 710561a810..3e82a68e66 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -541,7 +541,6 @@ def counters(ctx, verbose, period, interface, printall, namespace, display): clicommon.run_command(cmd, display_cmd=verbose) - # 'errors' subcommand ("show interfaces counters errors") @counters.command() @click.option('-p', '--period') From 54d0f6298322acf56f2d118d82452da839dfa4f5 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:27:21 -0800 Subject: [PATCH 37/43] Update portstat --- scripts/portstat | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/portstat b/scripts/portstat index 3c3c5117f3..9649e91ffc 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -337,6 +337,8 @@ class Portstat(object): print(table_as_json(table, header)) else: print(tabulate(table, header, tablefmt='simple', stralign='right')) + if multi_asic.is_multi_asic(): + print("\nReminder: Please execute 'show interface counters -d all' to include internal links\n") def cnstat_intf_diff_print(self, cnstat_new_dict, cnstat_old_dict, intf_list): """ From 9657a0637ffa93e84647ff88353d1bc99b0cd7a3 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:30:37 -0800 Subject: [PATCH 38/43] Update portstat_test.py --- tests/portstat_test.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 919de6f8eb..94032b4909 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -75,6 +75,9 @@ --------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 U 8 0.00 B/s 0.00% 10 100 N/A 10 0.00 B/s 0.00% N/A N/A N/A Ethernet4 U 4 0.00 B/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_all_intf_counters = """\ @@ -86,6 +89,9 @@ Ethernet-BP4 U 8 0.00 B/s 0.00% 0 1,000 N/A 80 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP256 U 8 0.00 B/s 0.00% 10 100 N/A 10 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP260 U 4 0.00 B/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counters_asic0 = """\ IFACE STATE RX_OK RX_BPS RX_UTIL RX_ERR RX_DRP RX_OVR TX_OK TX_BPS TX_UTIL TX_ERR TX_DRP TX_OVR @@ -94,6 +100,9 @@ Ethernet4 U 4 0.00 B/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP0 U 6 0.00 B/s 0.00% 0 1,000 N/A 60 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP4 U 8 0.00 B/s 0.00% 0 1,000 N/A 80 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_external_intf_counters_printall = """\ @@ -101,6 +110,9 @@ --------- ------- ------- -------- -------- --------- -------- -------- -------- ------- -------- -------- --------- -------- -------- -------- Ethernet0 U 8 0.00 B/s 0.00/s 0.00% 10 100 N/A 10 0.00 B/s 0.00/s 0.00% N/A N/A N/A Ethernet4 U 4 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counters_printall = """\ @@ -112,6 +124,9 @@ Ethernet-BP4 U 8 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 80 0.00 B/s 0.00/s 0.00% N/A N/A N/A Ethernet-BP256 U 8 0.00 B/s 0.00/s 0.00% 10 100 N/A 10 0.00 B/s 0.00/s 0.00% N/A N/A N/A Ethernet-BP260 U 4 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counters_asic0_printall = """\ @@ -121,6 +136,9 @@ Ethernet4 U 4 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 40 0.00 B/s 0.00/s 0.00% N/A N/A N/A Ethernet-BP0 U 6 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 60 0.00 B/s 0.00/s 0.00% N/A N/A N/A Ethernet-BP4 U 8 0.00 B/s 0.00/s 0.00% 0 1,000 N/A 80 0.00 B/s 0.00/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counters_period = """\ The rates are calculated within 3 seconds period @@ -162,9 +180,6 @@ Ethernet-BP256 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A""" -multi_asic_intf_counters_reminder = """\ -Reminder: Please execute 'show interface counters -d all' to include internal links -""" intf_invalid_asic_error = """ValueError: Unknown Namespace asic99""" From 20635d74a9a3ca8c4356e2c6cb0a14c6ad61a115 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:31:28 -0800 Subject: [PATCH 39/43] add empty lines --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 07f7f81184..0a1a29f3b0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -312,7 +312,9 @@ def setup_ip_route_commands(): import show.main as show return show + @pytest.fixture def setup_fib_commands(): import show.main as show return show + From 492b0ed11a57197a24a33cc9a96689059f0dc972 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:46:31 -0800 Subject: [PATCH 40/43] remove outdated line --- tests/portstat_test.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 94032b4909..84279f7552 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -256,7 +256,6 @@ def test_show_intf_counters(self): print(result.output) assert result.exit_code == 0 assert result.output == intf_counters_before_clear - assert multi_asic_intf_counters_reminder not in result.output return_code, result = get_result_and_return_code('portstat') print("return_code: {}".format(return_code)) @@ -525,4 +524,3 @@ def teardown_class(cls): os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" remove_tmp_cnstat_file() - From ef188f95aa1d7f68cf804fe992ea13d2501f247e Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 6 Jan 2023 12:52:57 -0800 Subject: [PATCH 41/43] add print for -p option too --- scripts/portstat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/portstat b/scripts/portstat index 9649e91ffc..0e3b9c438c 100755 --- a/scripts/portstat +++ b/scripts/portstat @@ -555,7 +555,8 @@ class Portstat(object): print(table_as_json(table, header)) else: print(tabulate(table, header, tablefmt='simple', stralign='right')) - + if multi_asic.is_multi_asic(): + print("\nReminder: Please execute 'show interface counters -d all' to include internal links\n") def main(): parser = argparse.ArgumentParser(description='Display the ports state and counters', From aeb925ad514a29578fd02ad1f47e085b7bb28bb8 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 6 Jan 2023 12:53:36 -0800 Subject: [PATCH 42/43] Update portstat_test.py --- tests/portstat_test.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 84279f7552..64fc87f0fa 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -146,6 +146,9 @@ --------- ------- ------- -------- --------- -------- -------- -------- ------- -------- --------- -------- -------- -------- Ethernet0 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counters_period_all = """\ @@ -158,6 +161,9 @@ Ethernet-BP4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP256 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ multi_asic_intf_counter_period_asic_all = """\ @@ -168,6 +174,9 @@ Ethernet4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP0 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + """ mutli_asic_intf_counters_after_clear = """\ @@ -178,7 +187,11 @@ Ethernet-BP0 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP4 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Ethernet-BP256 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A -Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A""" +Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A + +Reminder: Please execute 'show interface counters -d all' to include internal links + +""" intf_invalid_asic_error = """ValueError: Unknown Namespace asic99""" From c56017c8b15956332db003b72f94b6b46e6fed97 Mon Sep 17 00:00:00 2001 From: wenyiz2021 <91497961+wenyiz2021@users.noreply.github.com> Date: Fri, 6 Jan 2023 14:32:29 -0800 Subject: [PATCH 43/43] syntax fix --- tests/portstat_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/portstat_test.py b/tests/portstat_test.py index 64fc87f0fa..d418a16feb 100644 --- a/tests/portstat_test.py +++ b/tests/portstat_test.py @@ -190,7 +190,6 @@ Ethernet-BP260 U 0 0.00 B/s 0.00% 0 0 N/A 0 0.00 B/s 0.00% N/A N/A N/A Reminder: Please execute 'show interface counters -d all' to include internal links - """