Skip to content

Commit 7297b17

Browse files
Issue 21164: [dhcp_relay] Add workaround for ACL limit issue (sonic-net#21165)
Summary: Some tests which use ACLs can fail when all ACLs have been programmed. We can detect this case and compensate for it by storing the table info and re-instating it at the end of the test. In the test infra, store the contents of the DATAACL table and restore those contents at the end of the test. Test fails without this change, but passes with the change.
1 parent 6e4c470 commit 7297b17

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/dhcp_relay/test_dhcp_pkt_recv.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import ptf.packet as scapy
34
import pytest
@@ -41,14 +42,61 @@ class Dhcpv6PktRecvBase:
4142
@pytest.fixture(scope="class")
4243
def setup_teardown(self, rand_selected_dut, tbinfo):
4344
duthost = rand_selected_dut
45+
46+
# Remove DATAACL table to free TCAM resources
47+
TABLE_NAME = "DATAACL"
48+
data_acl_table = None
49+
data_acl_rules = None
50+
51+
# Save both table and rules
52+
output = duthost.shell("sonic-cfggen -d --var-json \"ACL_TABLE\"")['stdout']
53+
try:
54+
acl_tables = json.loads(output)
55+
if TABLE_NAME in acl_tables:
56+
data_acl_table = {TABLE_NAME: acl_tables[TABLE_NAME]}
57+
except ValueError:
58+
pass
59+
60+
output = duthost.shell("sonic-cfggen -d --var-json \"ACL_RULE\"")['stdout']
61+
try:
62+
acl_rules = json.loads(output)
63+
data_acl_rules = {k: v for k, v in acl_rules.items() if k.startswith(TABLE_NAME + "|")}
64+
except ValueError:
65+
pass
66+
67+
if data_acl_table is not None:
68+
logging.info("Removing ACL table {} to free TCAM resources".format(TABLE_NAME))
69+
duthost.shell(cmd="config acl remove table {}".format(TABLE_NAME))
70+
4471
dut_index = str(tbinfo['duts_map'][duthost.hostname])
4572
disabled_host_interfaces = tbinfo['topo']['properties']['topology'].get('disabled_host_interfaces', [])
4673
host_interfaces = [intf for intf in tbinfo['topo']['properties']['topology'].get('host_interfaces', [])
4774
if intf not in disabled_host_interfaces]
4875
ptf_indices = self.parse_ptf_indices(host_interfaces, dut_index)
4976
dut_intf_ptf_index = duthost.get_extended_minigraph_facts(tbinfo)['minigraph_ptf_indices']
77+
5078
yield ptf_indices, dut_intf_ptf_index
5179

80+
# Restore DATAACL table and rules if they were removed
81+
if data_acl_table is not None:
82+
# Restore table
83+
data_acl = {'ACL_TABLE': data_acl_table}
84+
if data_acl_rules:
85+
data_acl['ACL_RULE'] = data_acl_rules
86+
cmd = 'sonic-cfggen -a \'{}\' -w'.format(json.dumps(data_acl))
87+
logging.info("Restoring ACL table {} with {} rules".format(TABLE_NAME,
88+
len(data_acl_rules) if data_acl_rules
89+
else 0))
90+
duthost.shell(cmd)
91+
# Verify restoration worked by checking for a specific rule
92+
if data_acl_rules:
93+
verify_cmd = "sonic-cfggen -d --var-json \"ACL_RULE\" | grep -q 'DATAACL'"
94+
result = duthost.shell(verify_cmd, module_ignore_errors=True)
95+
if result['rc'] == 0:
96+
logging.info("ACL rules successfully restored")
97+
else:
98+
logging.warning("ACL rule restoration may have failed")
99+
52100
def parse_ptf_indices(self, host_interfaces, dut_index):
53101
indices = list()
54102
for _ports in host_interfaces:

0 commit comments

Comments
 (0)