Skip to content

Commit bebcf75

Browse files
ausphamnnelluri-cisco
authored andcommitted
Fix multiasic testgap for iface_namingmode (sonic-net#17045)
Description of PR Summary: Add support for multi-asic compatible for this tests. This PR requires sonic-net/sonic-utilities#3781 to be merged as it's support -n <namespace> Fixes # (issue) 28837145 Approach What is the motivation for this PR? Described above How did you do it? Utility improvement: sonic-net/sonic-utilities#3781 Use namespace to get the information so that it's compatible with multi-asic. Enabled internal port when querying for port_alias_fact which was disabled before for compatibility How did you verify/test it? T2 testbed verified Signed-off-by: Austin Pham <austinpham@microsoft.com>
1 parent e825775 commit bebcf75

2 files changed

Lines changed: 81 additions & 71 deletions

File tree

tests/common/helpers/sonic_db.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_and_check_key_value(self, key, value, field=None):
147147
else:
148148
raise AssertionError("sonic-db value error: %s != %s key was: %s" % (result, value, key))
149149

150-
def get_keys(self, table):
150+
def get_keys(self, table, raise_error_when_not_found=True):
151151
"""
152152
Gets the list of keys in a table.
153153
@@ -164,7 +164,9 @@ def get_keys(self, table):
164164
cmd = self._cli_prefix() + " keys {}".format(table)
165165
result = self._run_and_check(cmd)
166166
if result == {}:
167-
raise SonicDbKeyNotFound("No keys for %s found in sonic-db cmd: %s" % (table, cmd))
167+
if raise_error_when_not_found:
168+
raise SonicDbKeyNotFound("No keys for %s found in sonic-db cmd: %s" % (table, cmd))
169+
return []
168170
else:
169171
if six.PY2:
170172
return result['stdout'].decode('unicode-escape').splitlines()

tests/iface_namingmode/test_iface_namingmode.py

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.common.utilities import wait, wait_until
88
from netaddr import IPAddress
99
from tests.common.helpers.assertions import pytest_assert
10-
from tests.common.helpers.sonic_db import redis_get_keys
10+
from tests.common.helpers.sonic_db import SonicDbCli
1111

1212
pytestmark = [
1313
pytest.mark.topology('any', "t1-multi-asic")
@@ -20,12 +20,6 @@
2020
QUEUE_COUNTERS_RE_FMT = r'{}\s+[U|M]C|ALL\d\s+\S+\s+\S+\s+\S+\s+\S+'
2121

2222

23-
def skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname):
24-
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
25-
if duthost.is_multi_asic:
26-
pytest.skip('CLI command not supported')
27-
28-
2923
@pytest.fixture(autouse=True)
3024
def ignore_expected_loganalyzer_exception(duthosts, enum_rand_one_per_hwsku_frontend_hostname, loganalyzer):
3125
if loganalyzer:
@@ -51,7 +45,7 @@ def setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, tbinfo):
5145

5246
hwsku = duthost.facts['hwsku']
5347
minigraph_facts = duthost.get_extended_minigraph_facts(tbinfo)
54-
port_alias_facts = duthost.port_alias(hwsku=hwsku, include_internal=False)['ansible_facts']
48+
port_alias_facts = duthost.port_alias(hwsku=hwsku, include_internal=True)['ansible_facts']
5549
up_ports = list(minigraph_facts['minigraph_ports'].keys())
5650
default_interfaces = list(port_alias_facts['port_name_map'].keys())
5751
minigraph_portchannels = minigraph_facts['minigraph_portchannels']
@@ -402,9 +396,9 @@ def test_show_pfc_counters(setup, setup_config_mode):
402396
per the configured naming mode
403397
"""
404398
dutHostGuest, mode, ifmode = setup_config_mode
405-
pfc_rx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters | sed -n "/Port Rx/,/^$/p"'
399+
pfc_rx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters -d all | sed -n "/Port Rx/,/^$/p"'
406400
.format(ifmode))['stdout']
407-
pfc_tx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters | sed -n "/Port Tx/,/^$/p"'
401+
pfc_tx = dutHostGuest.shell('SONIC_CLI_IFACE_MODE={} sudo show pfc counters -d all | sed -n "/Port Tx/,/^$/p"'
408402
.format(ifmode))['stdout']
409403
logger.info('pfc_rx:\n{}'.format(pfc_rx))
410404
logger.info('pfc_tx:\n{}'.format(pfc_tx))
@@ -430,7 +424,7 @@ class TestShowPriorityGroup():
430424

431425
@pytest.fixture(scope="class", autouse=True)
432426
def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
433-
skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname)
427+
pass
434428

435429
def test_show_priority_group_persistent_watermark_headroom(self, setup, setup_config_mode):
436430
"""
@@ -503,65 +497,65 @@ def test_show_priority_group_watermark_shared(self, setup, setup_config_mode):
503497

504498
class TestShowQueue():
505499

506-
@pytest.fixture(scope="class", autouse=True)
507-
def setup_check_topo(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
508-
skip_test_for_multi_asic(
509-
duthosts, enum_rand_one_per_hwsku_frontend_hostname)
510-
511500
def test_show_queue_counters(self, setup, setup_config_mode, duthosts, enum_rand_one_per_hwsku_frontend_hostname):
512501
"""
513502
Checks whether 'show queue counters' lists the interface names as
514503
per the configured naming mode
515504
"""
516-
dutHostGuest, mode, ifmode = setup_config_mode
517-
queue_counter = dutHostGuest.shell(
518-
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters | grep "UC\|MC\|ALL"'.format(ifmode))['stdout']
519-
logger.info('queue_counter:\n{}'.format(queue_counter))
520505

521506
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
522-
buffer_queue_keys = redis_get_keys(duthost, 'CONFIG_DB', 'BUFFER_QUEUE|*')
523-
interfaces = set()
524-
525-
for key in buffer_queue_keys:
526-
try:
527-
fields = key.split("|")
528-
# The format of BUFFER_QUEUE entries on VOQ chassis is
529-
# 'BUFFER_QUEUE|<host name>|<asic-name>|Ethernet32|0-2'
530-
# where 'host name' could be any host in the chassis, including those from other
531-
# cards. This test only cares about local interfaces, so we can filter out the rest
532-
if duthost.facts['switch_type'] == 'voq':
533-
hostname = fields[1]
534-
if hostname != duthost.hostname:
507+
for asic in duthost.asics:
508+
dutHostGuest, mode, ifmode = setup_config_mode
509+
queue_counter = dutHostGuest.shell(
510+
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters {} | grep "UC\|MC\|ALL"'.format(
511+
ifmode, asic.cli_ns_option
512+
))['stdout']
513+
logger.info('queue_counter:\n{}'.format(queue_counter))
514+
515+
configDbCli = SonicDbCli(asic, "CONFIG_DB")
516+
buffer_queue_keys = configDbCli.get_keys("BUFFER_QUEUE|*", raise_error_when_not_found=False)
517+
interfaces = set()
518+
519+
for key in buffer_queue_keys:
520+
try:
521+
fields = key.split("|")
522+
# The format of BUFFER_QUEUE entries on VOQ chassis is
523+
# 'BUFFER_QUEUE|<host name>|<asic-name>|Ethernet32|0-2'
524+
# where 'host name' could be any host in the chassis, including those from other
525+
# cards. This test only cares about local interfaces, so we can filter out the rest
526+
if duthost.facts['switch_type'] == 'voq':
527+
hostname = fields[1]
528+
if hostname != duthost.hostname:
529+
continue
530+
# The interface name is always the last but one field in the BUFFER_QUEUE entry key
531+
interfaces.add(fields[-2])
532+
except IndexError:
533+
pass
534+
535+
# For the test to be valid, we should have at least one interface selected
536+
assert (len(interfaces) > 0)
537+
538+
intfsChecked = 0
539+
if mode == 'alias':
540+
for intf in interfaces:
541+
alias = setup['port_name_map'][intf]
542+
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(alias),
543+
queue_counter) is not None) \
544+
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_alias_map'][alias]),
545+
queue_counter) is None)
546+
intfsChecked += 1
547+
elif mode == 'default':
548+
for intf in interfaces:
549+
if intf not in setup['port_name_map']:
535550
continue
536-
# The interface name is always the last but one field in the BUFFER_QUEUE entry key
537-
interfaces.add(fields[-2])
538-
except IndexError:
539-
pass
551+
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(intf),
552+
queue_counter) is not None) \
553+
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_name_map'][intf]),
554+
queue_counter) is None)
555+
intfsChecked += 1
540556

541-
# For the test to be valid, we should have at least one interface selected
542-
assert (len(interfaces) > 0)
543-
544-
intfsChecked = 0
545-
if mode == 'alias':
546-
for intf in interfaces:
547-
alias = setup['port_name_map'][intf]
548-
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(alias),
549-
queue_counter) is not None) \
550-
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_alias_map'][alias]),
551-
queue_counter) is None)
552-
intfsChecked += 1
553-
elif mode == 'default':
554-
for intf in interfaces:
555-
if intf not in setup['port_name_map']:
556-
continue
557-
assert (re.search(QUEUE_COUNTERS_RE_FMT.format(intf),
558-
queue_counter) is not None) \
559-
and (re.search(QUEUE_COUNTERS_RE_FMT.format(setup['port_name_map'][intf]),
560-
queue_counter) is None)
561-
intfsChecked += 1
562-
563-
# At least one interface should have been checked to have a valid result
564-
assert (intfsChecked > 0)
557+
# At least one interface should have been checked to have a valid result
558+
assert (intfsChecked > 0)
565559

566560
def test_show_queue_counters_interface(self, setup_config_mode, sample_intf):
567561
"""
@@ -570,8 +564,13 @@ def test_show_queue_counters_interface(self, setup_config_mode, sample_intf):
570564
"""
571565
dutHostGuest, mode, ifmode = setup_config_mode
572566
test_intf = sample_intf[mode]
567+
573568
queue_counter_intf = dutHostGuest.shell(
574-
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters {} | grep "UC\|MC\|ALL"'.format(ifmode, test_intf))
569+
r'SONIC_CLI_IFACE_MODE={} sudo show queue counters {} {} | grep "UC\|MC\|ALL"'.format(
570+
ifmode,
571+
test_intf,
572+
sample_intf["cli_ns_option"])
573+
)
575574
logger.info('queue_counter_intf:\n{}'.format(queue_counter_intf))
576575

577576
for i in range(len(queue_counter_intf['stdout_lines'])):
@@ -735,7 +734,7 @@ class TestConfigInterface():
735734

736735
@pytest.fixture(scope="class", autouse=True)
737736
def setup_check_topo(self, tbinfo):
738-
if tbinfo['topo']['type'] not in ['t2', 't1']:
737+
if tbinfo['topo']['type'] not in ['t1']:
739738
pytest.skip('Unsupported topology')
740739

741740
def check_speed_change(self, duthost, asic_index, interface, change_speed):
@@ -948,22 +947,31 @@ def test_show_interfaces_neighbor_expected(setup, setup_config_mode, tbinfo, dut
948947
if tbinfo['topo']['type'] not in ['t1', 't2']:
949948
pytest.skip('Unsupported topology')
950949

951-
skip_test_for_multi_asic(duthosts, enum_rand_one_per_hwsku_frontend_hostname)
952-
953950
dutHostGuest, mode, ifmode = setup_config_mode
954951
minigraph_neighbors = setup['minigraph_facts']['minigraph_neighbors']
955952

956-
show_int_neighbor = dutHostGuest.shell(
957-
'SONIC_CLI_IFACE_MODE={} show interfaces neighbor expected'.format(ifmode))['stdout']
953+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
954+
955+
show_int_neighbor = {}
956+
957+
for asic in duthost.asics:
958+
# In minigraph_neighbors, if there is no namespace it will have namespace: ''. Therefore we default to ''
959+
asic_namespace = asic.namespace if asic.namespace else ''
960+
show_int_neighbor[asic_namespace] = dutHostGuest.shell(
961+
'SONIC_CLI_IFACE_MODE={} show interfaces neighbor expected {}'.format(ifmode, asic.cli_ns_option))['stdout']
962+
958963
logger.info('show_int_neighbor:\n{}'.format(show_int_neighbor))
959964

960965
for key, value in list(minigraph_neighbors.items()):
961966
if 'server' not in value['name'].lower():
962967
if mode == 'alias':
963968
assert re.search(r'{}\s+{}'
964-
.format(setup['port_name_map'][key], value['name']), show_int_neighbor) is not None
969+
.format(setup['port_name_map'][key], value['name']),
970+
show_int_neighbor[value["namespace"]]) is not None
965971
elif mode == 'default':
966-
assert re.search(r'{}\s+{}'.format(key, value['name']), show_int_neighbor) is not None
972+
logger.info("key value name: {} - {}".format(key, value['name']))
973+
assert re.search(r'{}\s+{}'.format(key, value['name']),
974+
show_int_neighbor[value["namespace"]]) is not None
967975

968976

969977
class TestNeighbors():

0 commit comments

Comments
 (0)