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

No exception raised with neither `ip` nor `ifconfig` are available #44

Closed LoyVanBeek closed 4 years ago

LoyVanBeek commented 4 years ago

Coming from https://github.com/ros2/ros2cli/issues/425, ifcfg reports no interfaces when neither ip nor ifconfig are available (as shown in the debug session output below)

I think this is incorrect and that ifcfg should raise an exception in that (dire, uncommon) case.

ipdb> break /usr/lib/python3/dist-packages/ifcfg/tools.py:32                                                                                                                                                                                   
Breakpoint 1 at /usr/lib/python3/dist-packages/ifcfg/tools.py:32
ipdb> c                                                                                                                                                                                                                                        
> /usr/lib/python3/dist-packages/ifcfg/tools.py(32)exec_cmd()
     31     # https://github.com/ftao/python-ifcfg/issues/17
1--> 32     proc = Popen(cmd_args, stdout=PIPE, stderr=PIPE, universal_newlines=False, shell=True)
     33     stdout, stderr = proc.communicate()

ipdb> n                                                                                                                                                                                                                                        
> /usr/lib/python3/dist-packages/ifcfg/tools.py(33)exec_cmd()
1    32     proc = Popen(cmd_args, stdout=PIPE, stderr=PIPE, universal_newlines=False, shell=True)
---> 33     stdout, stderr = proc.communicate()
     34     proc.wait()

ipdb>                                                                                                                                                                                                                                          
> /usr/lib/python3/dist-packages/ifcfg/tools.py(34)exec_cmd()
     33     stdout, stderr = proc.communicate()
---> 34     proc.wait()
     35 

ipdb> cmd_args                                                                                                                                                                                                                                 
'ip address show'
ipdb> stdout                                                                                                                                                                                                                                   
b''
ipdb> stderr                                                                                                                                                                                                                                   
b'/bin/sh: 1: ip: not found\n'
ipdb>   
LoyVanBeek commented 4 years ago

Not sure how this should be solved, I can create a PR when a correct approach is determined

benjaoming commented 4 years ago

@LoyVanBeek - thanks for opening an issue and explaining - seems like a very narrow case, I have no objections to failing with a loud and clear exception for this!

I would think that the exception should happen when trying to invoke ip and finding that it doesn't exist, but not at for instance module load time.

LoyVanBeek commented 4 years ago

What I had in mind was raising an exception in the get_command method of UnixIPParser and/or to check the return code.