Merge "Require mongodb >= 2.2 or fail misserably"

This commit is contained in:
Jenkins 2014-08-04 20:07:04 +00:00 committed by Gerrit Code Review
commit c8cc524245
2 changed files with 21 additions and 0 deletions

View File

@ -151,6 +151,21 @@ class MongodbDriverTest(MongodbSetupMixin, testing.TestBase):
self.assertThat(db.name, matchers.StartsWith( self.assertThat(db.name, matchers.StartsWith(
driver.mongodb_conf.database)) driver.mongodb_conf.database))
def test_version_match(self):
cache = oslo_cache.get_cache()
with mock.patch('pymongo.MongoClient.server_info') as info:
info.return_value = {'version': '2.1'}
self.assertRaises(RuntimeError, mongodb.DataDriver,
self.conf, cache)
info.return_value = {'version': '2.11'}
try:
mongodb.DataDriver(self.conf, cache)
except RuntimeError:
self.fail('version match failed')
@testing.requires_mongodb @testing.requires_mongodb
class MongodbQueueTests(MongodbSetupMixin, base.QueueControllerTest): class MongodbQueueTests(MongodbSetupMixin, base.QueueControllerTest):

View File

@ -21,6 +21,7 @@ import pymongo
import pymongo.errors import pymongo.errors
from zaqar.common import decorators from zaqar.common import decorators
from zaqar.i18n import _
from zaqar.openstack.common import log as logging from zaqar.openstack.common import log as logging
from zaqar.queues import storage from zaqar.queues import storage
from zaqar.queues.storage.mongodb import controllers from zaqar.queues.storage.mongodb import controllers
@ -81,6 +82,11 @@ class DataDriver(storage.DataDriverBase):
group=options.MONGODB_GROUP) group=options.MONGODB_GROUP)
self.mongodb_conf = self.conf[options.MONGODB_GROUP] self.mongodb_conf = self.conf[options.MONGODB_GROUP]
server_version = self.connection.server_info()['version']
if tuple(map(int, server_version.split('.'))) < (2, 2):
raise RuntimeError(_('The mongodb driver requires mongodb>=2.2, '
'%s found') % server_version)
def is_alive(self): def is_alive(self):
try: try:
# NOTE(zyuan): Requires admin access to mongodb # NOTE(zyuan): Requires admin access to mongodb