[Kimchi-devel] [PATCH 1/3] Update FeatureTests to use the same libvirt connection used by Model

Aline Manera alinefm at linux.vnet.ibm.com
Tue Nov 4 23:27:07 UTC 2014


The former code was running the FeatureTests with the system libvirt
connection, so if a developer used Model() with a different
libvirt URI the feature tests would report a false positive result.
To avoid this problem share the libvirt connection used by Model() with
FeatureTests.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/kimchi/featuretests.py | 17 ++++-------------
 src/kimchi/model/config.py | 10 ++++++----
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
index f1eb8ae..a8613aa 100644
--- a/src/kimchi/featuretests.py
+++ b/src/kimchi/featuretests.py
@@ -100,12 +100,10 @@ class FeatureTests(object):
         libvirt.registerErrorHandler(f=None, ctx=None)
 
     @staticmethod
-    def libvirt_supports_iso_stream(protocol):
+    def libvirt_supports_iso_stream(conn, protocol):
         xml = ISO_STREAM_XML % {'protocol': protocol}
-        conn = None
         try:
             FeatureTests.disable_libvirt_error_logging()
-            conn = libvirt.open(None)
             dom = conn.defineXML(xml)
             dom.undefine()
             return True
@@ -114,16 +112,14 @@ class FeatureTests(object):
             return False
         finally:
             FeatureTests.enable_libvirt_error_logging()
-            conn is None or conn.close()
 
     @staticmethod
-    def libvirt_support_nfs_probe():
+    def libvirt_support_nfs_probe(conn):
         def _get_xml():
             obj = E.source(E.host(name='localhost'), E.format(type='nfs'))
             xml = ET.tostring(obj)
             return xml
         try:
-            conn = libvirt.open(None)
             FeatureTests.disable_libvirt_error_logging()
             conn.findStoragePoolSources('netfs', _get_xml(), 0)
         except libvirt.libvirtError as e:
@@ -134,7 +130,6 @@ class FeatureTests(object):
                 return False
         finally:
             FeatureTests.enable_libvirt_error_logging()
-            conn is None or conn.close()
 
         return True
 
@@ -172,10 +167,9 @@ class FeatureTests(object):
         return True
 
     @staticmethod
-    def libvirt_support_fc_host():
+    def libvirt_support_fc_host(conn):
         try:
             FeatureTests.disable_libvirt_error_logging()
-            conn = libvirt.open(None)
             pool = None
             pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0)
         except libvirt.libvirtError as e:
@@ -185,18 +179,15 @@ class FeatureTests(object):
         finally:
             FeatureTests.enable_libvirt_error_logging()
             pool is None or pool.undefine()
-            conn is None or conn.close()
         return True
 
     @staticmethod
-    def has_metadata_support():
+    def has_metadata_support(conn):
         KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi/"
         KIMCHI_NAMESPACE = "kimchi"
         with RollbackContext() as rollback:
             FeatureTests.disable_libvirt_error_logging()
             rollback.prependDefer(FeatureTests.enable_libvirt_error_logging)
-            conn = libvirt.open(None)
-            rollback.prependDefer(conn.close)
             dom = conn.defineXML(SIMPLE_VM_XML)
             rollback.prependDefer(dom.undefine)
             try:
diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py
index 9ffc53e..73ca9c0 100644
--- a/src/kimchi/model/config.py
+++ b/src/kimchi/model/config.py
@@ -48,6 +48,7 @@ class CapabilitiesModel(object):
     __metaclass__ = Singleton
 
     def __init__(self, **kargs):
+        self.conn = kargs['conn']
         self.qemu_stream = False
         self.qemu_stream_dns = False
         self.libvirt_stream_protocols = []
@@ -62,16 +63,17 @@ class CapabilitiesModel(object):
 
     def _set_capabilities(self):
         kimchi_log.info("*** Running feature tests ***")
+        conn = self.conn.get()
         self.qemu_stream = FeatureTests.qemu_supports_iso_stream()
         self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns()
-        self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe()
-        self.fc_host_support = FeatureTests.libvirt_support_fc_host()
-        self.metadata_support = FeatureTests.has_metadata_support()
+        self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe(conn)
+        self.fc_host_support = FeatureTests.libvirt_support_fc_host(conn)
+        self.metadata_support = FeatureTests.has_metadata_support(conn)
         self.kernel_vfio = FeatureTests.kernel_support_vfio()
 
         self.libvirt_stream_protocols = []
         for p in ['http', 'https', 'ftp', 'ftps', 'tftp']:
-            if FeatureTests.libvirt_supports_iso_stream(p):
+            if FeatureTests.libvirt_supports_iso_stream(conn, p):
                 self.libvirt_stream_protocols.append(p)
 
         kimchi_log.info("*** Feature tests completed ***")
-- 
1.9.3




More information about the Kimchi-devel mailing list