[Kimchi-devel] [kimchi-devel][PATCH 1/2] Avoid using server dependent feature tests when server not running

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Tue Feb 3 08:47:06 UTC 2015


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

This patch forces all server dependent feature tests return False
to prevent wrong results returned when used as imported module.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/featuretests.py | 5 ++++-
 src/kimchi/utils.py              | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/model/featuretests.py b/src/kimchi/model/featuretests.py
index c187f86..c1ab972 100644
--- a/src/kimchi/model/featuretests.py
+++ b/src/kimchi/model/featuretests.py
@@ -29,7 +29,7 @@ from lxml.builder import E
 
 
 from kimchi.rollbackcontext import RollbackContext
-from kimchi.utils import kimchi_log, run_command
+from kimchi.utils import kimchi_log, run_command, servermethod
 
 
 ISO_STREAM_XML = """
@@ -135,6 +135,7 @@ class FeatureTests(object):
         return True
 
     @staticmethod
+    @servermethod
     def qemu_supports_iso_stream():
         host = cherrypy.server.socket_host
         port = cherrypy.server.socket_port
@@ -146,6 +147,7 @@ class FeatureTests(object):
         return len(stderr) == 0
 
     @staticmethod
+    @servermethod
     def qemu_iso_stream_dns():
         host = socket.getfqdn(cherrypy.server.socket_host)
         port = cherrypy.server.socket_port
@@ -153,6 +155,7 @@ class FeatureTests(object):
                (host, port), "-c", "'read -v 0 512'"]
         proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
+
         thread = threading.Thread(target=proc.communicate)
         thread.start()
         thread.join(5)
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
index fc5245f..28e547e 100644
--- a/src/kimchi/utils.py
+++ b/src/kimchi/utils.py
@@ -388,3 +388,11 @@ def get_unique_file_name(all_names, name):
             max_num = max(max_num, int(match.group(re_group_num)))
 
     return u'%s (%d)' % (name, max_num + 1)
+
+
+def servermethod(f):
+    def wrapper(*args, **kwargs):
+        if str(cherrypy.engine.state) != "states.STARTED":
+            return False
+        return f(*args, **kwargs)
+    return wrapper
-- 
1.9.3




More information about the Kimchi-devel mailing list