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 fwupdmgr attachment job (New) #1089

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions providers/base/bin/get_firmware_info_fwupd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
# This file is part of Checkbox.
#
# Copyright 2024 Canonical Ltd.
# Written by:
# Stanley Huang <[email protected]>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

import os
import json
import shlex
import subprocess
from checkbox_support.snap_utils.snapd import Snapd


def get_firmware_info_fwupd():

fwupd_snap = Snapd().list("fwupd")
if fwupd_snap:
# Dump firmware info by fwupd snap
subprocess.run(shlex.split("fwupd.fwupdmgr get-devices --json"))
else:
# Dump firmware info by fwupd debian package
fwupd_vers = subprocess.run(
shlex.split("fwupdmgr --version --json"),
capture_output=True)
fwupd_vers = json.loads(fwupd_vers.stdout)

runtime_ver = ()
for ver in fwupd_vers.get("Versions", []):
if (ver.get("Type") == "runtime" and
ver.get("AppstreamId") == "org.freedesktop.fwupd"):
runtime_ver = tuple(map(int, ver.get("Version").split(".")))
stanley31huang marked this conversation as resolved.
Show resolved Hide resolved
# Apply workaround to unset the SNAP for the fwupd issue
# See details from following PR
# https://github.com/canonical/checkbox/pull/1089

# SNAP environ is avaialble, so it's running on checkbox snap
# Unset the environ variable if debian fwupd lower than 1.9.14
if os.environ["SNAP"] and runtime_ver < (1, 9, 14):
del os.environ["SNAP"]

subprocess.run(shlex.split("fwupdmgr get-devices --json"))


if __name__ == "__main__":
try:
get_firmware_info_fwupd()
except Exception as err:
print(err)
stanley31huang marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 65 additions & 0 deletions providers/base/tests/test_get_firmware_info_fwupd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import unittest
from unittest.mock import patch
from get_firmware_info_fwupd import get_firmware_info_fwupd


class TestGetFirmwareInfo(unittest.TestCase):

@patch("subprocess.run")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd_snap(
self, mock_snapd, mock_subporcess):

mock_snapd.return_value = True
get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
['fwupd.fwupdmgr', 'get-devices', '--json'])

@patch.dict(os.environ, {"SNAP": "checkbox-snap"})
@patch("json.loads")
@patch("subprocess.run")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd1914_deb_on_checkbox_snap(
self, mock_snapd, mock_subporcess, mock_json):

mock_snapd.return_value = False
mock_json.return_value = {
"Versions": [
{
"Type": "runtime",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.9.14"
}
]
}
get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
['fwupdmgr', 'get-devices', '--json'])
self.assertEqual(
os.environ.get("SNAP"), "checkbox-snap")

@patch.dict(os.environ, {"SNAP": "checkbox-snap"})
@patch("json.loads")
@patch("subprocess.run")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd_deb_on_checkbox_snap(
self, mock_snapd, mock_subporcess, mock_json):

mock_snapd.return_value = False
mock_json.return_value = {
"Versions": [
{
"Type": "runtime",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
}
]
}
get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
['fwupdmgr', 'get-devices', '--json'])
self.assertIsNone(os.environ.get("SNAP"))
10 changes: 10 additions & 0 deletions providers/base/units/firmware/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,13 @@ plugin: attachment
depends: firmware/fwts_dump
command:
[ -f "$PLAINBOX_SESSION_SHARE/acpidump.log" ] && gzip -c "$PLAINBOX_SESSION_SHARE/acpidump.log"

id: firmware/fwupdmgr_get_devices
plugin: attachment
category_id: com.canonical.plainbox::firmware
_summary: Collect the device firmware update information
stanley31huang marked this conversation as resolved.
Show resolved Hide resolved
_purpose: Attach information about the devices, as reported by the fwupdmgr
requires:
executable.name in ("fwupdmgr", "fwupd.fwupdmgr")
command:
get_firmware_info_fwupd.py
25 changes: 25 additions & 0 deletions providers/base/units/firmware/test-plan.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,28 @@ include:
firmware/fwts_desktop_diagnosis
firmware/fwts_desktop_diagnosis_results.log.gz


id: firmware-fwupdmgr-full
unit: test plan
_name: fwupdmgr test
_description: Firmware update manager tests
include:
nested_part:
firmware-fwupdmgr-automated
firmware-fwupdmgr-manual

id: firmware-fwupdmgr-automated
unit: test plan
_name: Auto fwupdmgr tests
_description: Automated firmware update manager tests
bootstrap_include:
executable
environment
include:
firmware/fwupdmgr_get_devices

id: firmware-fwupdmgr-manual
unit: test plan
_name: Manual fwupdmgr tests
_description: Manual firmware update manager tests
include:
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ nested_part:
disk-cert-automated
misc-client-cert-automated
fingerprint-automated
firmware-fwupdmgr-automated
keys-cert-automated
led-cert-automated
mediacard-cert-automated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ nested_part:
disk-cert-automated
misc-client-cert-automated
fingerprint-automated
firmware-fwupdmgr-automated
keys-cert-automated
led-cert-automated
mediacard-cert-automated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ nested_part:
disk-cert-automated
misc-client-cert-automated
fingerprint-automated
firmware-fwupdmgr-automated
keys-cert-automated
led-cert-automated
mediacard-cert-automated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ nested_part:
disk-cert-automated
misc-client-cert-automated
fingerprint-automated
firmware-fwupdmgr-automated
keys-cert-automated
led-cert-automated
mediacard-cert-automated
Expand Down
Loading