Bug 816609 - [libvirt] python bindings have inconsistent handling of float->int conversion
[libvirt] python bindings have inconsistent handling of float->int conversion
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.4
Unspecified Unspecified
unspecified Severity unspecified
: rc
: 6.3
Assigned To: Gunannan Ren
Virtualization Bugs
:
Depends On: 804664 807751
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-26 09:53 EDT by Eric Blake
Modified: 2013-02-21 02:12 EST (History)
26 users (show)

See Also:
Fixed In Version: libvirt-0.10.2-3.el6
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 807751
Environment:
Last Closed: 2013-02-21 02:12:18 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Comment 1 Eric Blake 2012-04-26 09:58:03 EDT
See also this upstream question:
https://www.redhat.com/archives/libvir-list/2012-April/msg01170.html
Comment 3 Gunannan Ren 2012-10-08 09:54:25 EDT
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.
Comment 4 Jiri Denemark 2012-10-08 14:15:59 EDT
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.
Comment 6 Gunannan Ren 2012-10-12 09:27:11 EDT
patch sent to rhvirt mailing list
http://post-office.corp.redhat.com/archives/rhvirt-patches/2012-October/msg00615.html
Comment 9 Wayne Sun 2012-10-16 02:04:33 EDT
# 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.
Comment 10 errata-xmlrpc 2013-02-21 02:12:18 EST
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

Note You need to log in before you can comment on or make changes to this bug.