From: Iustin Pop <[email protected]> My previous pylint cleanups were done without psutil installed; as soon I installed it, pylint showed that the wheezy's version of psutil is too old (0.5.1), not having the cpu_count() function which was introduced in 2.0.0. Furthermore, thanks to Brian, it turns out that too new versions are also unsupported.
This change adds a simple way to detect this and to degrade gracefully by throwing an appropriate exception instead of an unclear one at runtime. Tested with wheezy's 0.5.0 and sid's 4.1.1 versions. It also updates the INSTALL file to note the supported versions and that [2.0.0,2.2.0) had issues with FH leaks. Signed-off-by: Iustin Pop <[email protected]> --- INSTALL | 4 +++- lib/hypervisor/hv_kvm/__init__.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/INSTALL b/INSTALL index e33ab96..95f3019 100644 --- a/INSTALL +++ b/INSTALL @@ -42,7 +42,9 @@ Before installing, please verify that you have the following programs: - `Paramiko <http://www.lag.net/paramiko/>`_, if you want to use ``ganeti-listrunner`` - `psutil Python module <https://github.com/giampaolo/psutil>`_, - optional python package for supporting CPU pinning under KVM + optional python package for supporting CPU pinning under KVM, versions + 2.x.x only; beware that versions from 2.0.0 to before 2.2.0 had a + number of file handle leaks, so running at least 2.2.0 is advised - `fdsend Python module <https://gitorious.org/python-fdsend>`_, optional Python package for supporting NIC hotplugging under KVM - `qemu-img <http://qemu.org/>`_, if you want to use ``ovfconverter`` diff --git a/lib/hypervisor/hv_kvm/__init__.py b/lib/hypervisor/hv_kvm/__init__.py index 4df0246..8271e0e 100644 --- a/lib/hypervisor/hv_kvm/__init__.py +++ b/lib/hypervisor/hv_kvm/__init__.py @@ -45,7 +45,17 @@ import urllib2 from bitarray import bitarray try: import psutil # pylint: disable=F0401 + if psutil.version_info < (2, 0, 0): + # The psutil version seems too old, we ignore it + psutil_err = "too old (2.x.x needed, %s found)" % psutil.__version__ + psutil = None + elif psutil.version_info >= (3,): + psutil_err = "too new (2.x.x needed, %s found)" % psutil.__version__ + psutil = None + else: + psutil_err = "<no error>" except ImportError: + psutil_err = "not found" psutil = None try: import fdsend # pylint: disable=F0401 @@ -716,11 +726,14 @@ class KVMHypervisor(hv_base.BaseHypervisor): """ if psutil is None: - raise errors.HypervisorError("psutil Python package not" - " found; cannot use CPU pinning under KVM") + raise errors.HypervisorError("psutil Python package %s" + "; cannot use CPU pinning" + " under KVM" % psutil_err) target_process = psutil.Process(process_id) if cpus == constants.CPU_PINNING_OFF: + # we checked this at import time + # pylint: disable=E1101 target_process.set_cpu_affinity(range(psutil.cpu_count())) else: target_process.set_cpu_affinity(cpus) -- 2.8.1
