Skip to content

Commit 7b0548f

Browse files
[test_iface_namingmode] Adjusted the test according to the new buffer queue/pg counters optimization (#6431)
Signed-off-by: Vadym Hlushko <[email protected]> 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
1 parent 2025935 commit 7b0548f

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

tests/common/helpers/sonic_db.py

+15
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,18 @@ class SonicDbNoCommandOutput(Exception):
539539
Raised when no output is generated by the sonic-db-cli command.
540540
"""
541541
pass
542+
543+
544+
def redis_get_keys(duthost, db_id, pattern):
545+
"""
546+
Get all keys for a given pattern in given redis database
547+
:param duthost: DUT host object
548+
:param db_id: ID of redis database
549+
:param pattern: Redis key pattern
550+
:return: A list of key name in string
551+
"""
552+
cmd = 'sonic-db-cli {} KEYS \"{}\"'.format(db_id, pattern)
553+
logger.debug('Getting keys from redis by command: {}'.format(cmd))
554+
output = duthost.shell(cmd)
555+
content = output['stdout'].strip()
556+
return content.split('\n') if content else None

tests/iface_namingmode/test_iface_namingmode.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from tests.common.utilities import wait, wait_until
77
from netaddr import IPAddress
88
from tests.common.helpers.assertions import pytest_assert
9+
from tests.common.helpers.sonic_db import redis_get_keys
910

1011
pytestmark = [
1112
pytest.mark.topology('any')
@@ -430,7 +431,7 @@ def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
430431
skip_test_for_multi_asic(
431432
duthosts, enum_rand_one_per_hwsku_frontend_hostname)
432433

433-
def test_show_queue_counters(self, setup, setup_config_mode):
434+
def test_show_queue_counters(self, setup, setup_config_mode, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
434435
"""
435436
Checks whether 'show queue counters' lists the interface names as
436437
per the configured naming mode
@@ -439,11 +440,22 @@ def test_show_queue_counters(self, setup, setup_config_mode):
439440
queue_counter = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show queue counters | grep "UC\|MC\|ALL"'.format(ifmode))['stdout']
440441
logger.info('queue_counter:\n{}'.format(queue_counter))
441442

443+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
444+
buffer_queue_keys = redis_get_keys(duthost, 'CONFIG_DB', 'BUFFER_QUEUE|*')
445+
interfaces = set()
446+
447+
for key in buffer_queue_keys:
448+
try:
449+
interfaces.add(key.split('|')[1])
450+
except IndexError:
451+
pass
452+
442453
if mode == 'alias':
443-
for alias in setup['port_alias']:
454+
for intf in interfaces:
455+
alias = setup['port_name_map'][intf]
444456
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)
445457
elif mode == 'default':
446-
for intf in setup['default_interfaces']:
458+
for intf in interfaces:
447459
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)
448460

449461
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
468480
show_queue_wm_mcast = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show queue persistent-watermark multicast'.format(ifmode))['stdout']
469481
logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast))
470482

471-
if mode == 'alias':
472-
for alias in setup['port_alias']:
473-
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
474-
elif mode == 'default':
475-
for intf in setup['default_interfaces']:
476-
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
483+
if show_queue_wm_mcast != "Object map from the COUNTERS_DB is empty because the multicast queues are not configured in the CONFIG_DB!":
484+
if mode == 'alias':
485+
for alias in setup['port_alias']:
486+
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
487+
elif mode == 'default':
488+
for intf in setup['default_interfaces']:
489+
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
477490

478491
def test_show_queue_persistent_watermark_unicast(self, setup, setup_config_mode):
479492
"""
@@ -500,12 +513,13 @@ def test_show_queue_watermark_multicast(self, setup, setup_config_mode):
500513
show_queue_wm_mcast = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} show queue watermark multicast'.format(ifmode))['stdout']
501514
logger.info('show_queue_wm_mcast:\n{}'.format(show_queue_wm_mcast))
502515

503-
if mode == 'alias':
504-
for alias in setup['port_alias']:
505-
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
506-
elif mode == 'default':
507-
for intf in setup['default_interfaces']:
508-
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
516+
if show_queue_wm_mcast != "Object map from the COUNTERS_DB is empty because the multicast queues are not configured in the CONFIG_DB!":
517+
if mode == 'alias':
518+
for alias in setup['port_alias']:
519+
assert re.search(r'{}'.format(alias), show_queue_wm_mcast) is not None
520+
elif mode == 'default':
521+
for intf in setup['default_interfaces']:
522+
assert re.search(r'{}'.format(intf), show_queue_wm_mcast) is not None
509523

510524
def test_show_queue_watermark_unicast(self, setup, setup_config_mode):
511525
"""

tests/snmp/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)