Skip to content

Commit 6dd0a0d

Browse files
author
Sergei Antipov
committed
Added compatibility check for Pymongo
1 parent 3dfa06c commit 6dd0a0d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/mongodb_replication.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@
146146
# =========================================
147147
# MongoDB module specific support methods.
148148
#
149+
def check_compatibility(module, client):
150+
srv_info = client.server_info()
151+
if LooseVersion(srv_info['version']) >= LooseVersion('3.0') and LooseVersion(PyMongoVersion) <= LooseVersion('3.0'):
152+
module.fail_json(msg=' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)')
153+
elif LooseVersion(srv_info['version']) >= LooseVersion('2.6') and LooseVersion(PyMongoVersion) <= LooseVersion('2.7'):
154+
module.fail_json(msg=' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)')
155+
elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
156+
module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)')
149157

150158
def check_members(state, module, client, host_name, host_port, host_type):
151159
admin_db = client['admin']
@@ -331,6 +339,7 @@ def main():
331339
module.fail_json(msg='replica_set parameter is required')
332340
else:
333341
client = MongoReplicaSetClient(login_host, int(login_port), replicaSet=replica_set, ssl=ssl)
342+
check_compatibility(module, client)
334343

335344
authenticate(client, login_user, login_password)
336345

@@ -339,6 +348,7 @@ def main():
339348
except ConfigurationError:
340349
try:
341350
client = MongoClient(login_host, int(login_port), ssl=ssl)
351+
check_compatibility(module, client)
342352
authenticate(client, login_user, login_password)
343353
if state == 'present':
344354
new_host = { '_id': 0, 'host': "{0}:{1}".format(host_name, host_port) }

0 commit comments

Comments
 (0)