Allow config of mongo test url using env variable

This adds a new ZAQAR_TEST_MONGODB_URL environment variable that you
can set before running tests, to not run them against the default
localhost:27017 instance.

Change-Id: Ic3dae5e92fbe87155ac95cc597535af2f5f94e3c
This commit is contained in:
Thomas Herve 2015-07-01 15:31:37 +02:00
parent 448159f3d4
commit 77ded9136f
6 changed files with 45 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import six
import testtools
from zaqar.common import configs
from zaqar.tests import helpers
class TestBase(testtools.TestCase):
@ -47,6 +48,8 @@ class TestBase(testtools.TestCase):
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
if self.config_file:
self.config_file = helpers.override_mongo_conf(
self.config_file, self)
self.conf = self.load_conf(self.config_file)
else:
self.conf = cfg.ConfigOpts()

View File

@ -55,5 +55,14 @@ Adding New Tests
messages/test_messages.py
claim/test_claims.py
Using a custom MongoDB instance
-------------------------------
If you need to run the tests against a non-default MongoDB installation, you
can set the ZAQAR_TEST_MONGODB_URL environemment variable. For example: ::
export ZAQAR_TEST_MONGODB_URL=mongodb://remote-server:27017
.. _README : https://github.com/openstack/zaqar/blob/master/README.rst
.. _requests : https://pypi.python.org/pypi/requests

View File

@ -29,6 +29,7 @@ from zaqar import tests as testing
from zaqar.tests.functional import config
from zaqar.tests.functional import helpers
from zaqar.tests.functional import http
from zaqar.tests import helpers as base_helpers
from zaqar.transport import base as transport_base
# TODO(flaper87): This is necessary to register,
# wsgi configs and won't be permanent. It'll be
@ -61,8 +62,11 @@ class FunctionalTestBase(testing.TestBase):
if not self.cfg.run_tests:
self.skipTest("Functional tests disabled")
self.mconf = self.load_conf(self.config_file or
self.cfg.zaqar.config)
config_file = self.config_file or self.cfg.zaqar.config
config_file = base_helpers.override_mongo_conf(config_file, self)
self.mconf = self.load_conf(config_file)
validator = validation.Validator(self.mconf)
self.limits = validator._limits_conf

View File

@ -40,7 +40,7 @@ class TestHealth(base.V1_1FunctionalTestBase):
# as pool node and the mongodb is working on gate successfully.
doc = helpers.create_pool_body(
weight=10,
uri="mongodb://localhost:27017",
uri=self.mconf['drivers:management_store:mongodb'].uri,
options=dict(database='zaqar_test_pooled_1')
)

View File

@ -16,6 +16,7 @@
import contextlib
import functools
import os
import tempfile
import uuid
import six
@ -254,3 +255,26 @@ def is_slow(condition=lambda self: True):
return wrapper
return decorator
def override_mongo_conf(conf_file, test):
test_mongo_url = os.environ.get('ZAQAR_TEST_MONGODB_URL')
if test_mongo_url:
parser = six.moves.configparser.ConfigParser()
parser.read(test.conf_path(conf_file))
sections = ['drivers:management_store:mongodb',
'drivers:message_store:mongodb']
for section in sections:
if not parser.has_section(section):
parser.add_section(section)
parser.set(section, 'uri', test_mongo_url)
fd, path = tempfile.mkstemp()
conf_fd = os.fdopen(fd, 'w')
try:
parser.write(conf_fd)
finally:
conf_fd.close()
test.addCleanup(os.remove, path)
return path
else:
return conf_file

View File

@ -17,6 +17,7 @@ from zaqar import bootstrap
from zaqar.common import errors
from zaqar.storage import pooling
from zaqar.tests import base
from zaqar.tests import helpers
from zaqar.transport import websocket
from zaqar.transport import wsgi
@ -24,6 +25,7 @@ from zaqar.transport import wsgi
class TestBootstrap(base.TestBase):
def _bootstrap(self, conf_file):
conf_file = helpers.override_mongo_conf(conf_file, self)
self.conf = self.load_conf(conf_file)
return bootstrap.Bootstrap(self.conf)