summaryrefslogtreecommitdiffstats
path: root/iptables-test.py
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2022-02-04 18:45:22 +0100
committerPhil Sutter <phil@nwl.cc>2022-02-10 16:42:53 +0100
commit1407a9c45350839073842bcc8c84ce524db3a119 (patch)
tree940ec058ca59e4652ae516f44ea609e2da5b62f2 /iptables-test.py
parentfc8f7289a678d0a4d12383f21415ca8516352705 (diff)
tests: iptables-test: Support variant deviation
Some test results are not consistent between variants: * CLUSTERIP is not supported with nft_compat, so all related tests fail with iptables-nft. * iptables-legacy mandates TCPMSS be combined with SYN flag match, iptables-nft does not care. (Or precisely, xt_TCPMSS.ko can't validate match presence.) Introduce an optional fourth test spec field to specify the variant it applies to. Consequently, the opposite result is expected with the other variant. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables-test.py')
-rwxr-xr-xiptables-test.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/iptables-test.py b/iptables-test.py
index 95fa11b1..b49afcab 100755
--- a/iptables-test.py
+++ b/iptables-test.py
@@ -182,6 +182,28 @@ def execute_cmd(cmd, filename, lineno):
return ret
+def variant_res(res, variant):
+ '''
+ Adjust expected result with given variant
+
+ If expected result is scoped to a variant, the other one yields a different
+ result. Therefore map @res to itself if given variant is current, invert it
+ otherwise.
+
+ :param res: expected result from test spec ("OK" or "FAIL")
+ :param variant: variant @res is scoped to by test spec ("NFT" or "LEGACY")
+ '''
+ variant_executable = {
+ "NFT": "xtables-nft-multi",
+ "LEGACY": "xtables-legacy-multi"
+ }
+ res_inverse = { "OK": "FAIL", "FAIL": "OK" }
+
+ if variant_executable[variant] == EXECUTABLE:
+ return res
+ return res_inverse[res]
+
+
def run_test_file(filename, netns):
'''
Runs a test file
@@ -275,6 +297,9 @@ def run_test_file(filename, netns):
rule_save = chain + " " + item[1]
res = item[2].rstrip()
+ if len(item) > 3:
+ res = variant_res(res, item[3].rstrip())
+
ret = run_test(iptables, rule, rule_save,
res, filename, lineno + 1, netns)