Bug 1154918

Summary: 2 small issue in libvirt_virDomainGetTime and libvirt_virDomainSetTime
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirt-pythonAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.1CC: dyuan, honzhang, mzhan
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-python-1.2.13-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 05:33:12 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Luyao Huang 2014-10-21 03:53:31 UTC
Description of problem:
2 small issue found in  libvirt_virDomainGetTime  and libvirt_virDomainSetTime.
In libvirt_virDomainGetTime ,libvirt return NULL without set exception.
In libvirt_virDomainSetTime , should add a type check for time.

Version-Release number of selected component (if applicable):
libvirt-1.2.8-5.el7.x86_64
libvirt-python-1.2.8-4.el7.x86_64


How reproducible:
100%

Steps to Reproduce:
1.For libvirt_virDomainGetTime
# ipython
In [1]: import libvirt
In [2]: con = libvirt.open()
In [3]: domain = con.lookupByName('test3')
In [4]: domain.getTime()
libvirt: QEMU Driver error : Requested operation is not valid: domain is not running
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-4-8783bc50ec3c> in <module>()
----> 1 domain.getTime()

/usr/lib64/python2.7/site-packages/libvirt.pyc in getTime(self, flags)
   2695     def getTime(self, flags=0):
   2696         """Extract information about guest time """
-> 2697         ret = libvirtmod.virDomainGetTime(self._o, flags)
   2698         if ret == -1: raise libvirtError ('virDomainGetTime() failed', dom=self)
   2699         return ret

SystemError: error return without exception set

2.For libvirt_virDomainSetTime

3.# ipython
In [1]: import libvirt
In [2]: con = libvirt.open()
In [3]: domain = con.lookupByName('test3')
In [4]: domain.setTime(12345)
Out[4]: 0

In [5]: domain.getTime()
Out[5]: {'nseconds': 591617000, 'seconds': 11L}

Actual results:
In libvirt_virDomainGetTime ,libvirt return NULL without set exception.
In libvirt_virDomainSetTime , should add a type check for time.

Expected results:
In [19]: domain.getTime(1)
libvirt: QEMU Driver error : unsupported flags (0x1) in function qemuDomainGetTime


TypeError: time must be dict

Additional info:


I write two patch for the issue and send to upstream:

For libvirt_virDomainGetTime:
https://www.redhat.com/archives/libvir-list/2014-October/msg00538.html

For libvirt_virDomainSetTime:
https://www.redhat.com/archives/libvir-list/2014-October/msg00528.html

Comment 1 Michal Privoznik 2014-12-05 07:46:52 UTC
Moving to POST:

commit d8b7aa4b1839237e384e6547eb56f889046793ed
Author:     Luyao Huang <lhuang>
AuthorDate: Mon Oct 20 15:55:00 2014 +0200
Commit:     Pavel Hrdina <phrdina>
CommitDate: Mon Oct 20 17:06:12 2014 +0200

    Improve error output when use getTime with a nonzero flags.
    
    When give a nonzero flags to getTime, c_retval will get -1 and goto
    cleanup. But py_retval still is NULL, so set py_retval =  VIR_PY_NONE.
    This will make the output message more correct.
    
    Signed-off-by: Luyao Huang <lhuang>


commit 3d1d3fd52a60d9ab4159e4f9f8680b92dd7a9866
Author:     Luyao Huang <lhuang>
AuthorDate: Fri Oct 31 10:02:16 2014 +0800
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Nov 11 15:58:12 2014 +0100

    Add dict check for setTime and allow pass 'seconds' parameter
    
    When pass None or a empty dictionary to time, it will report
    error. This commit allows a one-element dictionary which contains
    just 'seconds' field, which results in the same as passing 0 for
    'nseconds' field. Moreover, dict is checked for unknown fields.
    
    Signed-off-by: Luyao Huang <lhuang>
    Signed-off-by: Michal Privoznik <mprivozn>

v1.2.10-3-g3d1d3fd

Comment 3 hongming 2015-05-12 08:30:57 UTC
Verify it as follows. The result is expected.Move its status to VERIFIED.


# rpm -q libvirt libvirt-python
libvirt-1.2.15-2.el7.x86_64
libvirt-python-1.2.13-1.el7.x86_64

# python
Python 2.7.5 (default, Feb 11 2014, 07:46:25) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libvirt
>>> con = libvirt.open('')
>>> dom = con.lookupByName('r7a')
>>> dom.getTime()
{'seconds': 1431418041L, 'nseconds': 384722000}
>>> dom.setTime(12345)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 2769, in setTime
    ret = libvirtmod.virDomainSetTime(self._o, time, flags)
TypeError: time must be a dictionary or None with flags set

>>> dom.setTime(1431418041,384722000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 2769, in setTime
    ret = libvirtmod.virDomainSetTime(self._o, time, flags)
TypeError: time must be a dictionary or None with flags set

>>> dom.setTime({'seconds': 384722000, 'nseconds': 0}, 1)
0

>>> dom.getTime(0)
{'seconds': 1431419304L, 'nseconds': 771291000}

>>> dom.getTime()
{'seconds': 1431419308L, 'nseconds': 115300000}

>>> dom.getTime(1)
libvirt: QEMU Driver error : unsupported flags (0x1) in function qemuDomainGetTime

>>> dom.getTime(-1)
libvirt: QEMU Driver error : unsupported flags (0xffffffff) in function qemuDomainGetTime

Comment 4 hongming 2015-05-12 09:24:32 UTC
The result is also passed in libvirt-python-1.2.15-1.el7.x86_64

Comment 6 errata-xmlrpc 2015-11-19 05:33:12 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.

https://rhn.redhat.com/errata/RHBA-2015-2203.html