-
Notifications
You must be signed in to change notification settings - Fork 20
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 fw upgrade test #93
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. I hope these comments will help you to improve the code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I added a few more comments below.
extras/devices/LVFS/LVFS.py
Outdated
self.run_cmd("sudo fwupdmgr refresh --force") | ||
rc, stdout, stderr = self.run_cmd("sudo fwupdmgr get-devices --json") | ||
logger.debug("$fwupdmgr get-devices = \n%s" % stdout) | ||
for dev in json.loads(stdout)["Devices"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this a lot, and also simplify TestLVFSDevice (see the comment from @nadzyah ) significantly by putting everything below here into a func or method, and feeding it the stdout that you get from the command above. Then instead of having to mock command line args, you can just give it test data and confirm that you get back the expected result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for the suggestion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your changes from my previous review. I hope the following once also will help you to improve the code!
extras/devices/LVFS/LVFS.py
Outdated
logger.info("collect firmware info") | ||
self.run_cmd("sudo fwupdmgr refresh --force") | ||
rc, stdout, stderr = self.run_cmd("sudo fwupdmgr get-devices --json") | ||
logger.debug(f"$fwupdmgr get-devices = \n{stdout}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I should have been more specific about the f-strings. Logging is one place where you generally do NOT want to use f-strings, but use the built-in % syntax instead. It's weird, I know. Many times, it doesn't make a big difference, but it's a good habit to get into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about this. Why is it better to use %s
instead in logging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, the logging library is optimised to use the %s formatting style. I've found these links about it:
https://docs.python.org/3/howto/logging.html#optimization
https://docs.python.org/3/howto/logging-cookbook.html#formatting-styles
with patch("devices.LVFS.LVFS.LVFSDevice.run_cmd") as mock_path: | ||
mock_path.side_effect = self.mock_run_cmd | ||
device = LVFSDevice("", "", "") | ||
print(type(fwupd_data.get_device)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, using print() in test cases is not very helpful. I'm guessing you were trying to get some debug info with this? Did you intend to leave it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I forgot to remove it. Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. +1 from me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from me too, thanks for working on this!
Description
This is the prototype for firmware upgrade test. It will be temporarily placed in
/extras
folder until we figure out a proper way to merge it into device agent codes.This tool relies on DMI chassis type and chassis vendor to determine which firmware update method should be applied on the device. Currently, it only supports
fwupd/LVFS
update method on selected device types (DMI chassis type: All In One, Desktop) with selected OEM (HP, Dell, and Lenovo). Note that it hasn't been widely tested on all supported devices.More detailed usages can be found in README.
Output logs
Here're the logs for two devices. Logs have been renamed (default: upgrade_fw.log) to reflect the different actions.
upgrade_fw_logs.zip
Test
It passed
ruff check *
and unit tests as below.