Skip to content

Commit

Permalink
Leave 1 ACL rule in test_crm.py::test_acl_entry (sonic-net#9054)
Browse files Browse the repository at this point in the history
Some platforms (like broadcom-dnx) allocate ACL banks dynamically so if there are no ACL rules it returns a NULL value for CRM purposes. So leave 1 ACL rule when comparing the returned used/available CRM values.

Also on broadcom-dnx an ACL entry is used per bind point so account for that when calculating the expected available acl entries.

Summary:
Fixes sonic-net#8812

Type of change
 Test case(new/improvement)
Back port request
 202205
 202305
  • Loading branch information
arista-nwolfe authored and AharonMalkin committed Jan 25, 2024
1 parent 233abb7 commit 21ac248
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions tests/crm/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,23 +920,23 @@ def test_acl_entry(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_fro
ports = ",".join([tmp_ports[20], tmp_ports[25]])
recreate_acl_table(duthost, ports)
verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hostname,
enum_frontend_asic_index, asic_collector)
enum_frontend_asic_index, asic_collector, tbinfo)
# Rebind DATA ACL at end to recover original config
recreate_acl_table(duthost, ports)
apply_acl_config(duthost, asichost, "test_acl_entry", asic_collector)
duthost.command("acl-loader delete")
else:
verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hostname,
enum_frontend_asic_index, asic_collector)
enum_frontend_asic_index, asic_collector, tbinfo)

pytest_assert(crm_stats_checker,
"\"crm_stats_acl_entry_used\" counter was not decremented or "
"\"crm_stats_acl_entry_available\" counter was not incremented")


def verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hostname,
enum_frontend_asic_index, asic_collector):
apply_acl_config(duthost, asichost, "test_acl_entry", asic_collector)
enum_frontend_asic_index, asic_collector, tbinfo):
apply_acl_config(duthost, asichost, "test_acl_entry", asic_collector, entry_num=2)
acl_tbl_key = asic_collector["acl_tbl_key"]
get_acl_entry_stats = "{db_cli} COUNTERS_DB HMGET {acl_tbl_key} \
crm_stats_acl_entry_used \
Expand All @@ -950,11 +950,9 @@ def verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hos
# Get new "crm_stats_acl_entry" used and available counter value
new_crm_stats_acl_entry_used, new_crm_stats_acl_entry_available = get_crm_stats(get_acl_entry_stats, duthost)
# Verify "crm_stats_acl_entry_used" counter was incremented
pytest_assert(new_crm_stats_acl_entry_used - crm_stats_acl_entry_used == 2,
pytest_assert(new_crm_stats_acl_entry_used - crm_stats_acl_entry_used == 4,
"\"crm_stats_acl_entry_used\" counter was not incremented")

crm_stats_acl_entry_available = new_crm_stats_acl_entry_available + new_crm_stats_acl_entry_used

used_percent = get_used_percent(new_crm_stats_acl_entry_used, new_crm_stats_acl_entry_available)
if used_percent < 1:
# Preconfiguration needed for used percentage verification
Expand All @@ -968,8 +966,34 @@ def verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hos
# Verify thresholds for "ACL entry" CRM resource
verify_thresholds(duthost, asichost, crm_cli_res="acl group entry", crm_cmd=get_acl_entry_stats)

# Remove ACL
duthost.command("acl-loader delete")
# Reduce ACL to one rule (plus default)
crm_stats_acl_entry_used = 2
apply_acl_config(duthost, asichost, "test_acl_entry", asic_collector, entry_num=1)
if duthost.facts["platform_asic"] == "broadcom-dnx":
# Each ACL rule consumes an acl entry per bind point
asicAclBindings = set()
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)

# PCs are a single bind point
portToLag = {}
for lag, lagData in mg_facts["minigraph_portchannels"].items():
for member in lagData['members']:
portToLag[member] = lag
aclBindings = mg_facts["minigraph_acls"]["DataAcl"]
for port in aclBindings:
if port in portToLag:
if asichost.portchannel_on_asic(portToLag[port]):
asicAclBindings.add(portToLag[port])
else:
if asichost.port_on_asic(port):
asicAclBindings.add(port)

freed_acl_entries = (new_crm_stats_acl_entry_used - crm_stats_acl_entry_used) * len(asicAclBindings)
else:
freed_acl_entries = new_crm_stats_acl_entry_used - crm_stats_acl_entry_used

crm_stats_acl_entry_available = new_crm_stats_acl_entry_available + freed_acl_entries

acl_tbl_key = asic_collector["acl_tbl_key"]
get_acl_entry_stats = "{db_cli} COUNTERS_DB HMGET {acl_tbl_key} \
crm_stats_acl_entry_used \
Expand Down Expand Up @@ -1002,6 +1026,9 @@ def verify_acl_crm_stats(duthost, asichost, enum_rand_one_per_hwsku_frontend_hos
crm_stats_acl_entry_available,
)

# Remove ACL
duthost.command("acl-loader delete")


def test_acl_counter(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, collector):
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
Expand Down

0 comments on commit 21ac248

Please sign in to comment.