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 fw upgrade test #93

Merged
merged 6 commits into from
Sep 13, 2023
Merged

Add fw upgrade test #93

merged 6 commits into from
Sep 13, 2023

Conversation

nancyc12
Copy link
Contributor

@nancyc12 nancyc12 commented Sep 8, 2023

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.

  • HP Z4 G4 workstation (202102-28691) chassis_type: Desktop
  • Dell Optiplex AIO Plus 7410 (202209-30589) chassis_type: All In One
    upgrade_fw_logs.zip

Test

It passed ruff check * and unit tests as below.

nancy-chen@Ubuntu:~/git/testflinger/extras$ python -m coverage run -m pytest .
================================================================================= test session starts =================================================================================
platform linux -- Python 3.10.12, pytest-7.4.1, pluggy-0.13.0
rootdir: /home/nancy-chen/git/testflinger
configfile: pyproject.toml
plugins: cov-4.1.0
collected 7 items                                                                                                                                                                     

devices/LVFS/tests/test_LVFS.py ...                                                                                                                                             [ 42%]
tests/test_upgrade_fw.py ....                                                                                                                                                   [100%]

================================================================================== 7 passed in 0.04s ==================================================================================

Copy link
Contributor

@nadzyah nadzyah left a 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!

extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Show resolved Hide resolved
extras/devices/LVFS/tests/test_LVFS.py Outdated Show resolved Hide resolved
extras/devices/base.py Outdated Show resolved Hide resolved
extras/upgrade_fw.py Outdated Show resolved Hide resolved
extras/upgrade_fw.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@plars plars left a 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/.gitignore Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
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"]:
Copy link
Collaborator

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor

@nadzyah nadzyah left a 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/base.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
extras/devices/LVFS/tests/fwupd_data.py Outdated Show resolved Hide resolved
extras/devices/LVFS/tests/test_LVFS.py Outdated Show resolved Hide resolved
extras/tests/test_upgrade_fw.py Outdated Show resolved Hide resolved
extras/upgrade_fw.py Outdated Show resolved Hide resolved
extras/upgrade_fw.py Show resolved Hide resolved
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}")
Copy link
Collaborator

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.

Copy link

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?

Copy link
Contributor

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

extras/devices/LVFS/LVFS.py Outdated Show resolved Hide resolved
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))
Copy link
Collaborator

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?

Copy link
Contributor Author

@nancyc12 nancyc12 Sep 13, 2023

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.

Copy link
Contributor

@nadzyah nadzyah left a 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

Copy link
Collaborator

@plars plars left a 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!

@plars plars merged commit 2ed4fa7 into main Sep 13, 2023
@plars plars deleted the add-fw-scripts branch September 13, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants