[PATCH] use LibvirtConnection instead of libivrt open directily to to get connection

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> On my F20, the kimchi can not start. It report: $ sudo PYTHONPATH=src ./src/kimchid *** Running feature tests *** [21/May/2014:19:41:48] ENGINE Error in 'start' listener <bound method CapabilitiesModel._set_capabilities of <kimchi.model.config.CapabilitiesModel object at 0x314ac10>> Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/process/wspbus.py", line 197, in publish output.append(listener(*args, **kwargs)) File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/config.py", line 69, in _set_capabilities self.metadata_support = FeatureTests.has_metadata_support() File "/home/shhfeng/work/workdir/kimchi/src/kimchi/featuretests.py", line 197, in has_metadata_support conn = libvirt.open('qemu:///system') File "/usr/lib64/python2.7/site-packages/libvirt.py", line 247, in open if ret is None:raise libvirtError('virConnectOpen() failed') libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused [21/May/2014:19:41:48] ENGINE Shutting down due to error in start listener: [21/May/2014:19:41:48] ENGINE Bus STOPPING Now use LibvirtConnection to get connection, kimchi can work well. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/featuretests.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index 5192361..df833e1 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -28,6 +28,7 @@ from lxml.builder import E +from kimchi.model.libvirtconnection import LibvirtConnection from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log @@ -104,7 +105,7 @@ def libvirt_supports_iso_stream(protocol): conn = None try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() dom = conn.defineXML(xml) dom.undefine() return True @@ -122,7 +123,7 @@ def _get_xml(): xml = ET.tostring(obj) return xml try: - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() FeatureTests.disable_screen_error_logging() conn.findStoragePoolSources('netfs', _get_xml(), 0) except libvirt.libvirtError as e: @@ -174,7 +175,7 @@ def qemu_iso_stream_dns(): def libvirt_support_fc_host(): try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() pool = None pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0) except libvirt.libvirtError as e: @@ -194,7 +195,7 @@ def has_metadata_support(): with RollbackContext() as rollback: FeatureTests.disable_screen_error_logging() rollback.prependDefer(FeatureTests.enable_screen_error_logging) - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() rollback.prependDefer(conn.close) dom = conn.defineXML(SIMPLE_VM_XML) rollback.prependDefer(dom.undefine) -- 1.9.0

On 22-05-2014 11:26, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
On my F20, the kimchi can not start. It report: $ sudo PYTHONPATH=src ./src/kimchid *** Running feature tests *** [21/May/2014:19:41:48] ENGINE Error in 'start' listener <bound method CapabilitiesModel._set_capabilities of <kimchi.model.config.CapabilitiesModel object at 0x314ac10>> Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/process/wspbus.py", line 197, in publish output.append(listener(*args, **kwargs)) File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/config.py", line 69, in _set_capabilities self.metadata_support = FeatureTests.has_metadata_support() File "/home/shhfeng/work/workdir/kimchi/src/kimchi/featuretests.py", line 197, in has_metadata_support conn = libvirt.open('qemu:///system') File "/usr/lib64/python2.7/site-packages/libvirt.py", line 247, in open if ret is None:raise libvirtError('virConnectOpen() failed') libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused
[21/May/2014:19:41:48] ENGINE Shutting down due to error in start listener: [21/May/2014:19:41:48] ENGINE Bus STOPPING
Now use LibvirtConnection to get connection, kimchi can work well.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Do you know why that problem is happening to you? Do you know why that is the right solution? I'm running Kimchi on Fedora 20 as well and I don't have that error. And by reading the commit message, I didn't understand why using that other class/method works well.

On 05/23/2014 12:07 AM, Crístian Viana wrote:
On 22-05-2014 11:26, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
On my F20, the kimchi can not start. It report: $ sudo PYTHONPATH=src ./src/kimchid *** Running feature tests *** [21/May/2014:19:41:48] ENGINE Error in 'start' listener <bound method CapabilitiesModel._set_capabilities of <kimchi.model.config.CapabilitiesModel object at 0x314ac10>> Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/process/wspbus.py", line 197, in publish output.append(listener(*args, **kwargs)) File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/config.py", line 69, in _set_capabilities self.metadata_support = FeatureTests.has_metadata_support() File "/home/shhfeng/work/workdir/kimchi/src/kimchi/featuretests.py", line 197, in has_metadata_support conn = libvirt.open('qemu:///system') File "/usr/lib64/python2.7/site-packages/libvirt.py", line 247, in open if ret is None:raise libvirtError('virConnectOpen() failed') libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused
[21/May/2014:19:41:48] ENGINE Shutting down due to error in start listener: [21/May/2014:19:41:48] ENGINE Bus STOPPING
Now use LibvirtConnection to get connection, kimchi can work well.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Do you know why that problem is happening to you? Do you know why that is the right solution? I'm running Kimchi on Fedora 20 as well and I don't have that error. And by reading the commit message, I didn't understand why using that other class/method works well.
Not sure the root reason, I have look into this for a long time, not find the root reason. Also zhengsheng also can not reproduce it on his Fedora20. This is caused by: libvirt_support_fc_host in libvirt_support_fc_host. as follow: try: conn = libvirt.open('qemu:///system') pool = None pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0) except libvirt.libvirtError as e: if e.get_error_code() == 27: # Libvirt requires adapter name, not needed when supports to FC else: print e.get_error_code(), e finally: print "finally close pool and conn" pool is None or pool.undefine() print pool, conn conn is None or conn.close() conn = libvirt.open("qemu:///system") conn.close() it does not raise VIR_ERR_XML_ERROR(27), an XML description is not well formed or broken. It raise VIR_ERR_SYSTEM_ERROR(38) , general system call failure from the libvirt log it is: 2014-05-23 02:09:32.831+0000: 17127: info : libvirt version: 1.1.3.4, package: 4.fc20 (Fedora Project, 2014-03-18-18:53:51, buildvm-21.phx2.fedoraproject.org) 2014-05-23 02:09:32.831+0000: 17127: error : virCommandWait:2376 : internal error: Child process (/usr/sbin/iscsiadm --mode session) unexpected exit status 21 And this error log raises about several seconds later after connection is closed. Not sure why libvirt call "iscsiadm" when we just try to create a scsi pool. Maybe need to look into libvirt code. LibvirtConnection will try to get connection several times with 2s interval. so LibvirtConnection can avoid this problem. -- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

I think the reason you succeed in using LibvirtConnection may be it retries several times when encountering error. LibvirtConnection is useful to me for it reuse the connection instance and avoid opening new instance. But with differenct LibvirtConnection object, I think reuse cannot work. So what about a global object for all feature tests? On 2014年05月22日 22:26, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
On my F20, the kimchi can not start. It report: $ sudo PYTHONPATH=src ./src/kimchid *** Running feature tests *** [21/May/2014:19:41:48] ENGINE Error in 'start' listener <bound method CapabilitiesModel._set_capabilities of <kimchi.model.config.CapabilitiesModel object at 0x314ac10>> Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/process/wspbus.py", line 197, in publish output.append(listener(*args, **kwargs)) File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/config.py", line 69, in _set_capabilities self.metadata_support = FeatureTests.has_metadata_support() File "/home/shhfeng/work/workdir/kimchi/src/kimchi/featuretests.py", line 197, in has_metadata_support conn = libvirt.open('qemu:///system') File "/usr/lib64/python2.7/site-packages/libvirt.py", line 247, in open if ret is None:raise libvirtError('virConnectOpen() failed') libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused
[21/May/2014:19:41:48] ENGINE Shutting down due to error in start listener: [21/May/2014:19:41:48] ENGINE Bus STOPPING
Now use LibvirtConnection to get connection, kimchi can work well.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/featuretests.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index 5192361..df833e1 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -28,6 +28,7 @@ from lxml.builder import E
+from kimchi.model.libvirtconnection import LibvirtConnection from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log
@@ -104,7 +105,7 @@ def libvirt_supports_iso_stream(protocol): conn = None try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() dom = conn.defineXML(xml) dom.undefine() return True @@ -122,7 +123,7 @@ def _get_xml(): xml = ET.tostring(obj) return xml try: - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() FeatureTests.disable_screen_error_logging() conn.findStoragePoolSources('netfs', _get_xml(), 0) except libvirt.libvirtError as e: @@ -174,7 +175,7 @@ def qemu_iso_stream_dns(): def libvirt_support_fc_host(): try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() pool = None pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0) except libvirt.libvirtError as e: @@ -194,7 +195,7 @@ def has_metadata_support(): with RollbackContext() as rollback: FeatureTests.disable_screen_error_logging() rollback.prependDefer(FeatureTests.enable_screen_error_logging) - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() rollback.prependDefer(conn.close) dom = conn.defineXML(SIMPLE_VM_XML) rollback.prependDefer(dom.undefine)

On 05/26/2014 12:05 AM, Royce Lv wrote:
I think the reason you succeed in using LibvirtConnection may be it retries several times when encountering error. LibvirtConnection is useful to me for it reuse the connection instance and avoid opening new instance. But with differenct LibvirtConnection object, I think reuse cannot work. So what about a global object for all feature tests?
Usually we call the FeatureTests in CapabilitiesModel() In CapabilitiesModel() there is already a LibvirtConnection instance - maybe we can reuse it while calling FeatureTests()
On 2014年05月22日 22:26, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
On my F20, the kimchi can not start. It report: $ sudo PYTHONPATH=src ./src/kimchid *** Running feature tests *** [21/May/2014:19:41:48] ENGINE Error in 'start' listener <bound method CapabilitiesModel._set_capabilities of <kimchi.model.config.CapabilitiesModel object at 0x314ac10>> Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cherrypy/process/wspbus.py", line 197, in publish output.append(listener(*args, **kwargs)) File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/config.py", line 69, in _set_capabilities self.metadata_support = FeatureTests.has_metadata_support() File "/home/shhfeng/work/workdir/kimchi/src/kimchi/featuretests.py", line 197, in has_metadata_support conn = libvirt.open('qemu:///system') File "/usr/lib64/python2.7/site-packages/libvirt.py", line 247, in open if ret is None:raise libvirtError('virConnectOpen() failed') libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused
[21/May/2014:19:41:48] ENGINE Shutting down due to error in start listener: [21/May/2014:19:41:48] ENGINE Bus STOPPING
Now use LibvirtConnection to get connection, kimchi can work well.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/featuretests.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index 5192361..df833e1 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -28,6 +28,7 @@ from lxml.builder import E
+from kimchi.model.libvirtconnection import LibvirtConnection from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log
@@ -104,7 +105,7 @@ def libvirt_supports_iso_stream(protocol): conn = None try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() dom = conn.defineXML(xml) dom.undefine() return True @@ -122,7 +123,7 @@ def _get_xml(): xml = ET.tostring(obj) return xml try: - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() FeatureTests.disable_screen_error_logging() conn.findStoragePoolSources('netfs', _get_xml(), 0) except libvirt.libvirtError as e: @@ -174,7 +175,7 @@ def qemu_iso_stream_dns(): def libvirt_support_fc_host(): try: FeatureTests.disable_screen_error_logging() - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() pool = None pool = conn.storagePoolDefineXML(SCSI_FC_XML, 0) except libvirt.libvirtError as e: @@ -194,7 +195,7 @@ def has_metadata_support(): with RollbackContext() as rollback: FeatureTests.disable_screen_error_logging() rollback.prependDefer(FeatureTests.enable_screen_error_logging) - conn = libvirt.open('qemu:///system') + conn = LibvirtConnection('qemu:///system').get() rollback.prependDefer(conn.close) dom = conn.defineXML(SIMPLE_VM_XML) rollback.prependDefer(dom.undefine)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
participants (5)
-
Aline Manera
-
Crístian Viana
-
Royce Lv
-
shaohef@linux.vnet.ibm.com
-
Sheldon