Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a plugin to get information from ipmitool #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gthvn1
Copy link
Contributor

@gthvn1 gthvn1 commented Sep 6, 2024

Commands are:

  • get_all_sensors: run ipmitool sdr list - returns a JSON string with all sensors
  • get_sensor: run ipmitool sdr get <sensor> - returns details about sensors passed as parameter
  • get_ipmi_lan: returns network info of the IPMI server as a JSON

@gthvn1 gthvn1 self-assigned this Sep 6, 2024
@gthvn1
Copy link
Contributor Author

gthvn1 commented Sep 6, 2024

@AtaxyaNetwork , do you think that it will be possible to test this plugin on a 2crsi server in order to check that output are correct? Thanks a lot for your great help.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

For info, @AtaxyaNetwork tested it several weeks ago and it looks ok. Don't know if it needs to be checked with XO team but for me it looks ok to merge it. @stormi I added you as reviewer but feel free to add someone else :)

@gthvn1 gthvn1 requested a review from stormi October 17, 2024 10:43
Copy link
Member

@stormi stormi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Is ipmitool guaranteed to report information structured as expected by the code on every XCP-ng host? I see no error handling outside the automatic one that will report the exception raised by python. I just tried on a nested XCP-ng VM and got [15:51 xcpng-ci-82-b1 ~]# ipmitool sdr list Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory.
  • Code changes to this repository must come with unit tests in the same repository. Ideally also covering error handling.

README.md Outdated Show resolved Hide resolved
@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

This PR supersedes #47

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

@stormi in case of error it raises a raise_plugin_error raised from decorator error_wrapped. Isn't what is expected? I thought it was the purpose of the decorator.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

In the Readme I see:

Error: raise a XenAPIPlugin.Failure describing the error, to do that: either raise the XenAPIPlugin.Failure exception directly or use error_wrapped from xcpngutils"

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

  • And about tests I will add them

@stormi
Copy link
Member

stormi commented Oct 17, 2024

In the Readme I see:

Error: raise a XenAPIPlugin.Failure describing the error, to do that: either raise the XenAPIPlugin.Failure exception directly or use error_wrapped from xcpngutils"

Yes, but then errors that mean nothing to users will be displayed to users in XO. We'll likely need something better than Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory. hidden in some XO logs when the feature doesn't work as expected.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

In the Readme I see:

Error: raise a XenAPIPlugin.Failure describing the error, to do that: either raise the XenAPIPlugin.Failure exception directly or use error_wrapped from xcpngutils"

Yes, but then errors that mean nothing to users will be displayed to users in XO. We'll likely need something better than Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory. hidden in some XO logs when the feature doesn't work as expected.

You will have "Error parameters: Command '['ipmitool', 'sdr', 'list']' failed with code: 1, stdout: '', stderr: 'Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory". It is the error parameters returned from the wrapper. What should I put instead? I mean it is the error :)

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

Isn't XO that should handle this better? Not sure to see what you want instead of the "real error"?

@stormi
Copy link
Member

stormi commented Oct 17, 2024

Depends what the API user (XO) would like. I think they would appreciate it if we provided a way to discriminate between "not supported on this hardware" and unexpected errors on supported hardware, for example.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

So we should add some XO people to review right?

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 17, 2024

and I'm not sure to know how we can discriminate between "not supported on this hardware" and unexpected errors on supported hardware.

@gthvn1 gthvn1 force-pushed the gtn_add_ipmitool_plugin branch 3 times, most recently from 9b30a15 to e4a6140 Compare October 17, 2024 19:43
@benjamreis
Copy link
Contributor

The PR LGTM - I'd like some error cases tested as @stormi said.

Regarding the error report - IDK how this will be exposed in XO (I think we need more context) so hard to tell - if the error is directly presented to the user as is then a better error message would be preferrable but if its an internal thin in XO that will be procesed before giving a result then the translation can be done their as well.
It's not common for a XAPI plugin to do it usually.

@stormi
Copy link
Member

stormi commented Oct 21, 2024

Another argument for better feature support detection: I think "normal" errors will pollute host logs, so it would seem better to me if XO would first ask "do you have an IPMI device?" and then only if true asks for the data.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 21, 2024

The PR LGTM - I'd like some error cases tested as @stormi said.

Yes it is planed. I'm waiting comment from XO guys (that I already contacted and I should have feedback this week) before implementing error case because I don't know yet what they are expected...

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 21, 2024

Another argument for better feature support detection: I think "normal" errors will pollute host logs, so it would seem better to me if XO would first ask "do you have an IPMI device?" and then only if true asks for the data.

Or as suggested before instead of a new function I can return an explicit string if I have an error "Could not open device" and only raise an exception for other errors. It won't cover all unexpected errors (maybe it will if the only "normal" error is the missing device) but it is an improvement.

@gthvn1 gthvn1 force-pushed the gtn_add_ipmitool_plugin branch 5 times, most recently from dde7c0a to 47e8413 Compare October 22, 2024 12:34
SOURCES/etc/xapi.d/plugins/ipmitool.py Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
SOURCES/etc/xapi.d/plugins/ipmitool.py Outdated Show resolved Hide resolved
SOURCES/etc/xapi.d/plugins/ipmitool.py Outdated Show resolved Hide resolved
SOURCES/etc/xapi.d/plugins/ipmitool.py Outdated Show resolved Hide resolved
SOURCES/etc/xapi.d/plugins/ipmitool.py Outdated Show resolved Hide resolved
SOURCES/etc/xapi.d/plugins/ipmitool.py Outdated Show resolved Hide resolved
@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 23, 2024

After discussing with XO team (Mathieu) I will add a new method to ensure that hardware supports IPMI. This method is_ipmi_module_available will return a boolean (or a Json with true or false if we cannot return a boolean).
Now calling get all sensors, get sensor and Co will always raise a XenAPIPlugin Error in case of failure. It is up to you to check if IPMI is supported on your hardware by calling the new method.

@benjamreis
Copy link
Contributor

What could be even better is still checking in every method that IPMI is available and if not raise a XenAPI.Failure explaining it's not.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 23, 2024

Currently if IPMI is not available when running a command you will have this XenAPIplugin error:

Error code: 1
Error parameters: Command '['ipmitool', 'sdr', 'list']' failed with code: 1, stdout: '', stderr: 'Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0: No such file or directory
', Traceback (most recent call last):
  File "/etc/xapi.d/plugins/xcpngutils/__init__.py", line 127, in wrapper
    return func(*args, **kwds)
  File "/etc/xapi.d/plugins/ipmitool.py", line 33, in sensor_data
    output = run_command(["ipmitool", "sdr", "list"])
  File "/etc/xapi.d/plugins/xcpngutils/__init__.py", line 79, in run_command
    raise ProcessException(code, command, stdout, stderr)
ProcessException: Command '['ipmitool', 'sdr', 'list']' failed with code: 1

So you suggest to replace the stderr of this error for something more clear? Because in this particular case the is_ipmi_device_available will return false so you are able to understand that the raise is related to your system that doesn't support IPMI. I think that if we raise an error we shouldn't modify its stderr and keep exactly what is returned by the command. I think that's why we added a new method to detect "normal" error.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 23, 2024

  • I still need to modify test to add is_ipmi_device_available.
  • I updated the code with comment from @benjamreis about returning a better error message for known error.
  • Add tests failure for all commands (passed, normal failed and abnormal failed)
  • Add a test when the sensor name passed as parameter for sensor_info is wrong

@gthvn1 gthvn1 force-pushed the gtn_add_ipmitool_plugin branch 2 times, most recently from 15efa2f to 0622a7f Compare October 23, 2024 14:26
@gthvn1 gthvn1 requested a review from Wescoeur October 23, 2024 14:40
tests/test_ipmitool.py Outdated Show resolved Hide resolved
tests/test_ipmitool.py Outdated Show resolved Hide resolved
tests/test_ipmitool.py Outdated Show resolved Hide resolved
@gthvn1 gthvn1 force-pushed the gtn_add_ipmitool_plugin branch 2 times, most recently from 21f6007 to d9d4d83 Compare October 24, 2024 08:13
tests/test_ipmitool.py Outdated Show resolved Hide resolved
tests/test_ipmitool.py Outdated Show resolved Hide resolved
tests/test_ipmitool.py Outdated Show resolved Hide resolved
tests/test_ipmitool.py Outdated Show resolved Hide resolved
@gthvn1
Copy link
Contributor Author

gthvn1 commented Oct 24, 2024

All tests added. The last modification is when an error occured when trying to get information about a sensor that doesn't exist.

- is_ipmi_device_available: check that your system supports IPMI by
  running `ipmitool power state`
    - returns true if IPMI is supported, false otherwise
- get_all_sensors: run `ipmitool sdr list`
    - returns a JSON string with all sensors or raise an error
- get_sensor: run `ipmitool sdr get <sensor>`
    - returns details about sensors passed as parameter or raise an
      error
- get_ipmi_lan: run `ipmitool lan print`
    - returns network info of the IPMI server as a JSON or
      raise an error

Signed-off-by: Guillaume <[email protected]>
@gthvn1
Copy link
Contributor Author

gthvn1 commented Nov 13, 2024

For information the last version of the plugin has been tested successfully by @AtaxyaNetwork 👍 on her machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants