From: Phil Sutter <phil@nwl.cc>
To: Jeremy Sowden <jeremy@azazel.net>
Cc: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft] tests: py: use `os.unshare` Python function
Date: Wed, 11 Mar 2026 00:08:59 +0100 [thread overview]
Message-ID: <abCki9aBa8wVBvQi@orbyte.nwl.cc> (raw)
In-Reply-To: <20260306183553.GA5468@celephais.dreamlands>
Hi Jeremy,
On Fri, Mar 06, 2026 at 06:35:53PM +0000, Jeremy Sowden wrote:
> On 2026-03-06, at 18:41:06 +0100, Phil Sutter wrote:
> >On Thu, Mar 05, 2026 at 05:53:58PM +0000, Jeremy Sowden wrote:
> > > Since Python 3.12 the standard library has included an `os.unshare` function.
> > > Use it if it is available.
> >
> > This patch breaks py test suite cases involving time-related matches,
> > e.g. 'meta time "1970-05-23 21:07:14"'. It expects:
> >
> > | cmp eq reg 1 0x002bd503 0x43f05400
>
> $ TZ=UTC-2 perl -MPOSIX=strftime -le 'my $ns = hex $ARGV[0]; print strftime "%Y-%m-%d %H:%M:%S", localtime int $ns / 1000000000' 0x002bd50343f05400
> 1970-05-23 21:07:14
>
> > but instead the rule serializes into:
> >
> > | cmp eq reg 1 0x002bd849 0x74a8f400
>
> $ TZ=UTC-2 perl -MPOSIX=strftime -le 'my $ns = hex $ARGV[0]; print strftime "%Y-%m-%d %H:%M:%S", localtime int $ns / 1000000000' 0x002bd84974a8f400
> 1970-05-23 22:07:14
>
> > Do you see that too?
>
> Yes, e.g.:
>
> 6: WARNING: line 4: 'add rule netdev test-netdev egress meta time > "2022-07-01 11:00:00" accept': '[ cmp gt reg 1 0x16fda8f3 0x1977a000 ]' mismatches '[ cmp gt reg 1 0x16fdac39 0x4a304000 ]'
>
> As with your example, the discrepancy is an hour:
>
> $ TZ=UTC-2 perl -MPOSIX=strftime -le 'my $ns = hex $ARGV[0]; print strftime "%Y-%m-%d %H:%M:%S", localtime int $ns / 1000000000' 0x16fda8f31977a000
> 2022-07-01 11:00:00
>
> $ TZ=UTC-2 perl -MPOSIX=strftime -le 'my $ns = hex $ARGV[0]; print strftime "%Y-%m-%d %H:%M:%S", localtime int $ns / 1000000000' 0x16fdac394a304000
> 2022-07-01 12:00:00
>
> which suggests it's time-zone related. Didn't see anything about that
> in the doc's. Will take a closer look. Apologies.
Yes, it's odd. Neither unshare module nor 'unshare -n' behave like this,
even though os.unshare is described as doing the same as unshare command
does. It also doesn't mangle os.environ['TZ'] value, no idea why it
messes with this.
> PS UTC-2 is exotic. :)
Maybe it's Ander Juaristi's native timezone, he added the tests in
commit 0518ea3f70d8c ("tests: add meta time test cases"). And then I
did:
commit 7e326d697ecf43ea029de5584e59701eb61ca87e
Author: Phil Sutter <phil@nwl.cc>
Date: Sat Nov 16 22:32:18 2019 +0100
tests/py: Set a fixed timezone in nft-test.py
Payload generated for 'meta time' matches depends on host's timezone and
DST setting. To produce constant output, set a fixed timezone in
nft-test.py. Choose UTC-2 since most payloads are correct then, adjust
the remaining two tests.
Fixes: 0518ea3f70d8c ("tests: add meta time test cases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Ander Juaristi <a@juaristi.eus>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
So that's how UTC-2 became py test suite's native timezone. :D
Cheers, Phil
next prev parent reply other threads:[~2026-03-10 23:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 17:53 [PATCH nft] tests: py: use `os.unshare` Python function Jeremy Sowden
2026-03-05 22:15 ` Phil Sutter
2026-03-06 17:41 ` Phil Sutter
2026-03-06 18:35 ` Jeremy Sowden
2026-03-10 23:08 ` Phil Sutter [this message]
2026-03-12 22:14 ` Florian Westphal
2026-03-12 22:20 ` Pablo Neira Ayuso
2026-03-13 7:57 ` Jeremy Sowden
2026-03-13 7:56 ` Jeremy Sowden
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=abCki9aBa8wVBvQi@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=jeremy@azazel.net \
--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.