diff --git a/tests/common/helpers/sonic_db.py b/tests/common/helpers/sonic_db.py index a61ddf68e22..b506c48b77b 100644 --- a/tests/common/helpers/sonic_db.py +++ b/tests/common/helpers/sonic_db.py @@ -539,3 +539,18 @@ class SonicDbNoCommandOutput(Exception): Raised when no output is generated by the sonic-db-cli command. """ pass + + +def redis_get_keys(duthost, db_id, pattern): + """ + Get all keys for a given pattern in given redis database + :param duthost: DUT host object + :param db_id: ID of redis database + :param pattern: Redis key pattern + :return: A list of key name in string + """ + cmd = 'sonic-db-cli {} KEYS \"{}\"'.format(db_id, pattern) + logger.debug('Getting keys from redis by command: {}'.format(cmd)) + output = duthost.shell(cmd) + content = output['stdout'].strip() + return content.split('\n') if content else None diff --git a/tests/iface_namingmode/test_iface_namingmode.py b/tests/iface_namingmode/test_iface_namingmode.py index 2c9290f4329..695ee811196 100644 --- a/tests/iface_namingmode/test_iface_namingmode.py +++ b/tests/iface_namingmode/test_iface_namingmode.py @@ -6,6 +6,7 @@ from tests.common.utilities import wait, wait_until from netaddr import IPAddress from tests.common.helpers.assertions import pytest_assert +from tests.common.helpers.sonic_db import redis_get_keys pytestmark = [ pytest.mark.topology('any') @@ -430,7 +431,7 @@ def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname): skip_test_for_multi_asic( duthosts, enum_rand_one_per_hwsku_frontend_hostname) - def test_show_queue_counters(self, setup, setup_config_mode): + def test_show_queue_counters(self, setup, setup_config_mode, duthosts, enum_rand_one_per_hwsku_frontend_hostname): """ Checks whether 'show queue counters' lists the interface names as per the configured naming mode @@ -439,11 +440,22 @@ def test_show_queue_counters(self, setup, setup_config_mode): queue_counter = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show queue counters | grep "UC\|MC\|ALL"'.format(ifmode))['stdout'] logger.info('queue_counter:\n{}'.format(queue_counter)) + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] + buffer_queue_keys = redis_get_keys(duthost, 'CONFIG_DB', 'BUFFER_QUEUE|*') + interfaces = set() + + for key in buffer_queue_keys: + try: + interfaces.add(key.split('|')[1]) + except IndexError: + pass + if mode == 'alias': - for alias in setup['port_alias']: + for intf in interfaces: + alias = setup['port_name_map'][intf] assert (re.search(r'{}\s+[U|M]C|ALL\d\s+\S+\s+\S+\s+\S+\s+\S+'.format(alias), queue_counter) is not None) and (setup['port_alias_map'][alias] not in queue_counter) elif mode == 'default': - for intf in setup['default_interfaces']: + for intf in interfaces: assert (re.search(r'{}\s+[U|M]C|ALL\d\s+\S+\s+\S+\s+\S+\s+\S+'.format(intf), queue_counter) is not None) and (setup['port_name_map'][intf] not in queue_counter) def test_show_queue_counters_interface(self, setup_config_mode, sample_intf): @@ -468,12 +480,13 @@ def test_show_queue_persistent_watermark_multicast(self, setup, setup_config_mod show_queue_wm_mcast = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show queue persistent-watermark multicast'.format(ifmode))['stdout'] logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast)) - if mode == 'alias': - for alias in setup['port_alias']: - assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None - elif mode == 'default': - for intf in setup['default_interfaces']: - assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None + if show_queue_wm_mcast != "Object map from the COUNTERS_DB is empty because the multicast queues are not configured in the CONFIG_DB!": + if mode == 'alias': + for alias in setup['port_alias']: + assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None + elif mode == 'default': + for intf in setup['default_interfaces']: + assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None def test_show_queue_persistent_watermark_unicast(self, setup, setup_config_mode): """ @@ -500,12 +513,13 @@ def test_show_queue_watermark_multicast(self, setup, setup_config_mode): show_queue_wm_mcast = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show queue watermark multicast'.format(ifmode))['stdout'] logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast)) - if mode == 'alias': - for alias in setup['port_alias']: - assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None - elif mode == 'default': - for intf in setup['default_interfaces']: - assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None + if show_queue_wm_mcast != "Object map from the COUNTERS_DB is empty because the multicast queues are not configured in the CONFIG_DB!": + if mode == 'alias': + for alias in setup['port_alias']: + assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None + elif mode == 'default': + for intf in setup['default_interfaces']: + assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None def test_show_queue_watermark_unicast(self, setup, setup_config_mode): """ diff --git a/tests/snmp/__init__.py b/tests/snmp/__init__.py new file mode 100644 index 00000000000..e69de29bb2d