Merge "Reduced restriction of parsing for dmidecode output"

This commit is contained in:
Jenkins 2016-03-01 17:39:10 +00:00 committed by Gerrit Code Review
commit 1971ad7023
3 changed files with 21 additions and 5 deletions

View File

@ -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 '

View File

@ -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"),
""
)

View File

@ -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.