Bug 816609

Summary: [libvirt] python bindings have inconsistent handling of float->int conversion
Product: Red Hat Enterprise Linux 6 Reporter: Eric Blake <eblake>
Component: libvirtAssignee: Gunannan Ren <gren>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.4CC: abaron, acathrow, bazulay, berrange, clalancette, dallan, dougsland, dyasny, dyuan, eblake, gren, gsun, hateya, iheim, itamar, jdenemar, jforbes, jyang, laine, libvirt-maint, mzhan, rwu, veillard, virt-maint, whuang, ykaul
Target Milestone: rc   
Target Release: 6.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
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 07:12:18 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 804664, 807751    
Bug Blocks:    

Comment 1 Eric Blake 2012-04-26 13:58:03 UTC
See also this upstream question:
https://www.redhat.com/archives/libvir-list/2012-April/msg01170.html

Comment 3 Gunannan Ren 2012-10-08 13:54:25 UTC
set to POST

commit 283f1c4aef8736d61c3965874a837537fea05dbc
Author: Guannan Ren <gren>
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 18:15:59 UTC
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 13:27:11 UTC
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 06:04:33 UTC
# 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 07:12:18 UTC
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