summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Villaplana <mario.villaplana@gmail.com>2017-01-24 22:59:46 +0000
committerAlan Pevec <alan.pevec@redhat.com>2017-02-23 13:55:56 +0000
commite46f75ed0924bae57bc885a950c68a193c5e0eec (patch)
tree68aa5c8c224e90bb1c5451d2eba511ce5423a139
parent7ff6948d5f237afed4a967403306b297b1e3d7a0 (diff)
Support psutil 5.0.11.5.2
Backport notice: followup removed support for older psutil, this backport keeps compatibility for older releases for environments which want to run newer versions than frozen upper-constraints on stable branch. Original master (Ocata) message: 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 (cherry picked from commit e4919e04aa250b51e351c4e9dbfb3761f5f93a70)
Notes
Notes (review): Code-Review+2: Jay Faulkner <jay@jvf.cc> Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Workflow+1: Dmitry Tantsur <divius.inside@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 08 Mar 2017 00:22:03 +0000 Reviewed-on: https://review.openstack.org/437385 Project: openstack/ironic-python-agent Branch: refs/heads/stable/newton
-rw-r--r--ironic_python_agent/hardware.py6
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py8
2 files changed, 10 insertions, 4 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index aad4777..d82da6b 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -579,6 +579,12 @@ class GenericHardwareManager(HardwareManager):
579 total = int(psutil.TOTAL_PHYMEM) 579 total = int(psutil.TOTAL_PHYMEM)
580 elif psutil.version_info[0] == 2: 580 elif psutil.version_info[0] == 2:
581 total = int(psutil.phymem_usage().total) 581 total = int(psutil.phymem_usage().total)
582 elif psutil.version_info[0] == 5:
583 total = int(psutil.virtual_memory().total)
584 else:
585 total = None
586 LOG.warning("Cannot fetch total memory size: unsupported psutil "
587 "version %s", psutil.version_info[0])
582 588
583 try: 589 try:
584 out, _e = utils.execute("dmidecode --type 17 | grep Size", 590 out, _e = utils.execute("dmidecode --type 17 | grep Size",
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index 548c850..9b425ab 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -657,11 +657,11 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
657 self.assertEqual('x86_64', cpus.architecture) 657 self.assertEqual('x86_64', cpus.architecture)
658 self.assertEqual([], cpus.flags) 658 self.assertEqual([], cpus.flags)
659 659
660 @mock.patch('psutil.version_info', (2, 0)) 660 @mock.patch('psutil.version_info', (5, 0))
661 @mock.patch('psutil.phymem_usage', autospec=True) 661 @mock.patch('psutil.virtual_memory', autospec=True)
662 @mock.patch.object(utils, 'execute') 662 @mock.patch.object(utils, 'execute')
663 def test_get_memory(self, mocked_execute, mocked_usage): 663 def test_get_memory(self, mocked_execute, mocked_virtmem):
664 mocked_usage.return_value = mock.Mock(total=3952 * 1024 * 1024) 664 mocked_virtmem.return_value.total = 3952 * 1024 * 1024
665 mocked_execute.return_value = ( 665 mocked_execute.return_value = (
666 ("Foo\nSize: 2048 MB\nSize: 2 GB\n" 666 ("Foo\nSize: 2048 MB\nSize: 2 GB\n"
667 "Installed Size: Not Installed\n" 667 "Installed Size: Not Installed\n"