mongodb_user: Ensure to close database connection (closes #59353) (#65665)

This commit is contained in:
Lujeni 2020-02-15 14:10:27 +00:00 committed by GitHub
parent c9b38bd74e
commit 25181e1b70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -424,7 +424,11 @@ def main():
user_add(module, client, db_name, user, password, roles) user_add(module, client, db_name, user, password, roles)
except Exception as e: except Exception as e:
module.fail_json(msg='Unable to add or update user: %s' % to_native(e), exception=traceback.format_exc()) module.fail_json(msg='Unable to add or update user: %s' % to_native(e), exception=traceback.format_exc())
finally:
try:
client.close()
except Exception:
pass
# Here we can check password change if mongo provide a query for that : https://jira.mongodb.org/browse/SERVER-22848 # Here we can check password change if mongo provide a query for that : https://jira.mongodb.org/browse/SERVER-22848
# newuinfo = user_find(client, user, db_name) # newuinfo = user_find(client, user, db_name)
# if uinfo['role'] == newuinfo['role'] and CheckPasswordHere: # if uinfo['role'] == newuinfo['role'] and CheckPasswordHere:
@ -435,7 +439,11 @@ def main():
user_remove(module, client, db_name, user) user_remove(module, client, db_name, user)
except Exception as e: except Exception as e:
module.fail_json(msg='Unable to remove user: %s' % to_native(e), exception=traceback.format_exc()) module.fail_json(msg='Unable to remove user: %s' % to_native(e), exception=traceback.format_exc())
finally:
try:
client.close()
except Exception:
pass
module.exit_json(changed=True, user=user) module.exit_json(changed=True, user=user)