kontron / python-ipmi

A pure python IPMI library
GNU Lesser General Public License v2.1
187 stars 74 forks source link

interfaces.ipmitool: Throw exception if ipmitool not found #120

Closed patrislav1 closed 2 years ago

patrislav1 commented 2 years ago

pyipmi throws confusing error messages when ipmitool interface is used but ipmitool is not installed on the system, example:

  File "/home/jan/.local/lib/python3.8/site-packages/pyipmi/__init__.py", line 225, in raw_command
    return self.interface.send_and_receive_raw(self.target, lun, netfn,
  File "/home/jan/.local/lib/python3.8/site-packages/pyipmi/interfaces/ipmitool.py", line 143, in send_and_receive_raw
    cc, rsp = self._parse_output(output)
  File "/home/jan/.local/lib/python3.8/site-packages/pyipmi/interfaces/ipmitool.py", line 124, in _parse_output
    rsp = array('B', [
  File "/home/jan/.local/lib/python3.8/site-packages/pyipmi/interfaces/ipmitool.py", line 125, in <listcomp>
    int(value, 16) for value in hexstr.split(' ')

This patch checks the returncode of the shell invoking ipmitool for 127 (error code for 'command not found') and throws an exception with a clear error message.

(BTW, do we really need shell=True in _run_ipmitool()? If it can be omitted maybe it could improve performance).

hthiery commented 2 years ago

@patrislav1 Hi, thank you for the fix. For the shell=True thing: if you could do a patch for this change and you can confirm that that has no impact on the behavior the change will be welcome.