Merge "Reduced restriction of parsing for dmidecode output"
This commit is contained in:
@@ -421,7 +421,7 @@ class GenericHardwareManager(HardwareManager):
|
|||||||
total = int(psutil.phymem_usage().total)
|
total = int(psutil.phymem_usage().total)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
out, _e = utils.execute("dmidecode --type memory | grep Size",
|
out, _e = utils.execute("dmidecode --type 17 | grep Size",
|
||||||
shell=True)
|
shell=True)
|
||||||
except (processutils.ProcessExecutionError, OSError) as e:
|
except (processutils.ProcessExecutionError, OSError) as e:
|
||||||
LOG.warning("Cannot get real physical memory size: %s", e)
|
LOG.warning("Cannot get real physical memory size: %s", e)
|
||||||
@@ -433,12 +433,20 @@ class GenericHardwareManager(HardwareManager):
|
|||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if 'Size:' not in line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
value = None
|
||||||
try:
|
try:
|
||||||
value = line.split(None, 1)[1].strip()
|
value = line.split('Size: ', 1)[1]
|
||||||
physical += int(UNIT_CONVERTER(value).to_base_units())
|
physical += int(UNIT_CONVERTER(value).to_base_units())
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
LOG.error('Cannot parse size expression %s: %s',
|
if (value == "No Module Installed" or
|
||||||
line, exc)
|
value == "Not Installed"):
|
||||||
|
LOG.debug('One memory slot is empty')
|
||||||
|
else:
|
||||||
|
LOG.error('Cannot parse size expression %s: %s',
|
||||||
|
line, exc)
|
||||||
|
|
||||||
if not physical:
|
if not physical:
|
||||||
LOG.warning('failed to get real physical RAM, dmidecode '
|
LOG.warning('failed to get real physical RAM, dmidecode '
|
||||||
|
@@ -421,7 +421,10 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
|
|||||||
def test_get_memory(self, mocked_execute, mocked_usage):
|
def test_get_memory(self, mocked_execute, mocked_usage):
|
||||||
mocked_usage.return_value = mock.Mock(total=3952 * 1024 * 1024)
|
mocked_usage.return_value = mock.Mock(total=3952 * 1024 * 1024)
|
||||||
mocked_execute.return_value = (
|
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"),
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
5
releasenotes/notes/add-unit-test-cc4a1a05859ad17d.yaml
Normal file
5
releasenotes/notes/add-unit-test-cc4a1a05859ad17d.yaml
Normal 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.
|
Reference in New Issue
Block a user