Commit 9bfe70bd authored by Rafael Monnerat's avatar Rafael Monnerat

Create promise.cfg when during unit tests

 Create promise configuration on-the-fly with the configurations reusing
 existing API to get cloudooo, memcached and kumofs informations from
 environment.

 This approach allow us use erp5_promise alarms at any unit test to
 configure cloudooo, memcached and kumofs, instead implement ad-hoc
 configurations on tests afterSetup methods.
parent 851f3613
...@@ -19,6 +19,7 @@ import sys ...@@ -19,6 +19,7 @@ import sys
import time import time
import traceback import traceback
import urllib import urllib
import ConfigParser
from cStringIO import StringIO from cStringIO import StringIO
from cPickle import dumps from cPickle import dumps
from glob import glob from glob import glob
...@@ -263,6 +264,27 @@ def _getPersistentMemcachedServerDict(): ...@@ -263,6 +264,27 @@ def _getPersistentMemcachedServerDict():
port = os.environ.get('persistent_memcached_server_port', '12121') port = os.environ.get('persistent_memcached_server_port', '12121')
return dict(hostname=hostname, port=port) return dict(hostname=hostname, port=port)
def _createTestPromiseConfigurationFile(promise_path):
kumofs_url = "memcached://%(hostname)s:%(port)s/" % \
_getVolatileMemcachedServerDict()
memcached_url = "memcached://%(hostname)s:%(port)s/" % \
_getPersistentMemcachedServerDict()
cloudooo_url = "cloudooo://%(hostname)s:%(port)s/" % \
_getConversionServerDict()
promise_config = ConfigParser.RawConfigParser()
promise_config.add_section('external_service')
promise_config.set('external_service', 'cloudooo_url', cloudooo_url)
promise_config.set('external_service', 'memcached_url',memcached_url)
promise_config.set('external_service', 'kumofs_url', kumofs_url)
if os.environ.get('TEST_CA_PATH') is not None:
promise_config.add_section('portal_certificate_authority')
promise_config.set('portal_certificate_authority', 'certificate_authority_path',
os.environ['TEST_CA_PATH'])
promise_config.write(open(promise_path, 'w'))
def profile_if_environ(environment_var_name): def profile_if_environ(environment_var_name):
if int(os.environ.get(environment_var_name, 0)): if int(os.environ.get(environment_var_name, 0)):
def decorator(self, method): def decorator(self, method):
...@@ -928,6 +950,15 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -928,6 +950,15 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
""" """
return () return ()
def loadPromise(self):
""" Create promise configuration file and load it into configuration
"""
promise_path = os.path.join(instancehome, "promise.cfg")
ZopeTestCase._print('Adding Promise at %s...\n' % promise_path)
_createTestPromiseConfigurationFile(promise_path)
config.product_config["/%s" % self.getPortalName()] = \
{"promise_path": promise_path}
def _updateConnectionStrings(self): def _updateConnectionStrings(self):
"""Update connection strings with values passed by the testRunner """Update connection strings with values passed by the testRunner
""" """
...@@ -1088,6 +1119,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1088,6 +1119,7 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
self._setUpDummyMailHost() self._setUpDummyMailHost()
self.serverhost, self.serverport = self.startZServer(verbose=True) self.serverhost, self.serverport = self.startZServer(verbose=True)
self._registerNode(distributing=1, processing=1) self._registerNode(distributing=1, processing=1)
self.loadPromise()
self._updateConnectionStrings() self._updateConnectionStrings()
self._recreateCatalog() self._recreateCatalog()
......
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