Commit edacbe10 authored by Boris Kocherov's avatar Boris Kocherov

improve logging

parent 66e7ad71
...@@ -50,8 +50,14 @@ class Application(object): ...@@ -50,8 +50,14 @@ class Application(object):
if hasattr(self, 'process'): if hasattr(self, 'process'):
error = False error = False
process_pid = self.process.pid process_pid = self.process.pid
returncode = self.process.poll()
# libreoffice daemon want go to background
# so it return 0, so ignore 0
if returncode is not None and returncode != 0:
self.daemonOutputLog()
logger.debug("Process %s already ended with returncode %s", process_pid, returncode)
return False
logger.debug("Stop Pid - %s", process_pid) logger.debug("Stop Pid - %s", process_pid)
returncode = None
try: try:
process = Process(process_pid) process = Process(process_pid)
cmdline = " ".join(process.cmdline()) cmdline = " ".join(process.cmdline())
...@@ -74,10 +80,21 @@ class Application(object): ...@@ -74,10 +80,21 @@ class Application(object):
returncode = self.process.returncode returncode = self.process.returncode
if error and returncode: if error and returncode:
logger.error("Process %s cmdline: %s ended with returncode %s", process_pid, cmdline, returncode) logger.error("Process %s cmdline: %s ended with returncode %s", process_pid, cmdline, returncode)
elif returncode != 0: elif returncode is not None and returncode != 0:
self.daemonOutputLog()
logger.debug("Process %s ended with returncode %s", process_pid, returncode) logger.debug("Process %s ended with returncode %s", process_pid, returncode)
delattr(self, "process") delattr(self, "process")
def daemonOutputLog(self):
if hasattr(self, 'process'):
process_pid = self.process.pid
stdout = self.process.stdout.read()
if stdout:
logger.debug("Process %s stdout: %s", process_pid, stdout)
stderr = self.process.stderr.read()
if stderr:
logger.error("Process %s stderr: %s", process_pid, stderr)
def loadSettings(self, hostname, port, path_run_dir, **kwargs): def loadSettings(self, hostname, port, path_run_dir, **kwargs):
"""Define attributes for application instance """Define attributes for application instance
Keyword arguments: Keyword arguments:
......
...@@ -122,6 +122,8 @@ class OpenOffice(Application): ...@@ -122,6 +122,8 @@ class OpenOffice(Application):
for i in range(5): for i in range(5):
self.stop() self.stop()
self.process = Popen(command, self.process = Popen(command,
stdout=PIPE,
stderr=PIPE,
close_fds=True, close_fds=True,
env=env) env=env)
sleep(1) sleep(1)
......
...@@ -107,31 +107,6 @@ def stopFakeEnvironment(stop_openoffice=True): ...@@ -107,31 +107,6 @@ def stopFakeEnvironment(stop_openoffice=True):
openoffice.stop() openoffice.stop()
return True return True
if 1:
from cloudooo.handler.ooo.application.openoffice import OpenOffice
from cloudooo.handler.ooo.util import waitStartDaemon
from subprocess import Popen, PIPE
from time import sleep
# patch OpenOffice._startProcess not to put bogus output to stderr,
# that prevents detecting the end of unit test.
def _startProcess(self, command, env):
"""Start OpenOffice.org process"""
for i in range(5):
self.stop()
self.process = Popen(command, stderr=PIPE,
close_fds=True,
env=env)
sleep(1)
if self.process.poll() is not None:
# process already terminated so
# rerun
continue
if waitStartDaemon(self, self.timeout - 1):
break
OpenOffice._startProcess = _startProcess
class HandlerTestCase(unittest.TestCase): class HandlerTestCase(unittest.TestCase):
"""Test Case to load cloudooo conf.""" """Test Case to load 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