[Erp5-report] r41878 gabriel - in /erp5/trunk/utils/cloudooo/cloudooo: application/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Dec 30 15:01:50 CET 2010
Author: gabriel
Date: Thu Dec 30 15:01:50 2010
New Revision: 41878
URL: http://svn.erp5.org?rev=41878&view=rev
Log:
- Add function to stop OpenOffice.org that is using the same port to new OpenOffice.org and when this process isn't controlled by cloudooo
- Add test to check if this function will not stop the wrong OpenOffice.org process
Modified:
erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py
erp5/trunk/utils/cloudooo/cloudooo/tests/testOpenOffice.py
Modified: erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py?rev=41878&r1=41877&r2=41878&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py [utf8] Thu Dec 30 15:01:50 2010
@@ -27,6 +27,7 @@
##############################################################################
import pkg_resources
+import psutil
from os import environ
from os.path import exists, join
from subprocess import Popen, PIPE
@@ -36,7 +37,8 @@ from application import Application
from xvfb import xvfb
from cloudooo.interfaces.lockable import ILockable
from cloudooo.utils import logger, waitStartDaemon, removeDirectory, \
- waitStopDaemon, convertStringToBool
+ waitStopDaemon, convertStringToBool, \
+ socketStatus
class OpenOffice(Application):
@@ -103,6 +105,19 @@ class OpenOffice(Application):
waitStartDaemon(self, self.timeout)
return self._testOpenOffice(self.hostname, self.port)
+ def _releaseOpenOfficePort(self):
+ for process in psutil.process_iter():
+ try:
+ if process.exe == join(self.office_binary_path, self._bin_soffice):
+ connection_list = process.get_connections()
+ if len(connection_list) > 0 and \
+ connection_list[0].local_address[1] == self.port:
+ process.terminate()
+ except psutil.error.AccessDenied, e:
+ logger.error(e)
+ except NotImplementedError, e:
+ logger.error("lsof isn't installed on this machine: " + str(e))
+
def start(self):
"""Start Instance."""
if not xvfb.status():
@@ -128,6 +143,8 @@ class OpenOffice(Application):
env["TMP"] = self.path_user_installation
env["TMPDIR"] = self.path_user_installation
env["DISPLAY"] = ":%s" % self.display_id
+ if socketStatus(self.hostname, self.port):
+ self._releaseOpenOfficePort()
process_started = self._start_process(self.command, env)
if not process_started:
self.stop()
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testOpenOffice.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testOpenOffice.py?rev=41878&r1=41877&r2=41878&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testOpenOffice.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testOpenOffice.py [utf8] Thu Dec 30 15:01:50 2010
@@ -31,6 +31,7 @@ from cloudoooTestCase import cloudoooTes
from cloudooo.application.openoffice import OpenOffice
from cloudoooTestCase import make_suite
from cloudooo.utils import waitStopDaemon
+from psutil import Process, AccessDenied
class TestOpenOffice(cloudoooTestCase):
@@ -86,6 +87,79 @@ class TestOpenOffice(cloudoooTestCase):
self.openoffice.release()
self.assertEquals(self.openoffice.isLocked(), False)
+ def testStartTwoOpenOfficeWithTheSameAddress(self):
+ """Check if starting two openoffice using the same address, the second
+ openoffice will terminate the first"""
+ second_openoffice = OpenOffice()
+ second_openoffice.loadSettings("localhost", 4090,
+ self.working_path,
+ self.virtual_display_id,
+ self.office_binary_path,
+ self.uno_path)
+ try:
+ second_openoffice.start()
+ try:
+ openoffice_process = Process(self.openoffice.pid())
+ openoffice_process.get_connections()
+ self.fail("Access get_connections() function should fails")
+ except AccessDenied:
+ self.assertTrue("Excepted failure")
+ finally:
+ second_openoffice.stop()
+
+ self.openoffice.start()
+ second_openoffice = OpenOffice()
+ second_openoffice.loadSettings("localhost", 4091,
+ self.working_path + "_",
+ self.virtual_display_id,
+ self.office_binary_path,
+ self.uno_path)
+ try:
+ second_openoffice.start()
+ try:
+ openoffice_process = Process(self.openoffice.pid())
+ connection = openoffice_process.get_connections()[0]
+ self.assertEquals(connection.local_address[1], 4090)
+ openoffice_process = Process(second_openoffice.pid())
+ connection = openoffice_process.get_connections()[0]
+ self.assertEquals(connection.local_address[1], 4091)
+ except AccessDenied:
+ self.fail("Access get_connections() function should be allowed")
+ finally:
+ second_openoffice.stop()
+
+ if not self.openoffice.status():
+ self.openoffice.start()
+ second_openoffice = OpenOffice()
+ second_openoffice.loadSettings("localhost", 40900,
+ self.working_path + "_",
+ self.virtual_display_id,
+ self.office_binary_path,
+ self.uno_path)
+ second_openoffice.start()
+
+ third_openoffice = OpenOffice()
+ third_openoffice.loadSettings("localhost", 40900,
+ self.working_path + "_",
+ self.virtual_display_id,
+ self.office_binary_path,
+ self.uno_path)
+
+ try:
+ third_openoffice.start()
+ try:
+ openoffice_process = Process(self.openoffice.pid())
+ connection = openoffice_process.get_connections()[0]
+ self.assertEquals(connection.local_address[1], 4090)
+ openoffice_process = Process(second_openoffice.pid())
+ openoffice_process.get_connections()
+ self.fail("Access get_connections() function should fails")
+ except AccessDenied:
+ self.assertTrue("Excepted failure")
+ finally:
+ second_openoffice.stop()
+ third_openoffice.stop()
+
def test_suite():
return make_suite(TestOpenOffice)
More information about the Erp5-report
mailing list