Skip to content

Commit

Permalink
Fixed problem with wrong pymongo package
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Antipov committed Nov 16, 2015
1 parent 94ebb6e commit 09ff5f9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions library/mongodb_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
# MongoDB module specific support methods.
#

def check_compatibility(module, client):
srv_info = client.server_info()
if LooseVersion(srv_info['version']) >= LooseVersion('3.0') and LooseVersion(PyMongoVersion) <= LooseVersion('3.0'):
module.fail_json(msg=' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)')
elif LooseVersion(srv_info['version']) >= LooseVersion('2.6') and LooseVersion(PyMongoVersion) <= LooseVersion('2.7'):
module.fail_json(msg=' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)')
elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)')

def user_find(client, user):
for mongo_user in client["admin"].system.users.find():
if mongo_user['user'] == user:
Expand All @@ -165,13 +174,6 @@ def user_add(module, client, db_name, user, password, roles):
db.add_user(user, password, None, roles=roles)
except OperationFailure, e:
err_msg = str(e)
srv_info = client.server_info()
if LooseVersion(srv_info['version']) >= LooseVersion('3.0') and LooseVersion(PyMongoVersion) <= LooseVersion('3.0'):
err_msg = err_msg + ' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)'
elif LooseVersion(srv_info['version']) >= LooseVersion('2.6') and LooseVersion(PyMongoVersion) <= LooseVersion('2.7'):
err_msg = err_msg + ' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)'
elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
err_msg = err_msg + ' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)'
module.fail_json(msg=err_msg)

def user_remove(module, client, db_name, user):
Expand Down Expand Up @@ -262,6 +264,8 @@ def main():
except ConnectionFailure, e:
module.fail_json(msg='unable to connect to database: %s' % str(e))

check_compatibility(module, client)

if state == 'present':
if password is None and update_password == 'always':
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')
Expand Down

0 comments on commit 09ff5f9

Please sign in to comment.