Bug 766553

Summary: Expose 'virDomainSnapshotListChildrenNames' API in python binding
Product: Red Hat Enterprise Linux 6 Reporter: Alex Jia <ajia>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.3CC: acathrow, dallan, dyuan, eblake, gsun, mzhan, rwu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-0.9.9-1.el6 Doc Type: Bug Fix
Doc Text:
No Documentation needed
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 06:38:34 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:

Description Alex Jia 2011-12-12 10:46:35 UTC
Description of problem:
Need to expose 'virDomainSnapshotListChildrenNames' API in python binding. 

Version-Release number of selected component (if applicable):
libvirt-python-0.9.8-1.el6.x86_64

How reproducible:
always

Steps to Reproduce:
1. define a guest with qcow2 image
2. create a snapshot for the guest
3. run interact python to try libvirt python API

# qemu-img create -f qcow2 /var/lib/libvirt/images/disk.img 100M
Formatting '/var/lib/libvirt/images/disk.img', fmt=qcow2 size=104857600 encryption=off cluster_size=65536

# cat > /root/demo.xml <<EOF
<domain type='qemu'>
  <name>demo</name>
  <memory>219200</memory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64'>hvm</type>
    <boot dev='hd'/>
  </os>
  <devices>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/disk.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <input type='mouse' bus='ps2'/>
    <graphics type='spice' autoport='yes' listen='0.0.0.0'/>
  </devices>
</domain>
EOF

# virsh define /root/demo.xml
Domain demo defined from /root/demo.xml

# virsh snapshot-list demo
 Name                 Creation Time             State
------------------------------------------------------------

# virsh snapshot-create-as demo
Domain snapshot 1323685119 created

# virsh snapshot-list demo --descendants
 Name                 Creation Time             State
------------------------------------------------------------
 1323685119           2011-12-12 18:18:39 +0800 shutoff

# python
Python 2.6.6 (r266:84292, Sep 12 2011, 14:03:14) 
[GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libvirt
>>> con = libvirt.open(None)
>>> dom_name = con.listDefinedDomains()[0]
>>> dom = con.lookupByName(dom_name)
>>> snap_name = dom.snapshotListNames(0)[0]
>>> snap = dom.snapshotLookupByName(snap_name, 0)
>>> dir(snap)
['__del__', '__doc__', '__init__', '__module__', '_dom', '_o', 'delete', 'domain', 'getConnect', 'getDomain', 'getName', 'getParent', 'getXMLDesc', 'listChildrenNames', 'numChildren']
>>> snap.getName()
'1323685119'
>>> snap.getDomain().name()
'demo'
>>> snap.listChildrenNames(0)

Actual results:

>>> snap.listChildrenNames(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/site-packages/libvirt.py", line 3733, in listChildrenNames
    ret = libvirtmod.virDomainSnapshotListChildrenNames(self._o, flags)
AttributeError: 'module' object has no attribute 'virDomainSnapshotListChildrenNames'

Expected results:
fix it.

Additional info:

# nm -a -D /usr/lib64/python2.6/site-packages/libvirtmod.so |grep virDomainSnapshotNumChildren
000000000001d720 T libvirt_virDomainSnapshotNumChildren
                 U virDomainSnapshotNumChildren

# nm -a -D /usr/lib64/python2.6/site-packages/libvirtmod.so |grep virDomainSnapshotListChildrenNames

Note: nothing return in here.


In addition, it seems libvirt has exposed this c API, please see this commit:
http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=f2013c9dd1ce468b8620ee35c232a93ef7026fb0

Comment 1 Peter Krempa 2011-12-13 22:38:36 UTC
Function export fixed with upstream commit:

commit fbd8d6fc8786cde59e34b39450f3c2c632376f8f
Author: Peter Krempa <pkrempa>
Date:   Tue Dec 13 15:49:59 2011 +0100

    python: Fix export of virDomainSnapshotListChildrenNames
    
    Commit f2013c9dd1ce468b8620ee35c232a93ef7026fb0 added implementation of
    virDomainSnapshotListChildrenNames override export, but registration of
    the newly exported function was not added.


Thanks for finding the commit that added the export, it made finding the error easier.

Comment 3 Wayne Sun 2012-01-10 10:00:03 UTC
Follow the steps in description:

After last virsh command of create snapshot, create a children snapshot

# virsh snapshot-create-as demo
Domain snapshot 1326189262 created
# virsh snapshot-create-as demo
Domain snapshot 1326189264 created
# virsh snapshot-list demo --descendants
 Name                 Creation Time             State
------------------------------------------------------------
 1326189262           2012-01-10 17:54:22 +0800 shutoff
 1326189264           2012-01-10 17:54:24 +0800 shutoff


# python
Python 2.6.6 (r266:84292, Sep 12 2011, 14:03:14) 
[GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libvirt
>>> conn = libvirt.open(None)
>>> dom = conn.lookupByName('demo')
>>> dom.snapshotListNames(0)
['1326189264', '1326189262']
>>> snap_name = dom.snapshotListNames(0)[1]
>>> snap = dom.snapshotLookupByName(snap_name, 0)
>>> dir(snap)
['__del__', '__doc__', '__init__', '__module__', '_dom', '_o', 'delete', 'domain', 'getConnect', 'getDomain', 'getName', 'getParent', 'getXMLDesc', 'listChildrenNames', 'numChildren']
>>> snap.getName()
'1326189262'
>>> snap.getDomain().name()
'demo'
>>> snap.listChildrenNames(0)
['1326189264']
>>> snap.numChildren(0)
1
>>> 

so, this is fixed

Comment 4 Wayne Sun 2012-01-10 10:21:53 UTC
The package is:
# rpm -q libvirt libvirt-python
libvirt-0.9.9-1.el6.x86_64
libvirt-python-0.9.9-1.el6.x86_64

Comment 5 Peter Krempa 2012-05-02 09:49:37 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
No Documentation needed

Comment 7 errata-xmlrpc 2012-06-20 06:38:34 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-2012-0748.html