Commit 40549b55 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code to cloudooo daemon starts correctly

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@40341 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 73d51d12
...@@ -11,23 +11,18 @@ from subprocess import Popen ...@@ -11,23 +11,18 @@ from subprocess import Popen
ENVIRONMENT_PATH = path.abspath(path.dirname(__file__)) ENVIRONMENT_PATH = path.abspath(path.dirname(__file__))
def wait_liberate_port(hostname, port): def wait_liberate_port(hostname, port, timeout_limit=10):
for n in range(timeout_limit): for n in range(timeout_limit):
if not socketStatus(hostname, port): if not socketStatus(hostname, port):
break break
sleep(1) sleep(1)
def wait_use_port(hostname, port): def wait_use_port(hostname, port, timeout_limit=10):
for n in range(timeout_limit): for n in range(timeout_limit):
if socketStatus(hostname, port): if socketStatus(hostname, port):
return return
sleep(1) sleep(1)
def get_partial_log():
if path.exists(log_path):
return '\n'.join(open(log_path).read().split('\n')[-30:])
return ''
def exit(msg): def exit(msg):
sys.stderr.write(msg) sys.stderr.write(msg)
sys.exit(0) sys.exit(0)
...@@ -54,10 +49,13 @@ def run(): ...@@ -54,10 +49,13 @@ def run():
"log_path=", "log_path=",
"cloudooo_runner=", "cloudooo_runner=",
"server_cloudooo_conf=", "server_cloudooo_conf=",
"timeout_limit="]) "timeout_limit=",
"paster_path="])
except GetoptError, msg: except GetoptError, msg:
exit(msg.msg) exit(msg.msg)
paster_path = "paster"
for opt, arg in opt_list: for opt, arg in opt_list:
if opt == "--with-daemon": if opt == "--with-daemon":
DAEMON = True DAEMON = True
...@@ -74,11 +72,12 @@ def run(): ...@@ -74,11 +72,12 @@ def run():
environ["server_cloudooo_conf"] = arg environ["server_cloudooo_conf"] = arg
elif opt == "--timeout_limit": elif opt == "--timeout_limit":
timeout_limit = arg timeout_limit = arg
elif opt == "--paster_path":
paster_path = arg
from cloudoooTestCase import loadConfig, startFakeEnvironment, stopFakeEnvironment from cloudoooTestCase import loadConfig, startFakeEnvironment, stopFakeEnvironment
sys.path.append(ENVIRONMENT_PATH) sys.path.append(ENVIRONMENT_PATH)
chdir(ENVIRONMENT_PATH)
config = ConfigParser() config = ConfigParser()
config.read(server_cloudooo_conf) config.read(server_cloudooo_conf)
...@@ -91,24 +90,30 @@ def run(): ...@@ -91,24 +90,30 @@ def run():
if DAEMON: if DAEMON:
loadConfig(server_cloudooo_conf) loadConfig(server_cloudooo_conf)
Popen([cloudooo_runner, 'start']).communicate() command = [paster_path, "serve", server_cloudooo_conf]
process = Popen(" ".join(command), shell=True)
wait_use_port(hostname, server_port) wait_use_port(hostname, server_port)
print get_partial_log() chdir(ENVIRONMENT_PATH)
try: try:
run_test(test_name) run_test(test_name)
finally: finally:
Popen([cloudooo_runner, 'stop']).communicate() process.send_signal(1)
sleep(3)
process.terminate()
wait_liberate_port(hostname, server_port) wait_liberate_port(hostname, server_port)
elif OPENOFFICE: elif OPENOFFICE:
chdir(ENVIRONMENT_PATH)
openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf) openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf)
run_test(test_name) run_test(test_name)
stopFakeEnvironment() stopFakeEnvironment()
elif XVFB: elif XVFB:
chdir(ENVIRONMENT_PATH)
xvfb = startFakeEnvironment(start_openoffice=False, xvfb = startFakeEnvironment(start_openoffice=False,
conf_path=server_cloudooo_conf) conf_path=server_cloudooo_conf)
run_test(test_name) run_test(test_name)
stopFakeEnvironment(stop_openoffice=False) stopFakeEnvironment(stop_openoffice=False)
else: else:
chdir(ENVIRONMENT_PATH)
loadConfig(server_cloudooo_conf) loadConfig(server_cloudooo_conf)
run_test(test_name) run_test(test_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment