From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
Add nfs showmount cmd and parse its output, set timeout to be 10s.
With bug
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1264955,
Ubuntu libvirt run find-storage-pool-sources return error with error code 38,
generic system call error. While when server does not export any path,
it returns error code 1, internal error.
Leverage this to determine whether libvirt works right with target probe.
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
src/kimchi/featuretests.py | 22 ++++++++++++++++++++++
src/kimchi/utils.py | 20 ++++++++++++++++++--
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py
index a5755a2..32ad2ec 100644
--- a/src/kimchi/featuretests.py
+++ b/src/kimchi/featuretests.py
@@ -22,11 +22,15 @@
import cherrypy
import libvirt
+import lxml.etree as ET
import os
import subprocess
import threading
+from lxml.builder import E
+
+
from kimchi import config
@@ -70,6 +74,24 @@ class FeatureTests(object):
conn is None or conn.close()
@staticmethod
+ def libvirt_support_nfs_probe():
+ def _get_xml():
+ obj = E.source(E.host(name='localhost'),
E.format(type='nfs'))
+ xml = ET.tostring(obj)
+ return xml
+ try:
+ conn = libvirt.open('qemu:///system')
+ ret = conn.findStoragePoolSources('netfs', _get_xml(), 0)
+ except libvirt.libvirtError as e:
+ if e.get_error_code() == 38:
+ # if libvirt cannot find showmount,
+ # it returns 38--general system call failure
+ return False
+ finally:
+ conn is None or conn.close()
+ return True
+
+ @staticmethod
def qemu_supports_iso_stream():
cmd = "qemu-io -r
http://127.0.0.1:%d/images/icon-fedora.png \
-c 'read -v 0 512'" % cherrypy.server.socket_port
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index 5d6e8ea..c7ececf 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -159,6 +159,22 @@ def run_command(cmd, timeout=None):
def parse_cmd_output(output, output_items):
res = []
for line in output.split("\n"):
- res.append(dict(zip(output_items, line.split())))
-
+ if line:
+ res.append(dict(zip(output_items, line.split())))
return res
+
+
+def patch_find_nfs_target(nfs_server):
+ cmd = ["showmount", "--no-headers", "--exports",
nfs_server]
+ try:
+ out = run_command(cmd, 10)[0]
+ except TimeoutExpired:
+ kimchi_log.warning("server %s query timeout, may not have any path
exported",
+ storage_server)
+ return list()
+
+ targets = parse_cmd_output(out, output_items = ['target'])
+ for target in targets:
+ target['type'] = 'nfs'
+ target['host_name'] = nfs_server
+ return targets
--
1.8.1.2