@pytest.yield_fixture(scope='class', autouse=True)
def counters_sanity_check(self, duthosts, acl_rules, acl_table):
    'Validate that the counters for each rule in the rules list increased as expected.\n\n        This fixture yields a list of rule IDs. The test case should add on to this list if\n        it is required to check the rule for increased counters.\n\n        After the test cases pass, the fixture will wait for the ACL counters to update and then\n        check if the counters for each rule in the list were increased.\n\n        Args:\n            duthosts: All DUTs belong to the testbed.\n            rand_one_dut_hostname: hostname of a random chosen dut to run test.\n            acl_rules: Fixture that sets up the ACL rules.\n            acl_table: Fixture that sets up the ACL table.\n\n        '
    acl_facts = defaultdict(dict)
    table_name = acl_table['table_name']
    for duthost in duthosts:
        acl_facts[duthost]['before'] = duthost.acl_facts()['ansible_facts']['ansible_acl_facts'][table_name]['rules']
    rule_list = []
    (yield rule_list)
    if (not rule_list):
        return
    time.sleep(self.ACL_COUNTERS_UPDATE_INTERVAL_SECS)
    for duthost in duthosts:
        acl_facts[duthost]['after'] = duthost.acl_facts()['ansible_facts']['ansible_acl_facts'][table_name]['rules']
    for duthost in duthosts:
        assert (len(acl_facts[duthost]['before']) == len(acl_facts[duthost]['after']))
    for rule in rule_list:
        rule = 'RULE_{}'.format(rule)
        counters_before = {PACKETS_COUNT: 0, BYTES_COUNT: 0}
        for duthost in duthosts:
            counters_before[PACKETS_COUNT] += acl_facts[duthost]['before'][rule][PACKETS_COUNT]
            counters_before[BYTES_COUNT] += acl_facts[duthost]['before'][rule][BYTES_COUNT]
        logger.info('Counters for ACL rule "{}" before traffic:\n{}'.format(rule, pprint.pformat(counters_before)))
        counters_after = {PACKETS_COUNT: 0, BYTES_COUNT: 0}
        for duthost in duthosts:
            counters_after[PACKETS_COUNT] += acl_facts[duthost]['after'][rule][PACKETS_COUNT]
            counters_after[BYTES_COUNT] += acl_facts[duthost]['after'][rule][BYTES_COUNT]
        logger.info('Counters for ACL rule "{}" after traffic:\n{}'.format(rule, pprint.pformat(counters_after)))
        assert (counters_after[PACKETS_COUNT] > counters_before[PACKETS_COUNT])
        assert (counters_after[BYTES_COUNT] > counters_before[BYTES_COUNT])
Validate that the counters for each rule in the rules list increased as expected.

This fixture yields a list of rule IDs. The test case should add on to this list if
it is required to check the rule for increased counters.

After the test cases pass, the fixture will wait for the ACL counters to update and then
check if the counters for each rule in the list were increased.

Args:
    duthosts: All DUTs belong to the testbed.
    rand_one_dut_hostname: hostname of a random chosen dut to run test.
    acl_rules: Fixture that sets up the ACL rules.
    acl_table: Fixture that sets up the ACL table.
@pytest.yield_fixture(scope='class', autouse=True)
def counters_sanity_check(self, duthosts, acl_rules, acl_table):
    'Validate that the counters for each rule in the rules list increased as expected.\n\n        This fixture yields a list of rule IDs. The test case should add on to this list if\n        it is required to check the rule for increased counters.\n\n        After the test cases pass, the fixture will wait for the ACL counters to update and then\n        check if the counters for each rule in the list were increased.\n\n        Args:\n            duthosts: All DUTs belong to the testbed.\n            rand_one_dut_hostname: hostname of a random chosen dut to run test.\n            acl_rules: Fixture that sets up the ACL rules.\n            acl_table: Fixture that sets up the ACL table.\n\n        '
    acl_facts = defaultdict(dict)
    table_name = acl_table['table_name']
    for duthost in duthosts:
        acl_facts[duthost]['before'] = duthost.acl_facts()['ansible_facts']['ansible_acl_facts'][table_name]['rules']
    rule_list = []
    (yield rule_list)
    if (not rule_list):
        return
    time.sleep(self.ACL_COUNTERS_UPDATE_INTERVAL_SECS)
    for duthost in duthosts:
        acl_facts[duthost]['after'] = duthost.acl_facts()['ansible_facts']['ansible_acl_facts'][table_name]['rules']
    for duthost in duthosts:
        assert (len(acl_facts[duthost]['before']) == len(acl_facts[duthost]['after']))
    for rule in rule_list:
        rule = 'RULE_{}'.format(rule)
        counters_before = {PACKETS_COUNT: 0, BYTES_COUNT: 0}
        for duthost in duthosts:
            counters_before[PACKETS_COUNT] += acl_facts[duthost]['before'][rule][PACKETS_COUNT]
            counters_before[BYTES_COUNT] += acl_facts[duthost]['before'][rule][BYTES_COUNT]
        logger.info('Counters for ACL rule "{}" before traffic:\n{}'.format(rule, pprint.pformat(counters_before)))
        counters_after = {PACKETS_COUNT: 0, BYTES_COUNT: 0}
        for duthost in duthosts:
            counters_after[PACKETS_COUNT] += acl_facts[duthost]['after'][rule][PACKETS_COUNT]
            counters_after[BYTES_COUNT] += acl_facts[duthost]['after'][rule][BYTES_COUNT]
        logger.info('Counters for ACL rule "{}" after traffic:\n{}'.format(rule, pprint.pformat(counters_after)))
        assert (counters_after[PACKETS_COUNT] > counters_before[PACKETS_COUNT])
        assert (counters_after[BYTES_COUNT] > counters_before[BYTES_COUNT])