From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com,
Jakub Kicinski <kuba@kernel.org>,
Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next v2 3/6] selftests: net: py: extract tool logic
Date: Mon, 29 Apr 2024 07:44:23 -0700 [thread overview]
Message-ID: <20240429144426.743476-4-kuba@kernel.org> (raw)
In-Reply-To: <20240429144426.743476-1-kuba@kernel.org>
The main use of the ip() wrapper over cmd() is that it can parse JSON.
cmd("ip -j link show") will return stdout as a string, and test has
to call json.loads(). With ip("link show", json=True) the return value
will be already parsed.
More tools (ethtool, bpftool etc.) support the --json switch.
To avoid having to wrap all of them individually create a tool()
helper.
Switch from -j to --json (for ethtool).
While at it consume the netns attribute at the ip() level.
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2:
- use consistent quote type
- use format string to force string conversion of NetNS class
---
tools/testing/selftests/net/lib/py/utils.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index d3715e6c21f2..4930a90a64ea 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -56,10 +56,10 @@ import time
return self.process(terminate=self.terminate)
-def ip(args, json=None, ns=None, host=None):
- cmd_str = "ip "
+def tool(name, args, json=None, ns=None, host=None):
+ cmd_str = name + ' '
if json:
- cmd_str += '-j '
+ cmd_str += '--json '
cmd_str += args
cmd_obj = cmd(cmd_str, ns=ns, host=host)
if json:
@@ -67,6 +67,12 @@ import time
return cmd_obj
+def ip(args, json=None, ns=None, host=None):
+ if ns:
+ args = f'-netns {ns} ' + args
+ return tool('ip', args, json=json, host=host)
+
+
def rand_port():
"""
Get unprivileged port, for now just random, one day we may decide to check if used.
--
2.44.0
next prev parent reply other threads:[~2024-04-29 14:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 14:44 [PATCH net-next v2 0/6] selftests: net: page_poll allocation error injection Jakub Kicinski
2024-04-29 14:44 ` [PATCH net-next v2 1/6] net: page_pool: support " Jakub Kicinski
2024-04-29 14:44 ` [PATCH net-next v2 2/6] selftests: drv-net-hw: support using Python from net hw tests Jakub Kicinski
2024-04-29 14:44 ` Jakub Kicinski [this message]
2024-04-29 14:44 ` [PATCH net-next v2 4/6] selftests: net: py: avoid all ports < 10k Jakub Kicinski
2024-04-29 14:44 ` [PATCH net-next v2 5/6] selftests: drv-net: support generating iperf3 load Jakub Kicinski
2024-04-29 14:44 ` [PATCH net-next v2 6/6] selftests: drv-net-hw: add test for memory allocation failures with page pool Jakub Kicinski
2024-04-30 15:20 ` [PATCH net-next v2 0/6] selftests: net: page_poll allocation error injection patchwork-bot+netdevbpf
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=20240429144426.743476-4-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
/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.