Commit ee393c0a authored by Gabriel Monnerat's avatar Gabriel Monnerat

add script openoffice_tester.py to test the OpenOffice.org via socket. When...

add script openoffice_tester.py to test the OpenOffice.org via socket. When the OpenOffice.org is started this process is tested, if occurs error the openoffice.org is restarted. This way is more fast and reliable.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@37677 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 73304421
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
############################################################################## ##############################################################################
from os import environ, remove from os import environ
from os.path import exists, join from os.path import exists, join
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from threading import Lock from threading import Lock
...@@ -34,7 +34,8 @@ from cloudooo.ooolib import setUpUnoEnvironment ...@@ -34,7 +34,8 @@ from cloudooo.ooolib import setUpUnoEnvironment
from zope.interface import implements from zope.interface import implements
from application import Application from application import Application
from cloudooo.interfaces.lockable import ILockable from cloudooo.interfaces.lockable import ILockable
from cloudooo.utils import logger, waitStartDaemon, removeDirectory, waitStopDaemon from cloudooo.utils import logger, waitStartDaemon,\
removeDirectory, waitStopDaemon, convertStringToBool
class OpenOffice(Application): class OpenOffice(Application):
"""Object to control one OOo Instance and all features instance.""" """Object to control one OOo Instance and all features instance."""
...@@ -56,25 +57,19 @@ class OpenOffice(Application): ...@@ -56,25 +57,19 @@ class OpenOffice(Application):
"""Test if OpenOffice was started correctly""" """Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], self.pid())) logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], self.pid()))
command = [self.python_path command = [self.python_path
, self.unoconverter_bin , self.openoffice_tester_bin
, "--test"
, "--hostname=%s" % host , "--hostname=%s" % host
, "--port=%s" % port , "--port=%s" % port
, "--document_url=%s" % self.document_url , "--uno_path=%s" % self.uno_path]
, "--unomimemapper_bin=%s" % self.unomimemapper_bin
, "--python_path=%s" % self.python_path
, "--uno_path=%s" % self.uno_path
, "--office_bin_path=%s" % self.office_bin_path]
logger.debug("Testing Openoffice Instance %s" % port) logger.debug("Testing Openoffice Instance %s" % port)
stdout, stderr = Popen(" ".join(command), shell=True, stdout=PIPE, stdout, stderr = Popen(" ".join(command), shell=True, stdout=PIPE,
stderr=PIPE).communicate() stderr=PIPE, close_fds=True).communicate()
if not stdout and stderr != "": stdout_bool = convertStringToBool(stdout.replace("\n",""))
logger.debug(stderr) if stdout_bool and stderr != "":
logger.debug("%s\n%s" % (stderr, stdout))
return False return False
else: else:
url = stdout.replace("\n", "")
logger.debug("Instance %s works" % port) logger.debug("Instance %s works" % port)
remove(url)
return True return True
def _cleanRequest(self): def _cleanRequest(self):
...@@ -99,6 +94,7 @@ class OpenOffice(Application): ...@@ -99,6 +94,7 @@ class OpenOffice(Application):
self.unoconverter_bin = kw.get("unoconverter_bin", "unoconverter") self.unoconverter_bin = kw.get("unoconverter_bin", "unoconverter")
self.python_path = kw.get('python_path', 'python') self.python_path = kw.get('python_path', 'python')
self.unomimemapper_bin = kw.get("unomimemapper_bin") self.unomimemapper_bin = kw.get("unomimemapper_bin")
self.openoffice_tester_bin = kw.get("openoffice_tester_bin")
def _start_process(self, command, env): def _start_process(self, command, env):
"""Start OpenOffice.org process""" """Start OpenOffice.org process"""
...@@ -108,10 +104,7 @@ class OpenOffice(Application): ...@@ -108,10 +104,7 @@ class OpenOffice(Application):
close_fds=True, close_fds=True,
env=env) env=env)
waitStartDaemon(self, self.timeout) waitStartDaemon(self, self.timeout)
if exists(self.document_url): return self._testOpenOffice(self.hostname, self.port)
return self._testOpenOffice(self.hostname, self.port)
return True
def start(self): def start(self):
"""Start Instance.""" """Start Instance."""
......
#!/usr/bin/env python
import sys
from getopt import getopt, GetoptError
from cloudooo.utils import usage
from cloudooo import ooolib
from os import environ
def test_openoffice(hostname, port):
try:
ooolib.getServiceManager(hostname, port)
return True
except Exception, err:
print err
return False
def main():
try:
opt_list, arg_list = getopt(sys.argv[1:], "",
["port=","hostname=","uno_path="])
except GetoptError, e:
usage(sys.stderr, "%s \nUse --port and --hostname" % e)
sys.exit(2)
for opt, arg in opt_list:
if opt == "--port":
port = arg
elif opt == "--hostname":
hostname = arg
elif opt == "--uno_path":
environ["uno_path"] = arg
print test_openoffice(hostname, port)
if __name__ == "__main__":
main()
...@@ -67,10 +67,9 @@ def application(global_config, **local_config): ...@@ -67,10 +67,9 @@ def application(global_config, **local_config):
gc.enable() gc.enable()
debug_mode = convertStringToBool(local_config.get('debug_mode')) debug_mode = convertStringToBool(local_config.get('debug_mode'))
configureLogger(debug_mode=debug_mode) configureLogger(debug_mode=debug_mode)
document_name = local_config.get("document_name")
# path of directory to run cloudooo # path of directory to run cloudooo
path_dir_run_cloudooo = local_config.get('path_dir_run_cloudooo') path_dir_run_cloudooo = local_config.get('path_dir_run_cloudooo')
cleanDirectory(path_dir_run_cloudooo, ignore_list=["tmp", document_name]) cleanDirectory(path_dir_run_cloudooo, ignore_list=["tmp",])
# directory to create temporary files # directory to create temporary files
cloudooo_path_tmp_dir = path.join(path_dir_run_cloudooo, 'tmp') cloudooo_path_tmp_dir = path.join(path_dir_run_cloudooo, 'tmp')
cleanDirectory(cloudooo_path_tmp_dir) cleanDirectory(cloudooo_path_tmp_dir)
...@@ -86,10 +85,7 @@ def application(global_config, **local_config): ...@@ -86,10 +85,7 @@ def application(global_config, **local_config):
virtual_screen=local_config.get('virtual_screen'), virtual_screen=local_config.get('virtual_screen'),
start_timeout=local_config.get('start_timeout')) start_timeout=local_config.get('start_timeout'))
xvfb.start() xvfb.start()
document_url = path.join(path.dirname(__file__),
"tests/data/%s" % document_name)
# Loading Configuration to start OOo Instance and control it # Loading Configuration to start OOo Instance and control it
openoffice.loadSettings(application_hostname, openoffice.loadSettings(application_hostname,
openoffice_port, openoffice_port,
...@@ -97,10 +93,10 @@ def application(global_config, **local_config): ...@@ -97,10 +93,10 @@ def application(global_config, **local_config):
local_config.get('virtual_display_id'), local_config.get('virtual_display_id'),
local_config.get('office_bin_path'), local_config.get('office_bin_path'),
local_config.get('uno_path'), local_config.get('uno_path'),
document_url=document_url,
unoconverter_bin=local_config.get('unoconverter_bin'), unoconverter_bin=local_config.get('unoconverter_bin'),
python_path=local_config.get('python_path'), python_path=local_config.get('python_path'),
unomimemapper_bin=local_config.get('unomimemapper_bin')) unomimemapper_bin=local_config.get('unomimemapper_bin'),
openoffice_tester_bin=local_config.get('openoffice_tester_bin'))
openoffice.start() openoffice.start()
monitor.load(local_config) monitor.load(local_config)
......
import sys
from setuptools import setup, find_packages from setuptools import setup, find_packages
from os.path import realpath, exists, join, dirname
from os import symlink, unlink
from shutil import copyfile
version = '1.0.1' version = '1.0.2'
setup(name='cloudooo', setup(name='cloudooo',
version=version, version=version,
...@@ -39,5 +35,6 @@ setup(name='cloudooo', ...@@ -39,5 +35,6 @@ setup(name='cloudooo',
[console_scripts] [console_scripts]
unoconverter.py = cloudooo.bin.unoconverter:main unoconverter.py = cloudooo.bin.unoconverter:main
unomimemapper.py = cloudooo.bin.unomimemapper:main unomimemapper.py = cloudooo.bin.unomimemapper:main
openoffice_tester.py = cloudooo.bin.openoffice_tester:main
""", """,
) )
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