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 @@
#
##############################################################################
from os import environ, remove
from os import environ
from os.path import exists, join
from subprocess import Popen, PIPE
from threading import Lock
......@@ -34,7 +34,8 @@ from cloudooo.ooolib import setUpUnoEnvironment
from zope.interface import implements
from application import Application
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):
"""Object to control one OOo Instance and all features instance."""
......@@ -56,25 +57,19 @@ class OpenOffice(Application):
"""Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], self.pid()))
command = [self.python_path
, self.unoconverter_bin
, "--test"
, self.openoffice_tester_bin
, "--hostname=%s" % host
, "--port=%s" % port
, "--document_url=%s" % self.document_url
, "--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]
, "--uno_path=%s" % self.uno_path]
logger.debug("Testing Openoffice Instance %s" % port)
stdout, stderr = Popen(" ".join(command), shell=True, stdout=PIPE,
stderr=PIPE).communicate()
if not stdout and stderr != "":
logger.debug(stderr)
stderr=PIPE, close_fds=True).communicate()
stdout_bool = convertStringToBool(stdout.replace("\n",""))
if stdout_bool and stderr != "":
logger.debug("%s\n%s" % (stderr, stdout))
return False
else:
url = stdout.replace("\n", "")
logger.debug("Instance %s works" % port)
remove(url)
return True
def _cleanRequest(self):
......@@ -99,6 +94,7 @@ class OpenOffice(Application):
self.unoconverter_bin = kw.get("unoconverter_bin", "unoconverter")
self.python_path = kw.get('python_path', 'python')
self.unomimemapper_bin = kw.get("unomimemapper_bin")
self.openoffice_tester_bin = kw.get("openoffice_tester_bin")
def _start_process(self, command, env):
"""Start OpenOffice.org process"""
......@@ -108,11 +104,8 @@ class OpenOffice(Application):
close_fds=True,
env=env)
waitStartDaemon(self, self.timeout)
if exists(self.document_url):
return self._testOpenOffice(self.hostname, self.port)
return True
def start(self):
"""Start Instance."""
self.path_user_installation = join(self.path_run_dir, \
......
#!/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):
gc.enable()
debug_mode = convertStringToBool(local_config.get('debug_mode'))
configureLogger(debug_mode=debug_mode)
document_name = local_config.get("document_name")
# path of directory to 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
cloudooo_path_tmp_dir = path.join(path_dir_run_cloudooo, 'tmp')
cleanDirectory(cloudooo_path_tmp_dir)
......@@ -87,9 +86,6 @@ def application(global_config, **local_config):
start_timeout=local_config.get('start_timeout'))
xvfb.start()
document_url = path.join(path.dirname(__file__),
"tests/data/%s" % document_name)
# Loading Configuration to start OOo Instance and control it
openoffice.loadSettings(application_hostname,
openoffice_port,
......@@ -97,10 +93,10 @@ def application(global_config, **local_config):
local_config.get('virtual_display_id'),
local_config.get('office_bin_path'),
local_config.get('uno_path'),
document_url=document_url,
unoconverter_bin=local_config.get('unoconverter_bin'),
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()
monitor.load(local_config)
......
import sys
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',
version=version,
......@@ -39,5 +35,6 @@ setup(name='cloudooo',
[console_scripts]
unoconverter.py = cloudooo.bin.unoconverter: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