diff options
author | Phil Sutter <phil@nwl.cc> | 2021-02-04 15:58:25 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2021-11-30 14:57:46 +0100 |
commit | 38f1546ff34ae93d15caf5d003951aeb184a0396 (patch) | |
tree | 24a2084b1e564a7b528c1b5d86afec8987daff53 /tests | |
parent | 443503f53530c3829e7805018b3f7b55e6dcd3c4 (diff) |
tests/py: Avoid duplicate records in *.got files
If payloads don't contain family-specific bits, they may sit in a single
*.payload file for all tested families. In such case, nft-test.py will
consequently write dissenting payloads into a single *.got file. To
avoid the duplicate entries, check if a matching record exists already
before writing it out.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/py/nft-test.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py index f8f9341c..04dac8d7 100755 --- a/tests/py/nft-test.py +++ b/tests/py/nft-test.py @@ -809,17 +809,26 @@ def rule_add(rule, filename, lineno, force_all_family_option, filename_path): if state == "ok" and not payload_check(table_payload_expected, payload_log, cmd): error += 1 - gotf = open("%s.got" % payload_path, 'a') + + try: + gotf = open("%s.got" % payload_path) + gotf_payload_expected = payload_find_expected(gotf, rule[0]) + gotf.close() + except: + gotf_payload_expected = None payload_log.seek(0, 0) - gotf.write("# %s\n" % rule[0]) - while True: - line = payload_log.readline() - if line == "": - break - gotf.write(line) - gotf.close() - print_warning("Wrote payload for rule %s" % rule[0], - gotf.name, 1) + if not payload_check(gotf_payload_expected, payload_log, cmd): + gotf = open("%s.got" % payload_path, 'a') + payload_log.seek(0, 0) + gotf.write("# %s\n" % rule[0]) + while True: + line = payload_log.readline() + if line == "": + break + gotf.write(line) + gotf.close() + print_warning("Wrote payload for rule %s" % rule[0], + gotf.name, 1) # Check for matching ruleset listing numeric_proto_old = nftables.set_numeric_proto_output(True) |