From 67949a7870559e3045a7637b268d6d8462bc994d Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Mon, 4 Aug 2014 16:51:27 +0200 Subject: [PATCH] Require mongodb >= 2.2 or fail misserably The patch adds a minimum requirement for mongodb. This will provide a useful error message to users when the installed mongodb version doesn't match the minimum required one. Change-Id: Iff8bb1645e7276529230da58c408552bebd8647a --- tests/unit/queues/storage/test_impl_mongodb.py | 15 +++++++++++++++ zaqar/queues/storage/mongodb/driver.py | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/tests/unit/queues/storage/test_impl_mongodb.py b/tests/unit/queues/storage/test_impl_mongodb.py index 6c1242b7a..634fe1c1b 100644 --- a/tests/unit/queues/storage/test_impl_mongodb.py +++ b/tests/unit/queues/storage/test_impl_mongodb.py @@ -151,6 +151,21 @@ class MongodbDriverTest(MongodbSetupMixin, testing.TestBase): self.assertThat(db.name, matchers.StartsWith( 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 class MongodbQueueTests(MongodbSetupMixin, base.QueueControllerTest): diff --git a/zaqar/queues/storage/mongodb/driver.py b/zaqar/queues/storage/mongodb/driver.py index 6274bece2..07dad570a 100644 --- a/zaqar/queues/storage/mongodb/driver.py +++ b/zaqar/queues/storage/mongodb/driver.py @@ -21,6 +21,7 @@ import pymongo import pymongo.errors from zaqar.common import decorators +from zaqar.i18n import _ from zaqar.openstack.common import log as logging from zaqar.queues import storage from zaqar.queues.storage.mongodb import controllers @@ -81,6 +82,11 @@ class DataDriver(storage.DataDriverBase): group=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): try: # NOTE(zyuan): Requires admin access to mongodb