Skip to content

Commit 8123ab7

Browse files
[snmp][multi-asic]: Fix test_snmp_queue to support multi-asic platform (sonic-net#9115)
What is the motivation for this PR? test_snmp_queue was modified to get keys "QUEUE|*" from config_db in sonic-net#6744. This has to be modified to get keys from all namespace config_db on mulit-asic platform. Currently, test tries to retrieve from host config_db and skips the test for multi-asic platform. Test is currently skipped for supervisor node, but should not be skipped for supervisor node of packet chassis. How did you do it? Modified to get interfaces with queue configuration from all namespaces. The test case was not checking the right field in snmp_interfaces SNMP result. Test case was checking for "description" of each interface, from description, interface name was extracted and checked if the interface name is present in QUEUE table. This check will always be false and pytest fail condition was never hit. The test case was always incorrectly passing. (Pdb) snmp_facts['snmp_interfaces']['117']['description'] u'ARISTA02T1:Ethernet1' for k, v in list(snmp_facts['snmp_interfaces'].items()): if "Ethernet" in v['description']: intf = v['description'].split(':') # 'ARISTA*:Ethernet*' if len(intf) == 2: if intf[1] in q_interfaces and 'queues' not in v: -- intf[1] in q_interfaces will always be false pytest.fail( "port %s does not have queue counters" % v['name']) -- will never hit this condition intf[1] will always be Ethernet1 which is the interface of the neighbor Modified test to use 'name' which gives the interface alias instead of interface name present in 'description' (Pdb) snmp_facts['snmp_interfaces']['117']['name'] u'fortyGigE0/116' Remove skip of supervisor node. On voq chassis LC, QUEUE configuration will include hostname and asic namespace as queue configuration is created on system port. Test is modified to get the interface name for voq chassis. "QUEUE": { "<hostname>|asic0|Ethernet0|0": { "scheduler": "scheduler.0" }, How did you verify/test it? Verified on single asic VS testbed.
1 parent 7133697 commit 8123ab7

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

tests/snmp/test_snmp_queue.py

+34-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
from tests.common.helpers.snmp_helpers import get_snmp_facts
3-
from tests.common.helpers.sonic_db import redis_get_keys
43

54
pytestmark = [
65
pytest.mark.topology('any'),
@@ -11,33 +10,53 @@
1110
def test_snmp_queues(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_all_duts,
1211
collect_techsupport_all_duts):
1312
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
14-
if duthost.is_supervisor_node():
15-
pytest.skip("interfaces not present on supervisor node")
13+
q_keys = []
14+
1615
hostip = duthost.host.options['inventory_manager'].get_host(
1716
duthost.hostname).vars['ansible_host']
18-
19-
q_keys = redis_get_keys(duthost, "CONFIG_DB", "QUEUE|*")
20-
21-
if q_keys is None:
17+
port_name_to_alias_map = {}
18+
19+
for asic_id in duthost.get_asic_ids():
20+
namespace = duthost.get_namespace_from_asic_id(asic_id)
21+
config_facts_ns = duthost.config_facts(host=duthost.hostname, source="running",
22+
namespace=namespace)['ansible_facts']
23+
asic = duthost.asic_instance(asic_id)
24+
q_keys_ns = asic.run_sonic_db_cli_cmd('CONFIG_DB KEYS "QUEUE|*"')['stdout_lines']
25+
if q_keys_ns:
26+
q_keys.extend(q_keys_ns)
27+
if config_facts_ns and 'port_name_to_alias_map' in config_facts_ns:
28+
port_name_to_alias_map.update(config_facts_ns['port_name_to_alias_map'])
29+
30+
if not q_keys:
2231
pytest.skip("No queues configured on interfaces")
2332

33+
# Get alias : port_name map
34+
alias_port_name_map = {k: v for v, k in port_name_to_alias_map.items()}
35+
2436
q_interfaces = set()
2537
# get interfaces which has configured queues
2638
for key in q_keys:
2739
intf = key.split('|')
2840
# 'QUEUE|Ethernet*|2'
2941
if len(intf) == 3:
3042
q_interfaces.add(intf[1])
43+
# Packet chassis 'QUEUE|<hostname>|<asic_ns>|Ethernet*|2'
44+
elif len(intf) == 5:
45+
q_interfaces.add(intf[3])
3146

3247
snmp_facts = get_snmp_facts(localhost, host=hostip, version="v2c",
3348
community=creds_all_duts[duthost.hostname]["snmp_rocommunity"],
3449
wait=True)['ansible_facts']
3550

36-
for k, v in list(snmp_facts['snmp_interfaces'].items()):
37-
if "Ethernet" in v['description']:
38-
intf = v['description'].split(':')
39-
# 'ARISTA*:Ethernet*'
40-
if len(intf) == 2:
41-
if intf[1] in q_interfaces and 'queues' not in v:
42-
pytest.fail(
43-
"port %s does not have queue counters" % v['name'])
51+
snmp_ifnames = [alias_port_name_map[v['name']]
52+
for k, v in list(snmp_facts['snmp_interfaces'].items()) if v['name'] in alias_port_name_map]
53+
54+
for intf in q_interfaces:
55+
assert intf in snmp_ifnames, "Port {} with QUEUE config is not present in snmp interfaces".format(intf)
56+
57+
for k, v in snmp_facts['snmp_interfaces'].items():
58+
# v['name'] is alias for example Ethernet1/1
59+
if v['name'] in alias_port_name_map:
60+
intf = alias_port_name_map[v['name']]
61+
if intf in q_interfaces and 'queues' not in v:
62+
pytest.fail("port %s does not have queue counters" % v['name'])

0 commit comments

Comments
 (0)