Commit 48993e22 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Jakub Kicinski
Browse files

tools: ynl: replace print with NlError



Instead of dumping the error on the stdout, make the callee and
opportunity to decide what to do with it. This is mostly for the
ethtool testing.

Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a353318e
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -67,6 +67,14 @@ class Netlink:
    NLMSGERR_ATTR_MISS_NEST = 6
    NLMSGERR_ATTR_MISS_NEST = 6




class NlError(Exception):
  def __init__(self, nl_msg):
    self.nl_msg = nl_msg

  def __str__(self):
    return f"Netlink error: {os.strerror(-self.nl_msg.error)}\n{self.nl_msg}"


class NlAttr:
class NlAttr:
    type_formats = { 'u8' : ('B', 1), 's8' : ('b', 1),
    type_formats = { 'u8' : ('B', 1), 's8' : ('b', 1),
                     'u16': ('H', 2), 's16': ('h', 2),
                     'u16': ('H', 2), 's16': ('h', 2),
@@ -551,9 +559,7 @@ class YnlFamily(SpecFamily):
                    self._decode_extack(msg, op.attr_set, nl_msg.extack)
                    self._decode_extack(msg, op.attr_set, nl_msg.extack)


                if nl_msg.error:
                if nl_msg.error:
                    print("Netlink error:", os.strerror(-nl_msg.error))
                    raise NlError(nl_msg)
                    print(nl_msg)
                    return
                if nl_msg.done:
                if nl_msg.done:
                    if nl_msg.extack:
                    if nl_msg.extack:
                        print("Netlink warning:")
                        print("Netlink warning:")