Merge "mongodb: Ignore suffix in server version"

This commit is contained in:
Zuul
2025-08-12 03:39:22 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 7 deletions

View File

@@ -86,7 +86,8 @@ class DataDriver(storage.DataDriverBase):
conn = self.connection
server_info = conn.server_info()['version']
self.server_version = tuple(map(int, server_info.split('.')))
version_str = server_info.split('-')[0]
self.server_version = tuple(map(int, version_str.split('.')))
if self.server_version < (2, 2):
raise RuntimeError(_('The mongodb driver requires mongodb>=2.2, '

View File

@@ -172,17 +172,37 @@ class MongodbDriverTest(MongodbSetupMixin, testing.TestBase):
with mock.patch('pymongo.MongoClient.server_info') as info:
info.return_value = {'version': '2.1'}
self.assertRaises(RuntimeError, mongodb.DataDriver,
self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.1.0'}
self.assertRaises(RuntimeError, mongodb.DataDriver,
self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.1.0-1.0'}
self.assertRaises(RuntimeError, mongodb.DataDriver,
self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.11'}
info.return_value = {'version': '2.2'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.2.0'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.2.0-1.0'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
try:
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
except RuntimeError:
self.fail('version match failed')
info.return_value = {'version': '2.10'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.10.0'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
info.return_value = {'version': '2.10.0-1.0'}
mongodb.DataDriver(self.conf, cache,
mongodb.ControlDriver(self.conf, cache))
def test_replicaset_or_mongos_needed(self):
cache = oslo_cache.get_cache(self.conf)