[Kimchi-devel] [PATCH] Make VMs for tests auto-destroy'd and transient

Christy Perez christy at linux.vnet.ibm.com
Tue Feb 3 19:57:54 UTC 2015


If Kimchi's startup is interrupted for some reason, a VM created
during the feature tests may be left defined. When this happens,
the next time Kimchi is started it will fail with an error that
the domain already exists (for example, "libvirtError: operation
failed: domain 'A_SIMPLE_VM' already exists with uuid
e6fccea8-f7ed-4320-a4cb-b85217d23985").

About the new flag:
"If the VIR_DOMAIN_START_AUTODESTROY flag is set, the guest
    domain will be automatically destroyed when the virConnectPtr
    object is finally released. This will also happen if the
    client application crashes / loses its connection to the
    libvirtd daemon. Any domains marked for auto destroy will
    block attempts at migration, save-to-file, or snapshots."

This patch also changes the memory in the test VMs, due to the fact
that the domain will be started, and some platforms (Power is a known
example) require at least 128M of memory for a guest.

Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
---
 src/kimchi/kvmusertests.py       |  5 ++---
 src/kimchi/model/featuretests.py | 14 ++++++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/kimchi/kvmusertests.py b/src/kimchi/kvmusertests.py
index 408706d..3abf148 100644
--- a/src/kimchi/kvmusertests.py
+++ b/src/kimchi/kvmusertests.py
@@ -54,9 +54,8 @@ def probe_user(cls):
         with RollbackContext() as rollback:
             conn = libvirt.open(None)
             rollback.prependDefer(conn.close)
-            dom = conn.defineXML(xml)
-            rollback.prependDefer(dom.undefine)
-            dom.create()
+            dom = conn.createXML(xml,
+                                 flags=libvirt.VIR_DOMAIN_START_AUTODESTROY)
             rollback.prependDefer(dom.destroy)
             with open('/var/run/libvirt/qemu/%s.pid' % vm_name) as f:
                 pidStr = f.read()
diff --git a/src/kimchi/model/featuretests.py b/src/kimchi/model/featuretests.py
index 5a45990..ef7dcc5 100644
--- a/src/kimchi/model/featuretests.py
+++ b/src/kimchi/model/featuretests.py
@@ -58,7 +58,7 @@
 SIMPLE_VM_XML = """
 <domain type='%(domain)s'>
   <name>A_SIMPLE_VM</name>
-  <memory unit='KiB'>10240</memory>
+  <memory unit='KiB'>131072</memory>
   <os>
     <type arch='%(arch)s'>hvm</type>
     <boot dev='hd'/>
@@ -109,8 +109,9 @@ def libvirt_supports_iso_stream(conn, protocol):
                                 'arch': arch}
         try:
             FeatureTests.disable_libvirt_error_logging()
-            dom = conn.defineXML(xml)
-            dom.undefine()
+            dom = conn.createXML(xml,
+                                 flags=libvirt.VIR_DOMAIN_START_AUTODESTROY)
+            dom.destroy()
             return True
         except libvirt.libvirtError, e:
             kimchi_log.error(e.message)
@@ -196,9 +197,10 @@ def has_metadata_support(conn):
             domain_type = 'test' if conn.getType().lower() == 'test' else 'kvm'
             arch = 'ppc64' if platform.machine() == 'ppc64le' \
                 else platform.machine()
-            dom = conn.defineXML(SIMPLE_VM_XML % {'domain': domain_type,
-                                                  'arch': arch})
-            rollback.prependDefer(dom.undefine)
+            dom = conn.createXML(SIMPLE_VM_XML % {'domain': domain_type,
+                                                  'arch': arch},
+                                 flags=libvirt.VIR_DOMAIN_START_AUTODESTROY)
+            rollback.prependDefer(dom.destroy)
             try:
                 dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,
                                 "<metatest/>", KIMCHI_NAMESPACE,
-- 
1.9.3




More information about the Kimchi-devel mailing list