Skip to content

Commit

Permalink
[test_iface_namingmode] Adjusted the test according to the new buffer…
Browse files Browse the repository at this point in the history
… queue/pg counters optimization (#6431)

Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>

What is the motivation for this PR?
Because of the new implementation sonic-swss/pull/2432 from now on, there is a valid case if there are no multicast counters inside the COUNTERS_DB.

In order for multicast counters to be presented in COUNTERS_DB the appropriate queues should be configured inside the CONFIG_DB (e.g "BUFFER_QUEUE|Ethernet14|7-8")

How did you do it?
Change the testcases - test_show_queue_counters, test_show_queue_persistent_watermark_multicast, test_show_queue_watermark_multicast
  • Loading branch information
vadymhlushko-mlnx authored and wangxin committed Oct 21, 2022
1 parent fd85514 commit 832813a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
15 changes: 15 additions & 0 deletions tests/common/helpers/sonic_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 29 additions & 15 deletions tests/iface_namingmode/test_iface_namingmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
Empty file added tests/snmp/__init__.py
Empty file.

0 comments on commit 832813a

Please sign in to comment.