From 2e7ce613c0b5d6aa74f4b39dabb8db648b945390 Mon Sep 17 00:00:00 2001 From: kbabujp Date: Thu, 11 Jan 2024 06:24:02 +0000 Subject: [PATCH] Remove DATAACL to free TCAM resources for test_stress_acl.py --- tests/acl/test_stress_acl.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/acl/test_stress_acl.py b/tests/acl/test_stress_acl.py index 7f14de5b0d0..b67626eb0e1 100644 --- a/tests/acl/test_stress_acl.py +++ b/tests/acl/test_stress_acl.py @@ -1,6 +1,7 @@ import logging import random import pytest +import json import ptf.testutils as testutils from ptf import mask, packet from collections import defaultdict @@ -35,6 +36,43 @@ ACL_RULE_NUMS = 10 +@pytest.fixture(scope="module", autouse=True) +def remove_dataacl_table(duthosts, rand_selected_dut): + """ + Remove DATAACL to free TCAM resources. + The change is written to configdb as we don't want DATAACL recovered after reboot + """ + TABLE_NAME_1 = "DATAACL" + for duthost in duthosts: + lines = duthost.shell(cmd="show acl table {}".format(TABLE_NAME_1))['stdout_lines'] + data_acl_existing = False + for line in lines: + if TABLE_NAME_1 in line: + data_acl_existing = True + break + + if data_acl_existing: + # Remove DATAACL + logger.info("Removing ACL table {}".format(TABLE_NAME_1)) + rand_selected_dut.shell(cmd="config acl remove table {}".format(TABLE_NAME_1)) + + if not data_acl_existing: + yield + return + + yield + # Recover DATAACL + config_db_json = "/etc/sonic/config_db.json" + output = rand_selected_dut.shell("sonic-cfggen -j {} --var-json \"ACL_TABLE\"".format(config_db_json))['stdout'] + entry_json = json.loads(output) + if TABLE_NAME_1 in entry_json: + entry = entry_json[TABLE_NAME_1] + cmd_create_table = "config acl add table {} {} -p {} -s {}"\ + .format(TABLE_NAME_1, entry['type'], ",".join(entry['ports']), entry['stage']) + logger.info("Restoring ACL table {}".format(TABLE_NAME_1)) + rand_selected_dut.shell(cmd_create_table) + + @pytest.fixture(scope='module') def prepare_test_file(rand_selected_dut): # Define a custom table type CUSTOM_TYPE by loading a json configuration