* [PATCH nft] tests: py: don't use a fixed filename
@ 2026-04-09 11:58 Florian Westphal
0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2026-04-09 11:58 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
Using a predicatable filename in /tmp is not good practice.
This test runs with uid 0 and stray symlink could lead to unwanted
effects. Use a temporary file and auto-delete it unless -k/--keep gets
passed to us.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
tests/py/nft-test.py | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 53fd3f7ae6fe..c83a737a5f3b 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -30,13 +30,13 @@ os.environ['TZ'] = 'UTC-2'
from nftables import Nftables
TESTS_DIRECTORY = ["any", "arp", "bridge", "inet", "ip", "ip6", "netdev"]
-LOGFILE = "/tmp/nftables-test.log"
log_file = None
table_list = []
chain_list = []
all_set = dict()
obj_list = []
signal_received = 0
+auto_delete = True
class Colors:
@@ -1523,6 +1523,9 @@ def main():
parser.add_argument('-l', '--library', default=None,
help='path to libntables.so.1, overrides --host')
+ parser.add_argument('-k', '--keep', default=False,
+ help='keep log file around after tests')
+
parser.add_argument('-N', '--no-netns', action='store_true',
dest='no_netns',
help='Do not run in own network namespace')
@@ -1574,6 +1577,11 @@ def main():
"You need to build the project." % args.library)
return 99
+ global auto_delete
+
+ if args.keep:
+ auto_delete = False
+
if args.enable_schema and not args.enable_json:
print_error("Option --schema requires option --json")
return 99
@@ -1585,10 +1593,13 @@ def main():
tests = passed = warnings = errors = 0
global log_file
try:
- log_file = open(LOGFILE, 'w')
- print_info("Log will be available at %s" % LOGFILE)
+ log_file = tempfile.NamedTemporaryFile(prefix="nftables-test-py-", suffix=".log", mode='w', delete=auto_delete)
+ if auto_delete:
+ print_info("Log file %s will not be retained. Pass -k to keep it.")
+ else:
+ print_info("Log will be available at %s" % log_file.name)
except IOError:
- print_error("Cannot open log file %s" % LOGFILE)
+ print_error("Cannot create a temporary log file")
return 99
file_list = []
--
2.52.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-09 13:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 11:58 [PATCH nft] tests: py: don't use a fixed filename Florian Westphal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.