Skip to content

Commit

Permalink
[SNMP]: Modify test to verify all queue indexes are present (#11180)
Browse files Browse the repository at this point in the history
## Approach
#### What is the motivation for this PR?
ADO : 26336010

Modify test to detect issue sonic-net/sonic-buildimage#17448.
#### How did you do it?
Currently test_snmp_queue only verifies that each interface does have queue counters associated with it.
It does not verify if all the expected queue counters are present.
Modify test_snmp_queue to add 2 additional checks:
1. Ensure that queue index with queue configuration in config_db, is present for each interface.
2. Ensure that the number of Unicast queue counters for each interface in 'show queue counters <interface name> is the same as the number of queue indexes in the SNMP result.
#### How did you verify/test it?
Test case passes for single-asic/multi-asic/Chassis platforms.
Test case passed with: 202205/202305/202311/master images
Test case fails when run on device with image which has the issue: sonic-net/sonic-buildimage#17448.
```
                        snmp_q_idx = int(queue_idx) + 1
                        if str(snmp_q_idx) not in v['queues'][direction_type]:
                            pytest.fail("\
                                    Expected queue index %d not present in SNMP \
>                                           result for interface %s" % (snmp_q_idx, v['name']))
E                           Failed:                                 Expected queue index 6 not present in SNMP                                         result for interface Ethernet13/3

..
snmp/test_snmp_queue.py:87: Failed
-------------------------------------------------------------------------------------------------- generated xml file: /data/sonic-mgmt-int/tests/logs/tr.xml --------------------------------------------------------------------------------------------------
=================================================================================================================== short test summary info ====================================================================================================================
FAILED snmp/test_snmp_queue.py::test_snmp_queues[str3-7060-acs-1] - Failed:                                 Expected queue index 6 not present in SNMP                                         result for interface Ethernet13/3
================================================================================================================== 1 failed in 248.30 seconds ==================================================================================================================
INFO:root:Can not get Allure report URL. Please check logs
```
  • Loading branch information
SuvarnaMeenakshi authored Jan 10, 2024
1 parent b7e2e49 commit 0ad4705
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions tests/snmp/test_snmp_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ def test_snmp_queues(duthosts, enum_rand_one_per_hwsku_hostname, localhost, cred
collect_techsupport_all_duts):
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
q_keys = []
direction_type = '2' # direction_type in OID is set to 2 to denote "egress".

hostip = duthost.host.options['inventory_manager'].get_host(
duthost.hostname).vars['ansible_host']
port_name_to_alias_map = {}
port_name_to_ns = {}

for asic_id in duthost.get_asic_ids():
namespace = duthost.get_namespace_from_asic_id(asic_id)
Expand All @@ -26,25 +28,35 @@ def test_snmp_queues(duthosts, enum_rand_one_per_hwsku_hostname, localhost, cred
q_keys.extend(q_keys_ns)
if config_facts_ns and 'port_name_to_alias_map' in config_facts_ns:
port_name_to_alias_map.update(config_facts_ns['port_name_to_alias_map'])
for port_name in config_facts_ns['port_name_to_alias_map']:
port_name_to_ns[port_name] = namespace

if not q_keys:
pytest.skip("No queues configured on interfaces")

# Get alias : port_name map
alias_port_name_map = {k: v for v, k in port_name_to_alias_map.items()}

q_interfaces = set()
q_interfaces = dict() # {intf_name : set(queue_indexes)}
# get interfaces which has configured queues
for key in q_keys:
intf_idx = 0
queue_idx = 0
intf = key.split('|')
# 'QUEUE|Ethernet*|2'
if len(intf) == 3:
q_interfaces.add(intf[1])
intf_idx = 1
queue_idx = 2
# Voq chassis 'QUEUE|<hostname>|<asic_ns>|Ethernet*|2'
elif len(intf) == 5:
# Choose only interfaces on current linecard.
if intf[1] == duthost.hostname:
q_interfaces.add(intf[3])
intf_idx = 3
queue_idx = 4
if intf_idx != 0:
if intf[intf_idx] not in q_interfaces:
q_interfaces[intf[intf_idx]] = set()
q_interfaces[intf[intf_idx]].add(intf[queue_idx])

snmp_facts = get_snmp_facts(localhost, host=hostip, version="v2c",
community=creds_all_duts[duthost.hostname]["snmp_rocommunity"],
Expand All @@ -60,5 +72,27 @@ def test_snmp_queues(duthosts, enum_rand_one_per_hwsku_hostname, localhost, cred
# v['name'] is alias for example Ethernet1/1
if v['name'] in alias_port_name_map:
intf = alias_port_name_map[v['name']]
if intf in q_interfaces and 'queues' not in v:
pytest.fail("port %s does not have queue counters" % v['name'])

# Expect all interfaces to have queue counters
assert 'queues' in v, "Port {} does not have queue counters".format(intf)

# Check if queue index in QUEUE table in config_db
# is present in SNMP result
if intf in q_interfaces:
for queue_idx in q_interfaces[intf]:
# queue_idx starts with 0, queue_idx in OID starts with 1
# Increment queue_idx by 1 to form the right OID.
snmp_q_idx = int(queue_idx) + 1
if str(snmp_q_idx) not in v['queues'][direction_type]:
pytest.fail("Expected queue index %d not present in \
SNMP result for interface %s" % (snmp_q_idx, v['name']))
# compare number of unicast queues in CLI to the number of queue indexes in
# SNMP result
if port_name_to_ns[intf]:
show_cli = 'show queue counters -n {} {} | grep "UC" | wc -l'.format(port_name_to_ns[intf], intf)
else:
show_cli = 'show queue counters {} | grep "UC" | wc -l'.format(intf)
result = duthost.shell(show_cli)
assert len(v['queues'][direction_type].keys()) == int(result[u'stdout']),\
"Port {} does not have expected number of queue \
indexes in SNMP result".format(intf)

0 comments on commit 0ad4705

Please sign in to comment.