Skip to content

Commit

Permalink
[ACL] Fix ACL rules are not ready yet when test cases are started in …
Browse files Browse the repository at this point in the history
…as5835_54t model (sonic-net#2961)

What is the motivation for this PR?
Fix failed test cases in as5835_54t model.

How did you do it?
Check output of aclshow -a command and ensure that one or more rules are able to displayed and values of counters are not N/A.

How did you verify/test it?
Run the modified code in as5835_54t model to ensure that the problem is fixed.
  • Loading branch information
shihhsien-wang authored and nirmalya-keysight committed Apr 5, 2021
1 parent d495f39 commit 80bdea6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError
from tests.common.fixtures.duthost_utils import backup_and_restore_config_db_module
from tests.common.fixtures.ptfhost_utils import copy_arp_responder_py
from tests.common.utilities import wait_until
from tests.conftest import duthost

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -150,7 +151,7 @@ def setup(duthosts, rand_one_dut_hostname, tbinfo, ptfadapter):
vlan_ports = []

if topo == "t0":
vlan_ports = [mg_facts["minigraph_ptf_indices"][ifname]
vlan_ports = [mg_facts["minigraph_ptf_indices"][ifname]
for ifname in mg_facts["minigraph_vlans"].values()[0]["members"]]

setup_information = {
Expand Down Expand Up @@ -396,6 +397,9 @@ def acl_rules(self, duthosts, rand_one_dut_hostname, localhost, setup, acl_table
self.setup_rules(duthost, acl_table, ip_version)

self.post_setup_hook(duthost, localhost, populate_vlan_arp_entries, tbinfo)

assert self.check_rule_counters(duthost), "Rule counters should be ready!"

except LogAnalyzerError as err:
# Cleanup Config DB if rule creation failed
logger.error("ACL rule application failed, attempting to clean-up...")
Expand Down Expand Up @@ -463,6 +467,21 @@ def direction(self, request):
"""Parametrize test based on direction of traffic."""
return request.param

def check_rule_counters(self, duthost):
logger.info('Wait all rule counters are ready')

return wait_until(60, 2, self.check_rule_counters_internal, duthost)

def check_rule_counters_internal(self, duthost):
res = duthost.command('aclshow -a')

num_of_lines = len(res['stdout'].split('\n'))

if num_of_lines <= 2 or 'N/A' in res['stdout']:
return False

return True

def get_src_port(self, setup, direction):
"""Get a source port for the current test."""
src_ports = setup["downstream_port_ids"] if direction == "downlink->uplink" else setup["upstream_port_ids"]
Expand Down

0 comments on commit 80bdea6

Please sign in to comment.