Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202405] Stabilize test_cacl cases #15299

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions tests/generic_config_updater/test_cacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from tests.generic_config_updater.gu_utils import apply_patch, expect_op_success, expect_res_success, expect_op_failure
from tests.generic_config_updater.gu_utils import generate_tmpfile, delete_tmpfile
from tests.generic_config_updater.gu_utils import create_checkpoint, delete_checkpoint, rollback_or_reload
from tests.common.utilities import wait_until

# Test on t0 topo to verify functionality and to choose predefined variable
# admin@vlab-01:~$ show acl table
Expand Down Expand Up @@ -73,19 +74,8 @@ def setup_env(duthosts, rand_one_dut_hostname):
logger.info("Rolled back to original checkpoint")
rollback_or_reload(duthost)

current_iptable_rules = get_iptable_rules(duthost)
logger.info("original iptable rules: {}, current iptable rules: {}".format(
original_iptable_rules, current_iptable_rules)
)
iptable_rules_diff = [
li for li in difflib.ndiff(original_iptable_rules, current_iptable_rules) if li[0] != ' '
]
logger.info("iptable_rules_diff {}".format(iptable_rules_diff))
pytest_assert(
set(original_iptable_rules) == set(current_iptable_rules),
"iptable rules are not suppose to change after test. diff: {}".format(
iptable_rules_diff)
)
pytest_assert(wait_until(5, 1, 0, check_original_and_current_iptable_rule, duthost, original_iptable_rules),
"The current iptable rules doesn't match the original one")

current_cacl_tables = get_cacl_tables(duthost)
logger.info("original cacl tables: {}, current cacl tables: {}".format(
Expand All @@ -94,7 +84,7 @@ def setup_env(duthosts, rand_one_dut_hostname):
cacl_tables_diff = [
li for li in difflib.ndiff(original_cacl_tables, current_cacl_tables) if li[0] != ' '
]
logger.info("cacl_tables_diff {}".format(iptable_rules_diff))
logger.info("cacl_tables_diff {}".format(cacl_tables_diff))
pytest_assert(
set(original_cacl_tables) == set(current_cacl_tables),
"cacl tables are not suppose to change after test. diff: {}".format(
Expand All @@ -104,6 +94,23 @@ def setup_env(duthosts, rand_one_dut_hostname):
delete_checkpoint(duthost)


def check_original_and_current_iptable_rule(duthost, original_iptable_rules):
current_iptable_rules = get_iptable_rules(duthost)
logger.info("original iptable rules: {}, current iptable rules: {}".format(
original_iptable_rules, current_iptable_rules)
)
iptable_rules_diff = [
li for li in difflib.ndiff(original_iptable_rules, current_iptable_rules) if li[0] != ' '
]
logger.info("iptable_rules_diff {}".format(iptable_rules_diff))

if set(original_iptable_rules) == set(current_iptable_rules):
return True
else:
logger.error(f"iptable rules are not suppose to change after test. diff: {iptable_rules_diff}")
return False


def expect_acl_table_match(duthost, table_name, expected_content_list):
"""Check if acl table show as expected
"""
Expand Down
Loading