Skip to content

Commit

Permalink
[portstat] [telemetry] [snmp] Align tests to delay of flex counters c…
Browse files Browse the repository at this point in the history
…hange (#3903)

### Approach
#### What is the motivation for this PR?
Following PR's:
sonic-net/sonic-swss#1803
sonic-net/sonic-swss#1804
Flex counters are delayed and these tests are failing as a result of missing information on the DUT.
This PR is to wait until all counters are enabled before running the test.
Timeout value chosen by the delay script which can be found here:
https://github.com/Azure/sonic-buildimage/blob/master/dockers/docker-orchagent/enable_counters.py

#### How did you do it?
Wait until all counters are enabled before running the tests.

#### How did you verify/test it?
Run the tests with this change.
  • Loading branch information
shlomibitton authored Aug 16, 2021
1 parent 909c7b3 commit 67266b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

from tests.common.connections.console_host import ConsoleHost

WAIT_FOR_COUNTERS_TIMEOUT = 190
WAIT_FOR_COUNTERS_INTERVAL = 10

logger = logging.getLogger(__name__)
cache = FactsCache()
Expand Down Expand Up @@ -1143,3 +1145,25 @@ def duts_minigraph_facts(duthosts, tbinfo):
}
"""
return duthosts.get_extended_minigraph_facts(tbinfo)

@pytest.fixture(scope='function')
def wait_for_counters(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]
logger.info('Wait until all counters are enabled on the DUT')
counters = ['PORT_STAT', 'PORT_BUFFER_DROP', 'QUEUE_STAT', 'PG_WATERMARK_STAT', 'RIF_STAT']
current_attempt = 0
while current_attempt < WAIT_FOR_COUNTERS_TIMEOUT / WAIT_FOR_COUNTERS_INTERVAL:
output = duthost.shell("counterpoll show | sed '1,2d'", module_ignore_errors=True)
assert output.has_key('rc') and output['rc'] == 0, "Failed to get counters status"
counters_lines = output['stdout'].splitlines()
enabled_counters = 0
for line in counters_lines:
if any(counter in line for counter in counters) and 'enable' in line:
enabled_counters += 1
continue
if enabled_counters == len(counters):
return
else:
current_attempt += 1
time.sleep(WAIT_FOR_COUNTERS_INTERVAL)
assert False, "Not all counters are enabled after {} seconds".format(WAIT_FOR_COUNTERS_TIMEOUT)
2 changes: 1 addition & 1 deletion tests/portstat/test_portstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def reset_portstat(duthosts, enum_rand_one_per_hwsku_frontend_hostname):


@pytest.mark.parametrize('command', ['portstat -c', 'portstat --clear'])
def test_portstat_clear(duthosts, enum_rand_one_per_hwsku_frontend_hostname, command):
def test_portstat_clear(duthosts, enum_rand_one_per_hwsku_frontend_hostname, command, wait_for_counters):
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
wait(30, 'Wait for DUT to receive/send some packets')
before_portstat = parse_portstat(duthost.command('portstat')['stdout_lines'])
Expand Down
4 changes: 4 additions & 0 deletions tests/snmp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def setup_check_snmp_ready(duthosts):
for duthost in duthosts:
assert wait_until(300, 20, duthost.is_service_fully_started, "snmp"), "SNMP service is not running"

@pytest.fixture(scope="function", autouse=True)
def snmp_wait_for_counters(wait_for_counters):
return

def pytest_addoption(parser):
"""
Adds options to pytest that are used by the snmp tests.
Expand Down
2 changes: 1 addition & 1 deletion tests/telemetry/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_telemetry_enabledbydefault(duthosts, rand_one_dut_hostname):
status_expected = "enabled";
pytest_assert(str(v) == status_expected, "Telemetry feature is not enabled")

def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, setup_streaming_telemetry, localhost):
def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, setup_streaming_telemetry, localhost, wait_for_counters):
"""Run pyclient from ptfdocker and show gnmi server outputself.
"""
duthost = duthosts[rand_one_dut_hostname]
Expand Down

0 comments on commit 67266b9

Please sign in to comment.