diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index e15926a5c..97d64162b 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -421,7 +421,7 @@ class GenericHardwareManager(HardwareManager): total = int(psutil.phymem_usage().total) try: - out, _e = utils.execute("dmidecode --type memory | grep Size", + out, _e = utils.execute("dmidecode --type 17 | grep Size", shell=True) except (processutils.ProcessExecutionError, OSError) as e: LOG.warning("Cannot get real physical memory size: %s", e) @@ -433,12 +433,20 @@ class GenericHardwareManager(HardwareManager): if not line: continue + if 'Size:' not in line: + continue + + value = None try: - value = line.split(None, 1)[1].strip() + value = line.split('Size: ', 1)[1] physical += int(UNIT_CONVERTER(value).to_base_units()) except Exception as exc: - LOG.error('Cannot parse size expression %s: %s', - line, exc) + if (value == "No Module Installed" or + value == "Not Installed"): + LOG.debug('One memory slot is empty') + else: + LOG.error('Cannot parse size expression %s: %s', + line, exc) if not physical: LOG.warning('failed to get real physical RAM, dmidecode ' diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index f3523da67..c02519e3c 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -421,7 +421,10 @@ class TestGenericHardwareManager(test_base.BaseTestCase): def test_get_memory(self, mocked_execute, mocked_usage): mocked_usage.return_value = mock.Mock(total=3952 * 1024 * 1024) mocked_execute.return_value = ( - "Foo\nSize: 2048 MB\nSize: 2 GB\n", + ("Foo\nSize: 2048 MB\nSize: 2 GB\n" + "Installed Size: Not Installed\n" + "Enabled Size: Not Installed\n" + "Size: No Module Installed\n"), "" ) diff --git a/releasenotes/notes/add-unit-test-cc4a1a05859ad17d.yaml b/releasenotes/notes/add-unit-test-cc4a1a05859ad17d.yaml new file mode 100644 index 000000000..f4c09eb52 --- /dev/null +++ b/releasenotes/notes/add-unit-test-cc4a1a05859ad17d.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - dmidecode output produces less parsing errors and logs + common and normal output like "No Module Installed" or + "Not Installed" in debug instead of error.