kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.68k stars 195 forks source link

ethtool parsing doesn't work #577

Open BubuOT opened 6 days ago

BubuOT commented 6 days ago

I tried the new-ish ethtool parser but it doesn't work for me.

This is the output I get from ethtool (version 6.7, haven't tried with 6.9 yet):

# ethtool eth0
Settings for eth0:
    Supported ports: [ TP MII ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Half 1000baseT/Full 
    Supported pause frame use: Symmetric Receive-only
    Supports auto-negotiation: Yes
    Supported FEC modes: Not reported
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Half 1000baseT/Full 
    Advertised pause frame use: Symmetric Receive-only
    Advertised auto-negotiation: Yes
    Advertised FEC modes: Not reported
    Link partner advertised link modes:  10baseT/Half 10baseT/Full 
                                         100baseT/Half 100baseT/Full 
    Link partner advertised pause frame use: Symmetric
    Link partner advertised auto-negotiation: Yes
    Link partner advertised FEC modes: Not reported
    Speed: 100Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: external
    Auto-negotiation: on
    MDI-X: Unknown
    Supports Wake-on: d
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

Here's the jc output with -dd:

# ethtool eth0 | jc --ethtool -dd
ValueError
Python 3.11.9: /usr/bin/python
Wed Jun 26 19:48:43 2024

A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.

 /bin/jc in <module>()
   23         if entry_point.group == group and entry_point.name == name
   24     )
   25     return next(matches).load()
   26 
   27 
   28 globals().setdefault('load_entry_point', importlib_load_entry_point)
   29 
   30 
   31 if __name__ == '__main__':
   32     sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
   33     sys.exit(load_entry_point('jc==1.25.3', 'console_scripts', 'jc')())
sys = <module 'sys' (built-in)>
sys.exit = <built-in function exit>
load_entry_point = <function importlib_load_entry_point>

 /usr/lib/python3.11/site-packages/jc/cli.py in main()

 /usr/lib/python3.11/site-packages/jc/cli.py in run(self=<jc.cli.JcCli object>)

 /usr/lib/python3.11/site-packages/jc/cli.py in _run(self=<jc.cli.JcCli object>)

 /usr/lib/python3.11/site-packages/jc/cli.py in standard_parse_and_print(self=<jc.cli.JcCli object>)

 /usr/lib/python3.11/site-packages/jc/cli.py in create_normal_output(self=<jc.cli.JcCli object>)

 /usr/lib/python3.11/site-packages/jc/parsers/ethtool.py in parse(data='Settings for eth0:\n\tSupported ports: [ TP MII ]\n...(7)\n\t\t\t       drv probe link\n\tLink detected: yes\n', raw=False, quiet=False)

 /usr/lib/python3.11/site-packages/jc/parsers/ethtool.py in _parse_default(data='Settings for eth0:\n\tSupported ports: [ TP MII ]\n...(7)\n\t\t\t       drv probe link\n\tLink detected: yes\n')

ValueError: not enough values to unpack (expected 2, got 1)
    __cause__ = None
    __class__ = <class 'ValueError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of ValueError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of ValueError object>
    __doc__ = 'Inappropriate argument value (of correct type).'
    __eq__ = <method-wrapper '__eq__' of ValueError object>
    __format__ = <built-in method __format__ of ValueError object>
    __ge__ = <method-wrapper '__ge__' of ValueError object>
    __getattribute__ = <method-wrapper '__getattribute__' of ValueError object>
    __getstate__ = <built-in method __getstate__ of ValueError object>
    __gt__ = <method-wrapper '__gt__' of ValueError object>
    __hash__ = <method-wrapper '__hash__' of ValueError object>
    __init__ = <method-wrapper '__init__' of ValueError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of ValueError object>
    __lt__ = <method-wrapper '__lt__' of ValueError object>
    __ne__ = <method-wrapper '__ne__' of ValueError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of ValueError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of ValueError object>
    __repr__ = <method-wrapper '__repr__' of ValueError object>
    __setattr__ = <method-wrapper '__setattr__' of ValueError object>
    __setstate__ = <built-in method __setstate__ of ValueError object>
    __sizeof__ = <built-in method __sizeof__ of ValueError object>
    __str__ = <method-wrapper '__str__' of ValueError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    add_note = <built-in method add_note of ValueError object>
    args = ('not enough values to unpack (expected 2, got 1)',)
    with_traceback = <built-in method with_traceback of ValueError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "/bin/jc", line 33, in <module>
    sys.exit(load_entry_point('jc==1.25.3', 'console_scripts', 'jc')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jc/cli.py", line 965, in main
  File "/usr/lib/python3.11/site-packages/jc/cli.py", line 947, in run
  File "/usr/lib/python3.11/site-packages/jc/cli.py", line 911, in _run
  File "/usr/lib/python3.11/site-packages/jc/cli.py", line 803, in standard_parse_and_print
  File "/usr/lib/python3.11/site-packages/jc/cli.py", line 755, in create_normal_output
  File "/usr/lib/python3.11/site-packages/jc/parsers/ethtool.py", line 435, in parse
  File "/usr/lib/python3.11/site-packages/jc/parsers/ethtool.py", line 339, in _parse_default
ValueError: not enough values to unpack (expected 2, got 1)
kellyjonbrazil commented 6 days ago

Thank you for reporting this - I’ll take a look and see what’s going on.