diff --git a/tests/common/constants.py b/tests/common/constants.py index 6b8fbbbbe09..796e93731d9 100644 --- a/tests/common/constants.py +++ b/tests/common/constants.py @@ -17,3 +17,45 @@ "public": [] } KVM_PLATFORM = 'x86_64-kvm_x86_64-r0' + + +class CounterpollConstants: + COUNTERPOLL_SHOW = 'counterpoll show' + COUNTERPOLL_DISABLE = 'counterpoll {} disable' + COUNTERPOLL_ENABLE = 'counterpoll {} enable' + COUNTERPOLL_RESTORE = 'counterpoll {} {}' + COUNTERPOLL_INTERVAL_STR = 'counterpoll {} interval {}' + COUNTERPOLL_QUEST = 'counterpoll --help' + EXCLUDE_COUNTER_SUB_COMMAND = ['show', 'config-db', "flowcnt-trap", "tunnel"] + INTERVAL = 'interval (in ms)' + TYPE = 'type' + STATUS = 'status' + STDOUT = 'stdout' + PG_DROP = 'pg-drop' + PG_DROP_STAT_TYPE = 'PG_DROP_STAT' + QUEUE_STAT_TYPE = 'QUEUE_STAT' + QUEUE = 'queue' + PORT_STAT_TYPE = 'PORT_STAT' + PORT = 'port' + PORT_BUFFER_DROP_TYPE = 'PORT_BUFFER_DROP' + PORT_BUFFER_DROP = 'port-buffer-drop' + RIF_STAT_TYPE = 'RIF_STAT' + RIF = 'rif' + WATERMARK = 'watermark' + QUEUE_WATERMARK_STAT_TYPE = 'QUEUE_WATERMARK_STAT' + PG_WATERMARK_STAT_TYPE = 'PG_WATERMARK_STAT' + BUFFER_POOL_WATERMARK_STAT_TYPE = 'BUFFER_POOL_WATERMARK_STAT' + ACL = 'acl' + ACL_TYPE = "ACL" + COUNTERPOLL_MAPPING = {PG_DROP_STAT_TYPE: PG_DROP, + QUEUE_STAT_TYPE: QUEUE, + PORT_STAT_TYPE: PORT, + PORT_BUFFER_DROP_TYPE: PORT_BUFFER_DROP, + RIF_STAT_TYPE: RIF, + BUFFER_POOL_WATERMARK_STAT_TYPE: WATERMARK, + QUEUE_WATERMARK_STAT_TYPE: WATERMARK, + PG_WATERMARK_STAT_TYPE: WATERMARK, + ACL_TYPE: ACL} + PORT_BUFFER_DROP_INTERVAL = '10000' + COUNTERPOLL_INTERVAL = {PORT_BUFFER_DROP: 10000} + SX_SDK = 'sx_sdk' diff --git a/tests/platform_tests/counterpoll/counterpoll_helper.py b/tests/common/helpers/counterpoll_helper.py similarity index 96% rename from tests/platform_tests/counterpoll/counterpoll_helper.py rename to tests/common/helpers/counterpoll_helper.py index 199ab5e99dc..cd86bae78bf 100644 --- a/tests/platform_tests/counterpoll/counterpoll_helper.py +++ b/tests/common/helpers/counterpoll_helper.py @@ -1,4 +1,4 @@ -from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants +from tests.common.constants import CounterpollConstants class ConterpollHelper: diff --git a/tests/common/utilities.py b/tests/common/utilities.py index 7ae4275f2c8..68ba879401d 100644 --- a/tests/common/utilities.py +++ b/tests/common/utilities.py @@ -36,6 +36,7 @@ from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, UPSTREAM_ALL_NEIGHBOR_MAP from tests.common.helpers.constants import DOWNSTREAM_NEIGHBOR_MAP, DOWNSTREAM_ALL_NEIGHBOR_MAP from tests.common.helpers.assertions import pytest_assert +from tests.common.portstat_utilities import parse_column_positions from netaddr import valid_ipv6 logger = logging.getLogger(__name__) @@ -1549,3 +1550,50 @@ def cleanup_prev_images(duthost): current_os_version = duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout'] duthost.shell("sonic_installer set-next-boot {}".format(current_os_version), module_ignore_errors=True) duthost.shell("sonic_installer cleanup -y", module_ignore_errors=True) + + +def parse_rif_counters(output_lines): + """Parse the output of "show interfaces counters rif" command + Args: + output_lines (list): The output lines of "show interfaces counters rif" command + Returns: + list: A dictionary, key is interface name, value is a dictionary of fields/values + """ + + header_line = '' + separation_line = '' + separation_line_number = 0 + for idx, line in enumerate(output_lines): + if line.find('----') >= 0: + header_line = output_lines[idx - 1] + separation_line = output_lines[idx] + separation_line_number = idx + break + + try: + positions = parse_column_positions(separation_line) + except Exception: + logger.error('Possibly bad command output') + return {} + + headers = [] + for pos in positions: + header = header_line[pos[0]:pos[1]].strip().lower() + headers.append(header) + + if not headers: + return {} + + results = {} + for line in output_lines[separation_line_number + 1:]: + portstats = [] + for pos in positions: + portstat = line[pos[0]:pos[1]].strip() + portstats.append(portstat) + + intf = portstats[0] + results[intf] = {} + for idx in range(1, len(portstats)): # Skip the first column interface name + results[intf][headers[idx]] = portstats[idx].replace(',', '') + + return results diff --git a/tests/ip/ip_util.py b/tests/ip/ip_util.py index 978c4385f6c..670de01e9f9 100644 --- a/tests/ip/ip_util.py +++ b/tests/ip/ip_util.py @@ -1,7 +1,6 @@ import random import re import logging -from tests.common.portstat_utilities import parse_column_positions logger = logging.getLogger(__name__) @@ -36,53 +35,6 @@ def parse_interfaces(output_lines, pc_ports_map): return route_targets, ifaces -def parse_rif_counters(output_lines): - """Parse the output of "show interfaces counters rif" command - Args: - output_lines (list): The output lines of "show interfaces counters rif" command - Returns: - list: A dictionary, key is interface name, value is a dictionary of fields/values - """ - - header_line = '' - separation_line = '' - separation_line_number = 0 - for idx, line in enumerate(output_lines): - if line.find('----') >= 0: - header_line = output_lines[idx - 1] - separation_line = output_lines[idx] - separation_line_number = idx - break - - try: - positions = parse_column_positions(separation_line) - except Exception: - logger.error('Possibly bad command output') - return {} - - headers = [] - for pos in positions: - header = header_line[pos[0]:pos[1]].strip().lower() - headers.append(header) - - if not headers: - return {} - - results = {} - for line in output_lines[separation_line_number + 1:]: - portstats = [] - for pos in positions: - portstat = line[pos[0]:pos[1]].strip() - portstats.append(portstat) - - intf = portstats[0] - results[intf] = {} - for idx in range(1, len(portstats)): # Skip the first column interface name - results[intf][headers[idx]] = portstats[idx].replace(',', '') - - return results - - def random_mac(): return "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255), random.randint(0, 255), diff --git a/tests/ip/link_local/test_link_local_ip.py b/tests/ip/link_local/test_link_local_ip.py index 71198e3249f..342ea54678c 100644 --- a/tests/ip/link_local/test_link_local_ip.py +++ b/tests/ip/link_local/test_link_local_ip.py @@ -13,7 +13,8 @@ from tests.common import utilities from tests.common.helpers.assertions import pytest_assert from tests.common.portstat_utilities import parse_portstat -from tests.ip.ip_util import parse_rif_counters, sum_ifaces_counts +from tests.common.utilities import parse_rif_counters +from tests.ip.ip_util import sum_ifaces_counts pytestmark = [ pytest.mark.topology('any') diff --git a/tests/ip/test_ip_packet.py b/tests/ip/test_ip_packet.py index 65737f45770..6cc46dc1068 100644 --- a/tests/ip/test_ip_packet.py +++ b/tests/ip/test_ip_packet.py @@ -10,7 +10,8 @@ from tests.common.helpers.assertions import pytest_assert from tests.common.portstat_utilities import parse_portstat from tests.common.helpers.dut_utils import is_mellanox_fanout -from tests.ip.ip_util import parse_interfaces, parse_rif_counters, sum_ifaces_counts, random_mac +from tests.common.utilities import parse_rif_counters +from tests.ip.ip_util import parse_interfaces, sum_ifaces_counts, random_mac pytestmark = [ diff --git a/tests/platform_tests/counterpoll/counterpoll_constants.py b/tests/platform_tests/counterpoll/counterpoll_constants.py deleted file mode 100644 index bef7879d464..00000000000 --- a/tests/platform_tests/counterpoll/counterpoll_constants.py +++ /dev/null @@ -1,41 +0,0 @@ - -class CounterpollConstants: - COUNTERPOLL_SHOW = 'counterpoll show' - COUNTERPOLL_DISABLE = 'counterpoll {} disable' - COUNTERPOLL_ENABLE = 'counterpoll {} enable' - COUNTERPOLL_RESTORE = 'counterpoll {} {}' - COUNTERPOLL_INTERVAL_STR = 'counterpoll {} interval {}' - COUNTERPOLL_QUEST = 'counterpoll --help' - EXCLUDE_COUNTER_SUB_COMMAND = ['show', 'config-db', "flowcnt-trap", "tunnel"] - INTERVAL = 'interval (in ms)' - TYPE = 'type' - STATUS = 'status' - STDOUT = 'stdout' - PG_DROP = 'pg-drop' - PG_DROP_STAT_TYPE = 'PG_DROP_STAT' - QUEUE_STAT_TYPE = 'QUEUE_STAT' - QUEUE = 'queue' - PORT_STAT_TYPE = 'PORT_STAT' - PORT = 'port' - PORT_BUFFER_DROP_TYPE = 'PORT_BUFFER_DROP' - PORT_BUFFER_DROP = 'port-buffer-drop' - RIF_STAT_TYPE = 'RIF_STAT' - RIF = 'rif' - WATERMARK = 'watermark' - QUEUE_WATERMARK_STAT_TYPE = 'QUEUE_WATERMARK_STAT' - PG_WATERMARK_STAT_TYPE = 'PG_WATERMARK_STAT' - BUFFER_POOL_WATERMARK_STAT_TYPE = 'BUFFER_POOL_WATERMARK_STAT' - ACL = 'acl' - ACL_TYPE = "ACL" - COUNTERPOLL_MAPPING = {PG_DROP_STAT_TYPE: PG_DROP, - QUEUE_STAT_TYPE: QUEUE, - PORT_STAT_TYPE: PORT, - PORT_BUFFER_DROP_TYPE: PORT_BUFFER_DROP, - RIF_STAT_TYPE: RIF, - BUFFER_POOL_WATERMARK_STAT_TYPE: WATERMARK, - QUEUE_WATERMARK_STAT_TYPE: WATERMARK, - PG_WATERMARK_STAT_TYPE: WATERMARK, - ACL_TYPE: ACL} - PORT_BUFFER_DROP_INTERVAL = '10000' - COUNTERPOLL_INTERVAL = {PORT_BUFFER_DROP: 10000} - SX_SDK = 'sx_sdk' diff --git a/tests/platform_tests/counterpoll/cpu_memory_helper.py b/tests/platform_tests/counterpoll/cpu_memory_helper.py index 0bdd249ad55..6a4eaeb30eb 100644 --- a/tests/platform_tests/counterpoll/cpu_memory_helper.py +++ b/tests/platform_tests/counterpoll/cpu_memory_helper.py @@ -1,7 +1,7 @@ import pytest -from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants -from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper +from tests.common.constants import CounterpollConstants +from tests.common.helpers.counterpoll_helper import ConterpollHelper from tests.common.utilities import skip_release diff --git a/tests/platform_tests/counterpoll/test_counterpoll_watermark.py b/tests/platform_tests/counterpoll/test_counterpoll_watermark.py index 77fc2019e5e..30f0124537d 100644 --- a/tests/platform_tests/counterpoll/test_counterpoll_watermark.py +++ b/tests/platform_tests/counterpoll/test_counterpoll_watermark.py @@ -9,13 +9,13 @@ import pytest from tests.common.config_reload import config_reload +from tests.common.constants import CounterpollConstants from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.counterpoll_helper import ConterpollHelper from tests.common.helpers.sonic_db import SonicDbCli, SonicDbKeyNotFound from tests.common.utilities import get_inventory_files, get_host_visible_vars from tests.common.utilities import skip_release, wait_until from tests.common.reboot import reboot -from .counterpoll_constants import CounterpollConstants -from .counterpoll_helper import ConterpollHelper pytestmark = [ pytest.mark.sanity_check(skip_sanity=True), diff --git a/tests/platform_tests/test_cpu_memory_usage.py b/tests/platform_tests/test_cpu_memory_usage.py index 1eddd0b7a3b..5b171144ef5 100644 --- a/tests/platform_tests/test_cpu_memory_usage.py +++ b/tests/platform_tests/test_cpu_memory_usage.py @@ -4,8 +4,8 @@ from collections import namedtuple, Counter from tests.platform_tests.counterpoll.cpu_memory_helper import restore_counter_poll # noqa: F401 from tests.platform_tests.counterpoll.cpu_memory_helper import counterpoll_type # noqa: F401 -from tests.platform_tests.counterpoll.counterpoll_helper import ConterpollHelper -from tests.platform_tests.counterpoll.counterpoll_constants import CounterpollConstants +from tests.common.constants import CounterpollConstants +from tests.common.helpers.counterpoll_helper import ConterpollHelper from tests.common.mellanox_data import is_mellanox_device from tests.common.utilities import wait_until from tests.common.helpers.assertions import pytest_assert diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index 151f5e1ceef..b6daa55a741 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -2,6 +2,9 @@ import pytest from tests.common.helpers.assertions import pytest_assert from tests.common.helpers.snmp_helpers import get_snmp_facts +from tests.common.constants import CounterpollConstants +from tests.common.helpers.counterpoll_helper import ConterpollHelper +from tests.common.utilities import parse_rif_counters, wait_until pytestmark = [ pytest.mark.topology('any'), @@ -10,6 +13,86 @@ logger = logging.getLogger(__name__) +SAI_PORT_STAT_IF_IN_ERRORS = 'SAI_PORT_STAT_IF_IN_ERRORS' +SAI_PORT_STAT_IF_OUT_ERRORS = 'SAI_PORT_STAT_IF_OUT_ERRORS' +SAI_PORT_STAT_IF_IN_DISCARDS = 'SAI_PORT_STAT_IF_IN_DISCARDS' +SAI_PORT_STAT_IF_OUT_DISCARDS = 'SAI_PORT_STAT_IF_OUT_DISCARDS' +SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS = 'SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS' +SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS = 'SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS' + +COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP' +COUNTERS_RIF_NAME_MAP = 'COUNTERS_RIF_NAME_MAP' +COUNTER_VALUE = 5000 + + +@pytest.fixture() +def disable_conterpoll(duthost): + """ + Disable conterpoll for RIF and PORT and re-enable it when TC finished + :param duthost: DUT host object + :return: dict with data collected from DUT per each port + """ + ConterpollHelper.disable_counterpoll(duthost, counter_type_list=[CounterpollConstants.PORT, + CounterpollConstants.RIF]) + yield + ConterpollHelper.enable_counterpoll(duthost, counter_type_list=[CounterpollConstants.PORT, + CounterpollConstants.RIF]) + + +def get_interfaces(duthost, tbinfo): + """ + Method to get interfaces for testing + :param duthost: DUT host object + :return: RIF interface name in case available in topo. If not - return Port Channel name and interface in Port + Channel + """ + rif_counters = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"]) + for interface in rif_counters: + if 'Eth' in interface: + return interface, interface + else: + mg_facts = duthost.get_extended_minigraph_facts(tbinfo) + return mg_facts["minigraph_portchannels"][interface]['members'][0], interface + + +def get_oid_for_interface(duthost, table_name, interface_name): + """ + Method to get interface oid from Counters DB + :param duthost: DUT host object + :param table_name: table name + :param interface_name: interface name + :return: oid for specific interface + """ + return duthost.command(f"docker exec -i database redis-cli --raw -n 2 HMGET " + f"{table_name} {interface_name}")["stdout"] + + +def set_counters_value(duthost, interface_oid, counter_name, counter_value): + """ + Method to set interface counter value in Counters DB + :param duthost: DUT host object + :param interface_oid: oid value + :param counter_name: counter name + :param counter_value: counter value + """ + duthost.command(f"sudo redis-cli -n 2 hset COUNTERS:{interface_oid} {counter_name} {counter_value}") + + +def get_port_interface_counter(duthost, interface_name): + """ + Method to set interface counter value in Counters DB + :param duthost: DUT host object + :param interface_name: name of interface to collect counters + :return : dict with counters + """ + port_counters = duthost.show_and_parse("show interfaces counters") + for port_counter in port_counters: + if port_counter['iface'] == interface_name: + for key, value in port_counter.items(): + if ',' in value: + port_counter[key] = value.replace(',', '') + return port_counter + def collect_all_facts(duthost, ports_list, namespace=None): """ @@ -157,6 +240,40 @@ def verify_snmp_speed(facts, snmp_facts, results): return results +def verify_snmp_counter(duthost, localhost, creds_all_duts, hostip, mg_facts, rif_interface, rif_counters, + port_counters): + """ + Verify correct correctness of snmp counter + """ + snmp_facts = get_snmp_facts( + duthost, localhost, host=hostip, version="v2c", + community=creds_all_duts[duthost.hostname]["snmp_rocommunity"], wait=True)['ansible_facts'] + + minigraph_port_name_to_alias_map = mg_facts['minigraph_port_name_to_alias_map'] + snmp_port_map = {snmp_facts['snmp_interfaces'][idx]['name']: idx for idx in snmp_facts['snmp_interfaces']} + interface = rif_interface if 'PortChannel' in rif_interface else minigraph_port_name_to_alias_map[rif_interface] + rif_snmp_facts = snmp_facts['snmp_interfaces'][snmp_port_map[interface]] + + if (int(rif_snmp_facts['ifInDiscards']) != int(rif_counters[rif_interface]['rx_err']) + + int(port_counters['rx_drp'])): + logger.info(f"ifInDiscards value is {rif_snmp_facts['ifInDiscards']} but must be " + f"{int(rif_counters[rif_interface]['rx_err']) + int(port_counters['rx_drp'])}") + return False + if (int(rif_snmp_facts['ifOutDiscards']) != int(rif_counters[rif_interface]['tx_err']) + + int(port_counters['tx_drp'])): + logger.info(f"ifOutDiscards value is {rif_snmp_facts['ifOutDiscards']} but must be " + f"{int(rif_counters[rif_interface]['tx_err']) + int(port_counters['tx_drp'])}") + return False + if int(rif_snmp_facts['ifInErrors']) != COUNTER_VALUE: + logger.info(f"ifInErrors value is {rif_snmp_facts['ifInErrors']} but must be {COUNTER_VALUE}") + return False + if int(rif_snmp_facts['ifOutErrors']) != COUNTER_VALUE: + logger.info(f"ifOutErrors value is {rif_snmp_facts['ifOutErrors']} but must be {COUNTER_VALUE}") + return False + + return True + + @pytest.mark.bsl def test_snmp_interfaces(localhost, creds_all_duts, duthosts, enum_rand_one_per_hwsku_hostname): """compare the snmp facts between observed states and target state""" @@ -244,3 +361,65 @@ def test_snmp_interfaces_mibs(duthosts, enum_rand_one_per_hwsku_hostname, localh result = verify_port_ifindex(snmp_facts, speed_snmp) pytest_assert( not result, "Unexpected comparsion of SNMP: {}".format(result)) + + +def test_snmp_interfaces_error_discard(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_all_duts, + enum_asic_index, disable_conterpoll, tbinfo, mg_facts): + """Verify correct behaviour of port MIBs ifInError, ifOutError, IfInDiscards, IfOutDiscards """ + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + hostip = duthost.host.options['inventory_manager'].get_host( + duthost.hostname).vars['ansible_host'] + port_interface, rif_interface = get_interfaces(duthost, tbinfo) + logger.info(f'Selected interfaces: port {port_interface}, rif {rif_interface}') + # Get interfaces oid + port_oid = get_oid_for_interface(duthost, COUNTERS_PORT_NAME_MAP, port_interface) + rif_oid = get_oid_for_interface(duthost, COUNTERS_RIF_NAME_MAP, rif_interface) + # Clear the counters from the cache to make test stable + # if "sonic-clear counters" was done before the test, /tmp/cache/intfstat and /tmp/cache/portstat will be created. + # if /tmp/cache/portstat exist, show interfaces counters will calculate the counters that get from redis-db and the + # value saved in the cache file. then the value will not be the number that get from the redis db + # if /tmp/cache/intfstat exist, show interfaces counters rif will calculate the counters that get from redis-db and + # the value saved in the cache file. then the value will not be the number that get from the redis db + # Clear the cache file to make sure that the "show interfaces counters" and "show interfaces counters rif" return + # the number that set in the redis-db. + duthost.shell("rm -rf /tmp/cache/intfstat", module_ignore_errors=True) + duthost.shell("rm -rf /tmp/cache/portstat", module_ignore_errors=True) + + logger.info('Set port and rif counters in COUNTERS DB') + logger.info(f'Set port {port_interface} {SAI_PORT_STAT_IF_IN_ERRORS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, port_oid, SAI_PORT_STAT_IF_IN_ERRORS, COUNTER_VALUE) + logger.info(f'Set port {port_interface} {SAI_PORT_STAT_IF_IN_DISCARDS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, port_oid, SAI_PORT_STAT_IF_IN_DISCARDS, COUNTER_VALUE) + logger.info(f'Set port {rif_interface} {SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, rif_oid, SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS, COUNTER_VALUE) + logger.info(f'Set port {port_interface} {SAI_PORT_STAT_IF_OUT_DISCARDS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, port_oid, SAI_PORT_STAT_IF_OUT_DISCARDS, COUNTER_VALUE) + logger.info(f'Set port {rif_interface} {SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, rif_oid, SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS, COUNTER_VALUE) + logger.info(f'Set port {port_interface} {SAI_PORT_STAT_IF_OUT_ERRORS} counter to {COUNTER_VALUE}') + set_counters_value(duthost, port_oid, SAI_PORT_STAT_IF_OUT_ERRORS, COUNTER_VALUE) + + rif_counters = parse_rif_counters(duthost.command("show interfaces counters rif")["stdout_lines"]) + port_counters = get_port_interface_counter(duthost, port_interface) + + logger.info('Compare rif counters in COUNTERS DB and counters get from SONiC CLI') + assert int(rif_counters[rif_interface]['tx_err']) == COUNTER_VALUE, \ + f"tx_err value is {rif_counters[rif_interface]['tx_err']} not set to {COUNTER_VALUE}" + assert int(rif_counters[rif_interface]['rx_err']) == COUNTER_VALUE, \ + f"rx_err value is {rif_counters[rif_interface]['rx_err']} not set to {COUNTER_VALUE}" + + logger.info('Compare port counters in COUNTERS DB and counters get from SONiC CLI') + assert int(port_counters['tx_err']) == COUNTER_VALUE, \ + f"tx_err value is {port_counters['tx_err']} not set to {COUNTER_VALUE}" + assert int(port_counters['rx_err']) == COUNTER_VALUE, \ + f"rx_err value is {port_counters['rx_err']} not set to {COUNTER_VALUE}" + assert int(port_counters['tx_drp']) == COUNTER_VALUE, \ + f"tx_drp value is {port_counters['tx_drp']} not set to {COUNTER_VALUE}" + assert int(port_counters['rx_drp']) == COUNTER_VALUE, \ + f"rx_drp value is {port_counters['rx_drp']} not set to {COUNTER_VALUE}" + + pytest_assert(wait_until(60, 10, 0, verify_snmp_counter, duthost, localhost, creds_all_duts, hostip, mg_facts, + rif_interface, rif_counters, port_counters), "SNMP counter validate Failure") + # clear all counters after the test + duthost.shell('sonic-clear counters') + duthost.shell('sonic-clear rifcounters')