[Kimchi-devel] [PATCH] Enable remote libvirtds v2

bbaude at redhat.com bbaude at redhat.com
Tue Oct 7 21:33:30 UTC 2014


From: Brent Baude <bbaude at redhat.com>

v2 patch to remove static qemu assignments which will allow
a remote livirtd
---
 src/kimchi/config.py.in               |  2 +-
 src/kimchi/featuretests.py            |  8 ++++----
 src/kimchi/kvmusertests.py            |  2 +-
 src/kimchi/model/libvirtconnection.py | 20 +++++++++++++++++---
 src/kimchi/model/model.py             |  5 +++--
 src/kimchi/model/networks.py          |  2 +-
 tests/test_model.py                   | 16 ++++++++--------
 7 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in
index 91e5f48..6e24d11 100644
--- a/src/kimchi/config.py.in
+++ b/src/kimchi/config.py.in
@@ -62,7 +62,7 @@ def get_version():
 
 def find_qemu_binary(find_emulator=False):
     try:
-        connect = libvirt.open('qemu:///system')
+        connect = libvirt.open(None)
     except Exception, e:
         raise Exception("Unable to get qemu binary location: %s" % e)
     try:
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
index 8964098..b7b482a 100644
--- a/src/kimchi/featuretests.py
+++ b/src/kimchi/featuretests.py
@@ -104,7 +104,7 @@ class FeatureTests(object):
         conn = None
         try:
             FeatureTests.disable_screen_error_logging()
-            conn = libvirt.open('qemu:///system')
+            conn = libvirt.open(None)
             dom = conn.defineXML(xml)
             dom.undefine()
             return True
@@ -122,7 +122,7 @@ class FeatureTests(object):
             xml = ET.tostring(obj)
             return xml
         try:
-            conn = libvirt.open('qemu:///system')
+            conn = libvirt.open(None)
             FeatureTests.disable_screen_error_logging()
             conn.findStoragePoolSources('netfs', _get_xml(), 0)
         except libvirt.libvirtError as e:
@@ -174,7 +174,7 @@ class FeatureTests(object):
     def libvirt_support_fc_host():
         try:
             FeatureTests.disable_screen_error_logging()
-            conn = libvirt.open('qemu:///system')
+            conn = libvirt.open(None)
             pool = None
             pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0)
         except libvirt.libvirtError as e:
@@ -194,7 +194,7 @@ class FeatureTests(object):
         with RollbackContext() as rollback:
             FeatureTests.disable_screen_error_logging()
             rollback.prependDefer(FeatureTests.enable_screen_error_logging)
-            conn = libvirt.open('qemu:///system')
+            conn = libvirt.open(None)
             rollback.prependDefer(conn.close)
             dom = conn.defineXML(SIMPLE_VM_XML)
             rollback.prependDefer(dom.undefine)
diff --git a/src/kimchi/kvmusertests.py b/src/kimchi/kvmusertests.py
index 1ac2beb..2326727 100644
--- a/src/kimchi/kvmusertests.py
+++ b/src/kimchi/kvmusertests.py
@@ -49,7 +49,7 @@ class UserTests(object):
 
         xml = cls.SIMPLE_VM_XML % (vm_name, vm_uuid)
         with RollbackContext() as rollback:
-            conn = libvirt.open('qemu:///system')
+            conn = libvirt.open(None)
             rollback.prependDefer(conn.close)
             dom = conn.defineXML(xml)
             rollback.prependDefer(dom.undefine)
diff --git a/src/kimchi/model/libvirtconnection.py b/src/kimchi/model/libvirtconnection.py
index 80348a3..4fd2393 100644
--- a/src/kimchi/model/libvirtconnection.py
+++ b/src/kimchi/model/libvirtconnection.py
@@ -93,10 +93,13 @@ class LibvirtConnection(object):
                     except libvirt.libvirtError:
                         kimchi_log.error('Unable to connect to libvirt.')
                         if not retries:
-                            err = 'Libvirt is not available, exiting.'
-                            kimchi_log.error(err)
+                            kimchi_log.error("Unable to establish connection "
+                                             "with libvirt. Please check "
+                                             "your libvirt URI which is often "
+                                             "defined in "
+                                             "/etc/libvirt/libvirt.conf")
                             cherrypy.engine.stop()
-                            raise
+                            exit(1)
                     time.sleep(2)
 
                 for name in dir(libvirt.virConnect):
@@ -117,3 +120,14 @@ class LibvirtConnection(object):
                 # However the values need to be considered wisely to not affect
                 # hosts which are hosting a lot of virtual machines
             return conn
+
+    def isQemuURI(self):
+        """
+        This method will return True or Value when the system libvirt
+        URI is a qemu based URI.  For example:
+        qemu:///system or qemu+tcp://someipaddress/system
+        """
+        if self.get().getURI().startswith('qemu'):
+            return True
+        else:
+            return False
diff --git a/src/kimchi/model/model.py b/src/kimchi/model/model.py
index ac70852..566be66 100644
--- a/src/kimchi/model/model.py
+++ b/src/kimchi/model/model.py
@@ -38,12 +38,13 @@ DEFAULT_POOLS = {'default': {'path': '/var/lib/libvirt/images'},
 
 
 class Model(BaseModel):
-    def __init__(self, libvirt_uri='qemu:///system', objstore_loc=None):
+    def __init__(self, libvirt_uri=None, objstore_loc=None):
+
         self.objstore = ObjectStore(objstore_loc)
         self.conn = LibvirtConnection(libvirt_uri)
         kargs = {'objstore': self.objstore, 'conn': self.conn}
 
-        if 'qemu:///' in libvirt_uri:
+        if self.conn.isQemuURI():
             for pool_name, pool_arg in DEFAULT_POOLS.iteritems():
                 self._default_pool_check(pool_name, pool_arg)
 
diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index 0ea9449..43f9d50 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -41,7 +41,7 @@ KIMCHI_BRIDGE_PREFIX = 'kb'
 class NetworksModel(object):
     def __init__(self, **kargs):
         self.conn = kargs['conn']
-        if 'qemu:///' in self.conn.get().getURI():
+        if self.conn.isQemuURI():
             self._default_network_check()
 
     def _default_network_check(self):
diff --git a/tests/test_model.py b/tests/test_model.py
index 1f2e79c..3bb090e 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -457,7 +457,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_storagepool(self):
-        inst = model.Model('qemu:///system', self.tmp_store)
+        inst = model.Model(None, self.tmp_store)
 
         poolDefs = [
             {'type': 'dir',
@@ -524,7 +524,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_storagevolume(self):
-        inst = model.Model('qemu:///system', self.tmp_store)
+        inst = model.Model(None, self.tmp_store)
 
         with RollbackContext() as rollback:
             path = '/tmp/kimchi-images'
@@ -742,7 +742,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_template_clone(self):
-        inst = model.Model('qemu:///system',
+        inst = model.Model(None,
                            objstore_loc=self.tmp_store)
         with RollbackContext() as rollback:
             orig_params = {'name': 'test-template', 'memory': 1024,
@@ -761,7 +761,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_template_update(self):
-        inst = model.Model('qemu:///system',
+        inst = model.Model(None,
                            objstore_loc=self.tmp_store)
         with RollbackContext() as rollback:
             net_name = 'test-network'
@@ -801,7 +801,7 @@ class ModelTests(unittest.TestCase):
                               'new-test', params)
 
     def test_vm_edit(self):
-        inst = model.Model('qemu:///system',
+        inst = model.Model(None,
                            objstore_loc=self.tmp_store)
 
         orig_params = {'name': 'test', 'memory': '1024', 'cpus': '1',
@@ -914,7 +914,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_network(self):
-        inst = model.Model('qemu:///system', self.tmp_store)
+        inst = model.Model(None, self.tmp_store)
 
         with RollbackContext() as rollback:
 
@@ -1240,7 +1240,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_get_hostinfo(self):
-        inst = model.Model('qemu:///system',
+        inst = model.Model(None,
                            objstore_loc=self.tmp_store)
         info = inst.host_lookup()
         distro, version, codename = platform.linux_distribution()
@@ -1279,7 +1279,7 @@ class ModelTests(unittest.TestCase):
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_deep_scan(self):
-        inst = model.Model('qemu:///system',
+        inst = model.Model(None,
                            objstore_loc=self.tmp_store)
         with RollbackContext() as rollback:
             path = '/tmp/kimchi-images/tmpdir'
-- 
1.9.3




More information about the Kimchi-devel mailing list