diff --git a/insights/collect.py b/insights/collect.py index b99d4a01ba..d9418b239b 100755 --- a/insights/collect.py +++ b/insights/collect.py @@ -184,7 +184,7 @@ - name: insights.combiners.sap.Sap enabled: true - # needed for fw_devices and fw_security specs + # needed for fw_security specs - name: insights.parsers.virt_what.VirtWhat enabled: true - name: insights.combiners.virt_what.VirtWhat diff --git a/insights/parsers/fwupdagent.py b/insights/parsers/fwupdagent.py index 7a6695b52d..8bd4416a72 100644 --- a/insights/parsers/fwupdagent.py +++ b/insights/parsers/fwupdagent.py @@ -123,13 +123,21 @@ class FwupdagentDevices(CommandParser, JSONParser): >>> len(devices["Devices"]) 2 """ - pass + def _handle_content(self, context): + # Find the actual json start line + # To skip the "INFO:", "WARNING:" lines at the top of the command output + index = 0 + for idx, line in enumerate(context.content): + if line and line.strip().startswith('{'): + index = idx + break + self.parse_content(context.content[index:]) @parser(Specs.fw_security) class FwupdagentSecurity(CommandParser, JSONParser): """ - Class ``FwupdagentSecurity`` parses the output of the ``/bin/fwupdagent get-devices`` command. + Class ``FwupdagentSecurity`` parses the output of the ``/bin/fwupdagent security --force`` command. Attributes: data (dict): The parsed output of the command. @@ -164,4 +172,12 @@ class FwupdagentSecurity(CommandParser, JSONParser): >>> len(security["HostSecurityAttributes"]) 2 """ - pass + def _handle_content(self, context): + # Find the actual json start line + # To skip the "INFO:", "WARNING:" lines at the top of the command output + index = 0 + for idx, line in enumerate(context.content): + if line and line.strip().startswith('{'): + index = idx + break + self.parse_content(context.content[index:]) diff --git a/insights/specs/default.py b/insights/specs/default.py index 9e842311ab..21204cb4fa 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -356,7 +356,6 @@ class DefaultSpecs(Specs): firewalld_conf = simple_file("/etc/firewalld/firewalld.conf") foreman_production_log = simple_file("/var/log/foreman/production.log") fstab = simple_file("/etc/fstab") - fw_devices = simple_command("/bin/fwupdagent get-devices", deps=[IsBareMetal]) fw_security = simple_command("/bin/fwupdagent security --force", deps=[IsBareMetal]) galera_cnf = first_file( [ diff --git a/insights/tests/parsers/test_fwupdagent.py b/insights/tests/parsers/test_fwupdagent.py index 984dbf6568..422a4ba7d4 100644 --- a/insights/tests/parsers/test_fwupdagent.py +++ b/insights/tests/parsers/test_fwupdagent.py @@ -8,6 +8,9 @@ from insights.tests import context_wrap DEVICES = """ +INFO: The fwupdagent command is deprecated, use `fwupdmgr --json` instead +WARNING: UEFI firmware can not be updated in legacy BIOS mode + See https://github.com/fwupd/fwupd/wiki/PluginFlag:legacy-bios for more information. { "Devices" : [ { @@ -103,7 +106,16 @@ } """ +DEVICES_ERROR_1 = """ +INFO: The fwupdagent command is deprecated, use `fwupdmgr --json` instead +WARNING: UEFI firmware can not be updated in legacy BIOS mode + See https://github.com/fwupd/fwupd/wiki/PluginFlag:legacy-bios for more information. +""".strip() + SECURITY = """ +INFO: The fwupdagent command is deprecated, use `fwupdmgr --json` instead +WARNING: UEFI firmware can not be updated in legacy BIOS mode + See https://github.com/fwupd/fwupd/wiki/PluginFlag:legacy-bios for more information. { "HostSecurityAttributes" : [ { @@ -150,6 +162,12 @@ This tool can be used from other tools and from shell scripts. """ +SECURITY_ERROR_3 = """ +INFO: The fwupdagent command is deprecated, use `fwupdmgr --json` instead +WARNING: UEFI firmware can not be updated in legacy BIOS mode + See https://github.com/fwupd/fwupd/wiki/PluginFlag:legacy-bios for more information. +""".strip() + def test_devices(): devices = FwupdagentDevices(context_wrap(DEVICES)) @@ -160,6 +178,9 @@ def test_devices(): assert devices["Devices"][1]["Name"] == "USB3.0 Hub" assert devices["Devices"][1]["Version"] == "3.114" + with pytest.raises(ParseException): + FwupdagentDevices(context_wrap(DEVICES_ERROR_1)) + def test_security(): security = FwupdagentSecurity(context_wrap(SECURITY)) @@ -175,6 +196,9 @@ def test_security(): with pytest.raises(ParseException): FwupdagentSecurity(context_wrap(SECURITY_ERROR_2)) + with pytest.raises(ParseException): + FwupdagentSecurity(context_wrap(SECURITY_ERROR_3)) + def test_doc_examples(): env = {