ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

Exception thrown in 0.20 and 0.21 (but not in 0.19) when ifconfig/ip not available #55

Open jamalex opened 4 years ago

jamalex commented 4 years ago

Environment:

Warning shown:

WARNING:ifcfg:Neither `ifconfig` (`ifconfig -a`) nor `ip` (`ip address show`) commands are available, listing network interfaces is likely to fail

In 0.19, it gracefully failed by returning an empty dictionary, whereas in 0.20 and 0.21 it fails by raising an Exception, interrupting execution.

>>> ifcfg.__version__
'0.19'
>>> ifcfg.interfaces()
{}
>>> ifcfg.__version__
'0.20'
>>> ifcfg.interfaces()
/bin/sh: 1: ip: not found

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/ifcfg/__init__.py", line 70, in interfaces
    return Parser(ifconfig=ifconfig).interfaces
  File "/usr/local/lib/python3.6/dist-packages/ifcfg/parser.py", line 30, in __init__
    self.parse(self.ifconfig_data)
  File "/usr/local/lib/python3.6/dist-packages/ifcfg/parser.py", line 57, in parse
    raise ValueError("Non-zero return code, reporting error-code '{}'".format(errors))
ValueError: Non-zero return code, reporting error-code '/bin/sh: 1: ip: not found
'
>>> ifcfg.__version__
'0.21'
>>> ifcfg.interfaces()
ERROR:ifcfg.parser:/bin/sh: 1: ip: not found

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/kolibri/dist/ifcfg/__init__.py", line 70, in interfaces
    return Parser(ifconfig=ifconfig).interfaces
  File "/usr/local/lib/python3.6/dist-packages/kolibri/dist/ifcfg/parser.py", line 30, in __init__
    self.parse(self.ifconfig_data)
  File "/usr/local/lib/python3.6/dist-packages/kolibri/dist/ifcfg/parser.py", line 57, in parse
    raise ValueError("Non-zero return code, reporting error-code '{}'".format(errors))
ValueError: Non-zero return code, reporting error-code '/bin/sh: 1: ip: not found
'
jamalex commented 4 years ago

Ah, it seems this was intentional... https://github.com/ftao/python-ifcfg/issues/44

I will update the calling code to deal with this. Leaving this issue open because it seems a bit strange to me to be throwing a raw ValueError instead of something more specific. If it's going to use a more generic base Python exception, something like an EnvironmentError might be more canonical?

benjaoming commented 4 years ago

@jamalex if Kolibri needs a custom exception, I agree that it would seem semantic/appropriate to replace ValueError :+1: