From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 10/13] tools: ynl: load jsonschema on demand
Date: Fri, 27 Jan 2023 20:32:14 -0800 [thread overview]
Message-ID: <20230128043217.1572362-11-kuba@kernel.org> (raw)
In-Reply-To: <20230128043217.1572362-1-kuba@kernel.org>
The CLI script tries to validate jsonschema by default.
It's seems better to validate too many times than too few.
However, when copying the scripts to random servers having
to install jsonschema is tedious. Load jsonschema via
importlib, and let the user opt out.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/cli.py | 4 ++++
tools/net/ynl/lib/nlspec.py | 11 ++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/tools/net/ynl/cli.py b/tools/net/ynl/cli.py
index 05d1f4069ce1..e64f1478764f 100755
--- a/tools/net/ynl/cli.py
+++ b/tools/net/ynl/cli.py
@@ -13,6 +13,7 @@ from lib import YnlFamily
parser = argparse.ArgumentParser(description='YNL CLI sample')
parser.add_argument('--spec', dest='spec', type=str, required=True)
parser.add_argument('--schema', dest='schema', type=str)
+ parser.add_argument('--no-schema', action='store_true')
parser.add_argument('--json', dest='json_text', type=str)
parser.add_argument('--do', dest='do', type=str)
parser.add_argument('--dump', dest='dump', type=str)
@@ -20,6 +21,9 @@ from lib import YnlFamily
parser.add_argument('--subscribe', dest='ntf', type=str)
args = parser.parse_args()
+ if args.no_schema:
+ args.schema = ''
+
attrs = {}
if args.json_text:
attrs = json.loads(args.json_text)
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index 4aa3b1ad97f0..e204679ad8b7 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -1,12 +1,16 @@
# SPDX-License-Identifier: BSD-3-Clause
import collections
-import jsonschema
+import importlib
import os
import traceback
import yaml
+# To be loaded dynamically as needed
+jsonschema = None
+
+
class SpecElement:
"""Netlink spec element.
@@ -197,9 +201,14 @@ import yaml
if schema_path is None:
schema_path = os.path.dirname(os.path.dirname(spec_path)) + f'/{self.proto}.yaml'
if schema_path:
+ global jsonschema
+
with open(schema_path, "r") as stream:
schema = yaml.safe_load(stream)
+ if jsonschema is None:
+ jsonschema = importlib.import_module("jsonschema")
+
jsonschema.validate(self.yaml, schema)
self.attr_sets = collections.OrderedDict()
--
2.39.1
next prev parent reply other threads:[~2023-01-28 4:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 4:32 [PATCH net-next 00/13] tools: ynl: more docs and basic ethtool support Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 01/13] tools: ynl-gen: prevent do / dump reordering Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 02/13] tools: ynl: move the cli and netlink code around Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 03/13] tools: ynl: add an object hierarchy to represent parsed spec Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 04/13] tools: ynl: use the common YAML loading and validation code Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 05/13] tools: ynl: add support for types needed by ethtool Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 06/13] tools: ynl: support directional enum-model in CLI Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 07/13] tools: ynl: support multi-attr Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 08/13] tools: ynl: support pretty printing bad attribute names Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 09/13] tools: ynl: use operation names from spec on the CLI Jakub Kicinski
2023-01-28 4:32 ` Jakub Kicinski [this message]
2023-01-28 4:32 ` [PATCH net-next 11/13] netlink: specs: finish up operation enum-models Jakub Kicinski
2023-01-30 19:32 ` Stanislav Fomichev
2023-01-28 4:32 ` [PATCH net-next 12/13] netlink: specs: add partial specification for ethtool Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 13/13] docs: netlink: add a starting guide for working with specs Jakub Kicinski
2023-01-30 19:36 ` [PATCH net-next 00/13] tools: ynl: more docs and basic ethtool support Stanislav Fomichev
2023-01-30 19:51 ` Jakub Kicinski
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=20230128043217.1572362-11-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 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).