|
1 | 1 | import pytest
|
2 | 2 | from tests.common.helpers.snmp_helpers import get_snmp_facts
|
3 |
| -from tests.common.helpers.sonic_db import redis_get_keys |
4 | 3 |
|
5 | 4 | pytestmark = [
|
6 | 5 | pytest.mark.topology('any'),
|
|
11 | 10 | def test_snmp_queues(duthosts, enum_rand_one_per_hwsku_hostname, localhost, creds_all_duts,
|
12 | 11 | collect_techsupport_all_duts):
|
13 | 12 | 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 | + |
16 | 15 | hostip = duthost.host.options['inventory_manager'].get_host(
|
17 | 16 | 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: |
22 | 31 | pytest.skip("No queues configured on interfaces")
|
23 | 32 |
|
| 33 | + # Get alias : port_name map |
| 34 | + alias_port_name_map = {k: v for v, k in port_name_to_alias_map.items()} |
| 35 | + |
24 | 36 | q_interfaces = set()
|
25 | 37 | # get interfaces which has configured queues
|
26 | 38 | for key in q_keys:
|
27 | 39 | intf = key.split('|')
|
28 | 40 | # 'QUEUE|Ethernet*|2'
|
29 | 41 | if len(intf) == 3:
|
30 | 42 | 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]) |
31 | 46 |
|
32 | 47 | snmp_facts = get_snmp_facts(localhost, host=hostip, version="v2c",
|
33 | 48 | community=creds_all_duts[duthost.hostname]["snmp_rocommunity"],
|
34 | 49 | wait=True)['ansible_facts']
|
35 | 50 |
|
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