Bug 204490

Summary: libvirt fails when 'factory' pattern used in python
Product: [Fedora] Fedora Reporter: Pete Vetere <pvetere>
Component: libvirtAssignee: Daniel Veillard <veillard>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-11-09 09:56:45 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Pete Vetere 2006-08-29 11:00:07 EDT
Description of problem:

When using a factory pattern to lookup a domain in python, libvirt produces the
following error:

    libvir: Xen error : failed Xen syscall  ioctl  3166208

Here's some sample code that reproduces the problem (assuming an existing domain
called "mydomain"):

    import libvirt
    def get_domain(dom_name):
        conn = libvirt.openReadOnly(None)
        domain = conn.lookupByName(dom_name)
        return domain
    d = get_domain("mydomain")
    print d.info()

The problem is that the connection object falls out of scope after the
get_domain routine ends, and is therefore garbage collected.  This leaves the
"d" domain object with no valid connection, resulting in the above error
message.  The simple solution would be for the connection object to pass a
reference to itself into each domain object it creates.  The domain objects
would then maintain the reference until they are destroyed.
Comment 1 Daniel Veillard 2006-11-09 09:56:45 EST
 Fixed in CVS:

paphio:~ -> cat tst.py
#!/usr/bin/python -u

import libvirt
def get_domain(dom_name):
    conn = libvirt.openReadOnly(None)
    domain = conn.lookupByName(dom_name)
    return domain

d = get_domain("rhel5")
print d.info()
paphio:~ -> ./tst.py 
[2, 394240, 393824, 1, 24694771381L]
paphio:~ -> 

  commited upstream with this changelog:

Thu Nov  9 15:39:19 CET 2006 Daniel Veillard <veillard@redhat.com>

        * python/generator.py: changed the generator to generate a reference
          from Domain class instances to the Connect they were issued from
          should fix rhbz#204490

I think it's the simplest and cleanest fix.
 thanks !

Daniel