mirror of
https://github.com/status-im/ansible-role-mongodb.git
synced 2025-02-25 19:25:27 +00:00
Exception handling compatible with Python 3.x
This commit is contained in:
parent
47d5b8e5b5
commit
6319a737b8
@ -236,7 +236,7 @@ def add_host(module, client, host_name, host_port, host_type, timeout=180, **kwa
|
|||||||
cfg['members'].append(new_host)
|
cfg['members'].append(new_host)
|
||||||
admin_db.command('replSetReconfig', cfg)
|
admin_db.command('replSetReconfig', cfg)
|
||||||
return
|
return
|
||||||
except (OperationFailure, AutoReconnect), e:
|
except (OperationFailure, AutoReconnect) as e:
|
||||||
timeout = timeout - 5
|
timeout = timeout - 5
|
||||||
if timeout <= 0:
|
if timeout <= 0:
|
||||||
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
|
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
|
||||||
@ -265,7 +265,7 @@ def remove_host(module, client, host_name, timeout=180):
|
|||||||
else:
|
else:
|
||||||
fail_msg = "couldn't find member with hostname: {0} in replica set members list".format(host_name)
|
fail_msg = "couldn't find member with hostname: {0} in replica set members list".format(host_name)
|
||||||
module.fail_json(msg=fail_msg)
|
module.fail_json(msg=fail_msg)
|
||||||
except (OperationFailure, AutoReconnect), e:
|
except (OperationFailure, AutoReconnect) as e:
|
||||||
timeout = timeout - 5
|
timeout = timeout - 5
|
||||||
if timeout <= 0:
|
if timeout <= 0:
|
||||||
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
|
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
|
||||||
@ -374,9 +374,9 @@ def main():
|
|||||||
wait_for_ok_and_master(module, client)
|
wait_for_ok_and_master(module, client)
|
||||||
replica_set_created = True
|
replica_set_created = True
|
||||||
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
||||||
except OperationFailure, e:
|
except OperationFailure as e:
|
||||||
module.fail_json(msg='Unable to initiate replica set: %s' % str(e))
|
module.fail_json(msg='Unable to initiate replica set: %s' % str(e))
|
||||||
except ConnectionFailure, e:
|
except ConnectionFailure as e:
|
||||||
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
||||||
|
|
||||||
check_compatibility(module, client)
|
check_compatibility(module, client)
|
||||||
@ -394,13 +394,13 @@ def main():
|
|||||||
priority = float(module.params['priority']),
|
priority = float(module.params['priority']),
|
||||||
slave_delay = module.params['slave_delay'],
|
slave_delay = module.params['slave_delay'],
|
||||||
votes = module.params['votes'])
|
votes = module.params['votes'])
|
||||||
except OperationFailure, e:
|
except OperationFailure as e:
|
||||||
module.fail_json(msg='Unable to add new member to replica set: %s' % str(e))
|
module.fail_json(msg='Unable to add new member to replica set: %s' % str(e))
|
||||||
|
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
try:
|
try:
|
||||||
remove_host(module, client, host_name)
|
remove_host(module, client, host_name)
|
||||||
except OperationFailure, e:
|
except OperationFailure as e:
|
||||||
module.fail_json(msg='Unable to remove member of replica set: %s' % str(e))
|
module.fail_json(msg='Unable to remove member of replica set: %s' % str(e))
|
||||||
|
|
||||||
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user