[Kimchi-devel] [PATCH] Eliminate name collision for feature tests' VMs

Christy Perez christy at linux.vnet.ibm.com
Thu Feb 5 23:15:13 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").

This patch just uses the same uuid-based name scheme as was already
in the user tests (kvmusertests.py). That gives a miniscule chance
for name collision.

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

diff --git a/src/kimchi/model/featuretests.py b/src/kimchi/model/featuretests.py
index 5a45990..aa8d709 100644
--- a/src/kimchi/model/featuretests.py
+++ b/src/kimchi/model/featuretests.py
@@ -24,6 +24,7 @@
 import socket
 import subprocess
 import threading
+import uuid
 
 
 from lxml.builder import E
@@ -35,7 +36,7 @@
 
 ISO_STREAM_XML = """
 <domain type='%(domain)s'>
-  <name>ISO_STREAMING</name>
+  <name>'%(name)s'</name>
   <memory unit='KiB'>1048576</memory>
   <os>
     <type arch='%(arch)s'>hvm</type>
@@ -57,7 +58,7 @@
 
 SIMPLE_VM_XML = """
 <domain type='%(domain)s'>
-  <name>A_SIMPLE_VM</name>
+  <name>'%(name)s'</name>
   <memory unit='KiB'>10240</memory>
   <os>
     <type arch='%(arch)s'>hvm</type>
@@ -105,8 +106,10 @@ def libvirt_supports_iso_stream(conn, protocol):
         domain_type = 'test' if conn.getType().lower() == 'test' else 'kvm'
         arch = 'ppc64' if platform.machine() == 'ppc64le' \
             else platform.machine()
+        vm_uuid = uuid.uuid1()
+        vm_name = "ISO_STREAM_%s" % vm_uuid
         xml = ISO_STREAM_XML % {'domain': domain_type, 'protocol': protocol,
-                                'arch': arch}
+                                'arch': arch, 'name': vm_name}
         try:
             FeatureTests.disable_libvirt_error_logging()
             dom = conn.defineXML(xml)
@@ -196,8 +199,11 @@ def has_metadata_support(conn):
             domain_type = 'test' if conn.getType().lower() == 'test' else 'kvm'
             arch = 'ppc64' if platform.machine() == 'ppc64le' \
                 else platform.machine()
+            vm_uuid = uuid.uuid1()
+            vm_name = "A_SIMPLE_VM_%s" % vm_uuid
             dom = conn.defineXML(SIMPLE_VM_XML % {'domain': domain_type,
-                                                  'arch': arch})
+                                                  'arch': arch,
+                                                  'name': vm_name})
             rollback.prependDefer(dom.undefine)
             try:
                 dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT,
-- 
1.9.3




More information about the Kimchi-devel mailing list