Support psutil 5.0.1
An upper-constraints update to psutil caused IPA to start using psutil 5.0.1. We had a hard-coded assumption that psutil would be major version 1 or 2. This allows us to use the updated psutil and attempts to simply fail gracefully if an unrecognized psutil version is used. Change-Id: Ibe072440159561b34a29b478d955876e5fb7f103 Closes-Bug: 1659137
This commit is contained in:
parent
44832822fe
commit
e4919e04aa
@ -598,6 +598,12 @@ class GenericHardwareManager(HardwareManager):
|
||||
total = int(psutil.TOTAL_PHYMEM)
|
||||
elif psutil.version_info[0] == 2:
|
||||
total = int(psutil.phymem_usage().total)
|
||||
elif psutil.version_info[0] == 5:
|
||||
total = int(psutil.virtual_memory().total)
|
||||
else:
|
||||
total = None
|
||||
LOG.warning("Cannot fetch total memory size: unsupported psutil "
|
||||
"version %s", psutil.version_info[0])
|
||||
|
||||
try:
|
||||
out, _e = utils.execute("dmidecode --type 17 | grep Size",
|
||||
|
@ -728,11 +728,11 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
|
||||
self.assertEqual('x86_64', cpus.architecture)
|
||||
self.assertEqual([], cpus.flags)
|
||||
|
||||
@mock.patch('psutil.version_info', (2, 0))
|
||||
@mock.patch('psutil.phymem_usage', autospec=True)
|
||||
@mock.patch('psutil.version_info', (5, 0))
|
||||
@mock.patch('psutil.virtual_memory', autospec=True)
|
||||
@mock.patch.object(utils, 'execute')
|
||||
def test_get_memory(self, mocked_execute, mocked_usage):
|
||||
mocked_usage.return_value = mock.Mock(total=3952 * 1024 * 1024)
|
||||
def test_get_memory(self, mocked_execute, mocked_virtmem):
|
||||
mocked_virtmem.return_value.total = 3952 * 1024 * 1024
|
||||
mocked_execute.return_value = (
|
||||
("Foo\nSize: 2048 MB\nSize: 2 GB\n"
|
||||
"Installed Size: Not Installed\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user