diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index f8107b555..a81b46385 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -1111,8 +1111,10 @@ class GenericHardwareManager(HardwareManager): LOG.warning('Could not get real physical RAM from lshw: %s', e) physical = None else: - if isinstance(sys_dict, str): - sys_dict = json.loads(sys_dict) + # Depending on lshw version, output might be a list, starting with + # https://github.com/lyonel/lshw/commit/135a853c60582b14c5b67e5cd988a8062d9896f4 # noqa + if isinstance(sys_dict, list): + sys_dict = sys_dict[0] physical = _calc_memory(sys_dict) if not physical: diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index b9348912c..4656311aa 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -1697,6 +1697,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.assertEqual(3952 * 1024 * 1024, mem.total) self.assertEqual(3952, mem.physical_mb) + @mock.patch('psutil.virtual_memory', autospec=True) + @mock.patch.object(utils, 'execute', autospec=True) + def test_get_memory_lshw_list(self, mocked_execute, mocked_psutil): + mocked_psutil.return_value.total = 3952 * 1024 * 1024 + mocked_execute.return_value = (f"[{LSHW_JSON_OUTPUT_V2[0]}]", "") + mem = self.hardware.get_memory() + + self.assertEqual(3952 * 1024 * 1024, mem.total) + self.assertEqual(65536, mem.physical_mb) + @mock.patch('ironic_python_agent.netutils.get_hostname', autospec=True) def test_list_hardware_info(self, mocked_get_hostname): self.hardware.list_network_interfaces = mock.Mock()