From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft] tests: py: don't use a fixed filename
Date: Thu, 9 Apr 2026 13:58:47 +0200 [thread overview]
Message-ID: <20260409132649.8571-1-fw@strlen.de> (raw)
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
reply other threads:[~2026-04-09 13:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260409132649.8571-1-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.