Change listDatabases exception handling (#53605)
This commit is contained in:
parent
3117900b1e
commit
8d00ccf60f
1 changed files with 6 additions and 4 deletions
|
@ -376,11 +376,13 @@ def main():
|
||||||
try:
|
try:
|
||||||
client['admin'].command('listDatabases', 1.0) # if this throws an error we need to authenticate
|
client['admin'].command('listDatabases', 1.0) # if this throws an error we need to authenticate
|
||||||
except Exception as excep:
|
except Exception as excep:
|
||||||
if "not authorized on" not in str(excep) and "command listDatabases requires authentication" not in str(excep):
|
if "not authorized on" in str(excep) or "command listDatabases requires authentication" in str(excep):
|
||||||
raise excep
|
if login_user is not None and login_password is not None:
|
||||||
if login_user is None or login_password is None:
|
|
||||||
raise excep
|
|
||||||
client.admin.authenticate(login_user, login_password, source=login_database)
|
client.admin.authenticate(login_user, login_password, source=login_database)
|
||||||
|
else:
|
||||||
|
raise excep
|
||||||
|
else:
|
||||||
|
raise excep
|
||||||
|
|
||||||
if len(replica_set) == 0:
|
if len(replica_set) == 0:
|
||||||
module.fail_json(msg="Parameter 'replica_set' must not be an empty string")
|
module.fail_json(msg="Parameter 'replica_set' must not be an empty string")
|
||||||
|
|
Loading…
Reference in a new issue