
From: Royce Lv <lvroyce@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@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