Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'tools-ynl-add-schema-checking'

Donald Hunter says:

====================
tools: ynl: add schema checking

Add schema checking and yaml linting for the YNL specs.

Patch 1 adds a schema_check make target using a pyynl --validate option
Patch 2 adds a lint make target using yamllint
Patches 3,4 fix issues reported by make -C tools/net/ynl lint schema_check
====================

Link: https://patch.msgid.link/20251127123502.89142-1-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+40 -9
+1 -1
Documentation/netlink/specs/conntrack.yaml
··· 457 457 name: labels 458 458 type: binary 459 459 - 460 - name: labels mask 460 + name: labels-mask 461 461 type: binary 462 462 - 463 463 name: synproxy
+1 -1
Documentation/netlink/specs/ethtool.yaml
··· 1269 1269 - 1270 1270 name: hist 1271 1271 type: nest 1272 - multi-attr: True 1272 + multi-attr: true 1273 1273 nested-attributes: fec-hist 1274 1274 - 1275 1275 name: fec
+1 -1
Documentation/netlink/specs/nftables.yaml
··· 915 915 type: string 916 916 doc: Name of set to use 917 917 - 918 - name: set id 918 + name: set-id 919 919 type: u32 920 920 byte-order: big-endian 921 921 doc: ID of set to use
+21 -1
tools/net/ynl/Makefile
··· 12 12 libdir ?= $(prefix)/$(libdir_relative) 13 13 includedir ?= $(prefix)/include 14 14 15 + SPECDIR=../../../Documentation/netlink/specs 16 + 15 17 SUBDIRS = lib generated samples ynltool tests 16 18 17 19 all: $(SUBDIRS) libynl.a ··· 56 54 run_tests: 57 55 @$(MAKE) -C tests run_tests 58 56 59 - .PHONY: all clean distclean install run_tests $(SUBDIRS) 57 + lint: 58 + yamllint $(SPECDIR) 59 + 60 + schema_check: 61 + @N=1; \ 62 + for spec in $(SPECDIR)/*.yaml ; do \ 63 + NAME=$$(basename $$spec) ; \ 64 + OUTPUT=$$(./pyynl/cli.py --spec $$spec --validate) ; \ 65 + if [ $$? -eq 0 ] ; then \ 66 + echo "ok $$N $$NAME schema validation" ; \ 67 + else \ 68 + echo "not ok $$N $$NAME schema validation" ; \ 69 + echo "$$OUTPUT" ; \ 70 + echo ; \ 71 + fi ; \ 72 + N=$$((N+1)) ; \ 73 + done 74 + 75 + .PHONY: all clean distclean install run_tests lint schema_check $(SUBDIRS)
+16 -5
tools/net/ynl/pyynl/cli.py
··· 10 10 import textwrap 11 11 12 12 sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix()) 13 - from lib import YnlFamily, Netlink, NlError 13 + from lib import YnlFamily, Netlink, NlError, SpecFamily 14 14 15 15 sys_schema_dir='/usr/share/ynl' 16 16 relative_schema_dir='../../../../Documentation/netlink' ··· 127 127 group.add_argument('--list-msgs', action='store_true') 128 128 group.add_argument('--list-attrs', dest='list_attrs', metavar='OPERATION', type=str, 129 129 help='List attributes for an operation') 130 + group.add_argument('--validate', action='store_true') 130 131 131 132 parser.add_argument('--duration', dest='duration', type=int, 132 133 help='when subscribed, watch for DURATION seconds') ··· 169 168 170 169 if args.family: 171 170 spec = f"{spec_dir()}/{args.family}.yaml" 172 - if args.schema is None and spec.startswith(sys_schema_dir): 173 - args.schema = '' # disable schema validation when installed 174 - if args.process_unknown is None: 175 - args.process_unknown = True 176 171 else: 177 172 spec = args.spec 178 173 if not os.path.isfile(spec): 179 174 raise Exception(f"Spec file {spec} does not exist") 175 + 176 + if args.validate: 177 + try: 178 + SpecFamily(spec, args.schema) 179 + except Exception as error: 180 + print(error) 181 + exit(1) 182 + return 183 + 184 + if args.family: # set behaviour when using installed specs 185 + if args.schema is None and spec.startswith(sys_schema_dir): 186 + args.schema = '' # disable schema validation when installed 187 + if args.process_unknown is None: 188 + args.process_unknown = True 180 189 181 190 ynl = YnlFamily(spec, args.schema, args.process_unknown, 182 191 recv_size=args.dbg_small_recv)