netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Haller <thaller@redhat.com>
To: Phil Sutter <phil@nwl.cc>
Cc: NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft 1/1] tests/shell: sanitize "handle" in JSON output
Date: Tue, 21 Nov 2023 13:10:11 +0100	[thread overview]
Message-ID: <f4b86e5318556be07a8c86c3fdd551ad5e22a831.camel@redhat.com> (raw)
In-Reply-To: <ZVgjLFGvHqoXXvjd@orbyte.nwl.cc>

Hi,


On Sat, 2023-11-18 at 03:36 +0100, Phil Sutter wrote:
> On Fri, Nov 17, 2023 at 06:18:45PM +0100, Thomas Haller wrote:
> > The "handle" in JSON output is not stable. Sanitize/normalizeit to
> > 1216.
> > 
> > The number is chosen arbitrarily, but it's somewhat unique in the
> > code
> > base. So when you see it, you may guess it originates from
> > sanitization.
> 
> Valid handles are monotonic starting at 1. Using 0 as a replacement
> is
> too simple?

Changed.

> 
> > Signed-off-by: Thomas Haller <thaller@redhat.com>
> > ---
> > Note that only a few .json-nft files are adjusted, because
> > otherwise the
> > patch is too large. Before applying, you need to adjust them all,
> > by
> > running `./tests/shell/run-tests.sh -g`.
> 
> Just put the bulk change into a second patch?

it would require 3 patches to stay below the limit.

Also, it blows up the inbox by everybody on the list by 850K (57k
gzipped). The rest of the patch is generated. Just generate it.

Alternatively,

  git fetch https://gitlab.freedesktop.org/thaller/nftables df984038a33c6da5b159e6f6458351c4fa673bf1
  git merge FETCH_HEAD
  


> 
> [...]
> > diff --git a/tests/shell/helpers/json-sanitize-ruleset.sh
> > b/tests/shell/helpers/json-sanitize-ruleset.sh
> > index 270a6107e0aa..3b66adabf055 100755
> > --- a/tests/shell/helpers/json-sanitize-ruleset.sh
> > +++ b/tests/shell/helpers/json-sanitize-ruleset.sh
> > @@ -6,7 +6,14 @@ die() {
> >  }
> >  
> >  do_sed() {
> > -	sed '1s/\({"nftables": \[{"metainfo": {"version": "\)[0-
> > 9.]\+\(", "release_name": "\)[^"]\+\(",
> > "\)/\1VERSION\2RELEASE_NAME\3/' "$@"
> > +	# Normalize the "version"/"release_name", otherwise we
> > have to regenerate the
> > +	# JSON output upon new release.
> > +	#
> > +	# Also, "handle" are not stable. Normalize them to 1216
> > (arbitrarily chosen).
> > +	sed \
> > +		-e '1s/\({"nftables": \[{"metainfo": {"version":
> > "\)[0-9.]\+\(", "release_name": "\)[^"]\+\(",
> > "\)/\1VERSION\2RELEASE_NAME\3/' \
> > +		-e '1s/"handle": [0-9]\+\>/"handle": 1216/g' \
> > +		"$@"
> >  }
> 
> Why not just drop the whole metainfo object? A dedicated test could
> still ensure its existence.

Normalization should only perform the absolute minimal of tampering.


> Also, scoping these replacements to line 1 is funny with single line
> input. Worse is identifying the change in the resulting diff. Maybe
> write a helper in python which lets you more comfortably sanitize
> input,
> sort attributes by key and output pretty-printed?

You mean, to parse and re-encode the JSON? That introduces additional
changes, which seems undesirable. That's why the regex is limited to
the first line (even if we only expect to ever see one line there).

Also, normalization via 2 regex seems simpler than writing some python.

Well, pretty-printing the output with `jq` would have the advantage,
that future diffs might be smaller (changing individual lines, vs.
replace one large line). Still, I think it's better to keep the amount
of post-processing minimal.


> 
> In general, the long lines in your scripts make them quite hard to
> read.
> Any particular reason why you don't stick to the 80 columns maxim?

I wrapped two lines in the patch.



Thomas


  reply	other threads:[~2023-11-21 12:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 17:18 [PATCH nft 1/1] tests/shell: sanitize "handle" in JSON output Thomas Haller
2023-11-18  2:36 ` Phil Sutter
2023-11-21 12:10   ` Thomas Haller [this message]
2023-11-21 12:39     ` Phil Sutter
2023-11-21 12:58       ` Thomas Haller
2023-11-21 13:40         ` Phil Sutter
2023-11-21 14:35           ` Thomas Haller
2023-11-21 15:19             ` Phil Sutter
2023-11-21 12:45     ` Pablo Neira Ayuso
     [not found]       ` <20231121132331.3401846-1-thaller@redhat.com>
2023-11-22 10:36         ` [PATCH nft v3 " Pablo Neira Ayuso
2023-11-22 10:44           ` Thomas Haller
2023-11-22 11:22             ` Pablo Neira Ayuso
2023-11-22 12:16               ` Thomas Haller
2023-11-22 12:32                 ` Pablo Neira Ayuso

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=f4b86e5318556be07a8c86c3fdd551ad5e22a831.camel@redhat.com \
    --to=thaller@redhat.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).