Bug 1309271 - VM creation fails by defineXML(), if not using domain.undefine().
Summary: VM creation fails by defineXML(), if not using domain.undefine().
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt-python
Version: unspecified
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-17 10:58 UTC by Robert Ozga
Modified: 2016-02-17 11:20 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-02-17 11:20:12 UTC


Attachments (Terms of Use)

Description Robert Ozga 2016-02-17 10:58:03 UTC
Description of problem:


By redefine of Domain using the function "defineXML()" from libvirt-module in python, causes that Domain creation fails. 
Domain has current state "shutdown()". In documentation of defineXML() I read:

"...A previous definition for this domain would be overridden if it already exists. ..."

But this works only than, before using the function undefine().


Version-Release number of selected component (if applicable):
libvirt 1.2.2
QEMU 1.2.2
Hypervisor: QEMU 2.0.0


Steps to Reproduce:

1. Define Domain with libvirt.defineXML(xml)
2. Create VM using domain.create()
3. Using domain.shutdown() function
4. Redefine Domain with libvirt.defineXML(xml)
5. New creation using domain.create()

Actual results:
File "/usr/lib/python2.7/dist-packages/libvirt.py", line 3240, in defineXML
    if ret is None:raise libvirtError('virDomainDefineXML() failed', conn=self)

libvirtd.log
------------
2016-02-17 08:41:16.552+0000: 1658: error : virDomainObjListAddLocked:2335 : operation failed: domain 'ecmprt11' already exists with uuid 491cf4b7-7573-4f36-acb8-52dbd9be8e48

Expected results:

Creation of Domain with new definition.

Additional info:

It works for me perfectly, if using between step 3 and 4 additionaly domain.undefine().

Question:
Is it only documentation bug, or I  missunderstood the description of defineXML()?

Many thanks and best regards

Comment 2 Ján Tomko 2016-02-17 11:16:31 UTC
libvirt 1.2.2 was never released in RHEL, moving to the upstream tracker.

Comment 3 Jiri Denemark 2016-02-17 11:20:12 UTC
It all depends on the XMLs you passed to defineXML (and you didn't attach them).
But in general, redefining a domain is only supported if the name and UUID in the new XML matches the original definition. Beware, if you don't specify any UUID libvirt will automatically assign it to a domain. Thus trying to redefine a domain with an XML which lacks UUID will never work. You should either generate the UUID in your script and use it in both XMLs or fetch it from libvirt after step 1 and use this UUID in step 4.


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