python-ifcfg
python-ifcfg copied to clipboard
Exception thrown in 0.20 and 0.21 (but not in 0.19) when ifconfig/ip not available
Environment:
- Python 3.6.9 (default, Apr 18 2020, 01:56:04)
- Inside Dockerfile based on arm32v7/ubuntu:bionic
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
'
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?
@jamalex if Kolibri needs a custom exception, I agree that it would seem semantic/appropriate to replace ValueError :+1: