Commit 985f0172 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor to control better the daemon

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@42253 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d66c2eb6
...@@ -8,7 +8,7 @@ from subprocess import Popen ...@@ -8,7 +8,7 @@ from subprocess import Popen
from cloudooo.handler.ooo.utils.utils import socketStatus from cloudooo.handler.ooo.utils.utils import socketStatus
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from os import chdir, path, environ, curdir from os import chdir, path, environ, curdir
import tempfile from psutil import Process
ENVIRONMENT_PATH = path.abspath(path.dirname(__file__)) ENVIRONMENT_PATH = path.abspath(path.dirname(__file__))
...@@ -20,11 +20,13 @@ def wait_liberate_port(hostname, port, timeout_limit=30): ...@@ -20,11 +20,13 @@ def wait_liberate_port(hostname, port, timeout_limit=30):
sleep(1) sleep(1)
def wait_use_port(hostname, port, timeout_limit=30): def wait_use_port(pid, timeout_limit=30):
process = Process(pid)
for n in range(timeout_limit): for n in range(timeout_limit):
if socketStatus(hostname, port): if len(process.get_connections()) > 0:
break return True
sleep(1) sleep(1)
return False
def exit(msg): def exit(msg):
...@@ -64,14 +66,10 @@ def run(): ...@@ -64,14 +66,10 @@ def run():
config = ConfigParser() config = ConfigParser()
config.read(server_cloudooo_conf) config.read(server_cloudooo_conf)
openoffice_port = int(config.get("app:main", "openoffice_port"))
hostname = config.get("app:main", "application_hostname")
server_port = int(config.get("server:main", "port"))
module = __import__(test_name) module = __import__(test_name)
if not hasattr(module, "test_suite"): if not hasattr(module, "test_suite"):
exit("No test suite to run, exiting immediately") exit("No test suite to run, exiting immediately")
DAEMON = getattr(module, 'DAEMON', False) DAEMON = getattr(module, 'DAEMON', False)
OPENOFFICE = getattr(module, 'OPENOFFICE', False) OPENOFFICE = getattr(module, 'OPENOFFICE', False)
XVFB = getattr(module, 'XVFB', False) XVFB = getattr(module, 'XVFB', False)
...@@ -81,21 +79,14 @@ def run(): ...@@ -81,21 +79,14 @@ def run():
suite.addTest(module.test_suite()) suite.addTest(module.test_suite())
if DAEMON: if DAEMON:
fd, pid_filename = tempfile.mkstemp() command = [paster_path, "serve", server_cloudooo_conf]
command = [paster_path, "serve", '--daemon', '--pid-file', pid_filename,
server_cloudooo_conf]
process = Popen(command) process = Popen(command)
wait_use_port(hostname, openoffice_port) wait_use_port(process.pid)
wait_use_port(hostname, server_port)
chdir(ENVIRONMENT_PATH) chdir(ENVIRONMENT_PATH)
try: try:
TestRunner(verbosity=2).run(suite) TestRunner(verbosity=2).run(suite)
finally: finally:
command = [paster_path, 'serve', '--stop-daemon', '--pid-file', process.terminate()
pid_filename]
stop_process = Popen(command)
stop_process.communicate()
# pid file is destroyed by paster
elif OPENOFFICE: elif OPENOFFICE:
chdir(ENVIRONMENT_PATH) chdir(ENVIRONMENT_PATH)
openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf) openoffice, xvfb = startFakeEnvironment(conf_path=server_cloudooo_conf)
......
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