Reduced restriction of parsing for dmidecode output

Changed implementation to strip tokens up until the first 'Size: '
string. This will allow for less parsing errors in the first
six lines of the following output:
"dmidecode --type 17 | grep Size" returns:
        Maximum Memory Module Size: 4096 MB
        Maximum Total Memory Size: 8192 MB
        Size: 2048 MB
        Size: 2048 MB

Added a condition in the exception handling to address the
issue of the bug on other outputs like:
        Installed Size: Not Installed
        Enabled Size: Not Installed
        Size: No Module Installed
        Size: 1024 MB

Common strings like "No Module Installed" and "Not Installed" are
normal. These two strings are hard coded in the before mentioned
comparison and when found are logged as warnings instead of errors.

Change-Id: If3475afcebfc7af7e9256b99924919557c4d909c
Closes-Bug: #1521202
This commit is contained in:
twm2016 2016-02-16 16:41:46 -06:00 committed by Trevor McCasland
parent 3bcda73ca0
commit d66fa523bf
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.