Red Hat Bugzilla – Bug 816609
[libvirt] python bindings have inconsistent handling of float->int conversion
Last modified: 2013-02-21 02:12:18 EST
See also this upstream question: https://www.redhat.com/archives/libvir-list/2012-April/msg01170.html
set to POST commit 283f1c4aef8736d61c3965874a837537fea05dbc Author: Guannan Ren <gren@redhat.com> Date: Fri Sep 28 20:29:03 2012 +0800 python: keep consistent handling of Python integer conversion libvirt_ulonglongUnwrap requires the integer type of python obj. But libvirt_longlongUnwrap still could handle python obj of Pyfloat_type which causes the float value to be rounded up to an integer. For example >>> dom.setSchedulerParameters({'vcpu_quota': 0.88}) 0 libvirt_longlongUnwrap treats 0.88 as a valid value 0 However >>> dom.setSchedulerParameters({'cpu_shares': 1000.22}) libvirt_ulonglongUnwrap will throw out an error "TypeError: an integer is required" The patch make this consistent.
The last rebase to libvirt-0.10.2 was completed and all patches need to be explicitly backported and sent to rhvirt-patches for review. Please, set bugs to POST only after sending the backported patches.
patch sent to rhvirt mailing list http://post-office.corp.redhat.com/archives/rhvirt-patches/2012-October/msg00615.html
# rpm -q libvirt libssh2 libvirt-0.10.2-3.el6.x86_64 libssh2-1.4.2-1.el6.x86_64 steps: # python Python 2.6.6 (r266:84292, May 1 2012, 13:52:17) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import libvirt >>> conn = libvirt.open(None) >>> dom = conn.lookupByName("libvirt_test_api") >>> dom.schedulerParameters() {'vcpu_quota': -1L, 'vcpu_period': 100000L, 'emulator_period': 100000L, 'emulator_quota': -1L, 'cpu_shares': 1024L} >>> dom.setSchedulerParameters({'vcpu_quota': 0.88}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 1959, in setSchedulerParameters ret = libvirtmod.virDomainSetSchedulerParameters(self._o, params) TypeError: an integer is required >>> dom.setSchedulerParameters({'cpu_shares': 1000.22}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 1959, in setSchedulerParameters ret = libvirtmod.virDomainSetSchedulerParameters(self._o, params) TypeError: an integer is required >>> dom.schedulerParameters() {'vcpu_quota': -1L, 'vcpu_period': 100000L, 'emulator_period': 100000L, 'emulator_quota': -1L, 'cpu_shares': 1024L} >>> dom.setSchedulerParameters({'vcpu_quota': 10.88}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 1959, in setSchedulerParameters ret = libvirtmod.virDomainSetSchedulerParameters(self._o, params) TypeError: an integer is required >>> dom.setSchedulerParameters({'vcpu_quota': 10}) libvir: QEMU Driver error : invalid argument: value of 'vcpu_quota' is out of range [1000, 18446744073709551] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/libvirt.py", line 1960, in setSchedulerParameters if ret == -1: raise libvirtError ('virDomainSetSchedulerParameters() failed', dom=self) libvirt.libvirtError: invalid argument: value of 'vcpu_quota' is out of range [1000, 18446744073709551] >>> dom.setSchedulerParameters({'vcpu_quota': 1001}) 0 >>> dom.setSchedulerParameters({'vcpu_quota': 100001}) 0 >>> dom.schedulerParameters() {'vcpu_quota': 100001L, 'vcpu_period': 100000L, 'emulator_period': 100000L, 'emulator_quota': -1L, 'cpu_shares': 1024L} >>> dom.setSchedulerParameters({'vcpu_quota': -1}) 0 >>> dom.schedulerParameters() {'vcpu_quota': -1L, 'vcpu_period': 100000L, 'emulator_period': 100000L, 'emulator_quota': -1L, 'cpu_shares': 1024L} This is consistent now, now set schedulerParameters reject fractional values with a type error.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHSA-2013-0276.html