Commit 771b7012 authored by Donald Hunter's avatar Donald Hunter Committed by Jakub Kicinski

tools/net/ynl: Report netlink errors without stacktrace

ynl does not handle NlError exceptions so they get reported like program
failures. Handle the NlError exceptions and report the netlink errors
more cleanly.

Example now:

Netlink error: No such file or directory
nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
	error: -2	extack: {'bad-attr': '.op'}

Example before:

Traceback (most recent call last):
  File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 81, in <module>
    main()
  File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 69, in main
    reply = ynl.dump(args.dump, attrs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 906, in dump
    return self._op(method, vals, [], dump=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 872, in _op
    raise NlError(nl_msg)
lib.ynl.NlError: Netlink error: No such file or directory
nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
	error: -2	extack: {'bad-attr': '.op'}
Signed-off-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20240306231046.97158-3-donald.hunter@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent cecbc52c
...@@ -6,7 +6,7 @@ import json ...@@ -6,7 +6,7 @@ import json
import pprint import pprint
import time import time
from lib import YnlFamily, Netlink from lib import YnlFamily, Netlink, NlError
class YnlEncoder(json.JSONEncoder): class YnlEncoder(json.JSONEncoder):
...@@ -66,12 +66,16 @@ def main(): ...@@ -66,12 +66,16 @@ def main():
if args.sleep: if args.sleep:
time.sleep(args.sleep) time.sleep(args.sleep)
try:
if args.do: if args.do:
reply = ynl.do(args.do, attrs, args.flags) reply = ynl.do(args.do, attrs, args.flags)
output(reply) output(reply)
if args.dump: if args.dump:
reply = ynl.dump(args.dump, attrs) reply = ynl.dump(args.dump, attrs)
output(reply) output(reply)
except NlError as e:
print(e)
exit(1)
if args.ntf: if args.ntf:
ynl.check_ntf() ynl.check_ntf()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
from .nlspec import SpecAttr, SpecAttrSet, SpecEnumEntry, SpecEnumSet, \ from .nlspec import SpecAttr, SpecAttrSet, SpecEnumEntry, SpecEnumSet, \
SpecFamily, SpecOperation SpecFamily, SpecOperation
from .ynl import YnlFamily, Netlink from .ynl import YnlFamily, Netlink, NlError
__all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet", __all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet",
"SpecFamily", "SpecOperation", "YnlFamily", "Netlink"] "SpecFamily", "SpecOperation", "YnlFamily", "Netlink", "NlError"]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment