Exception handling compatible with Python 3.x

This commit is contained in:
Sergei Antipov 2018-02-15 15:41:55 +07:00
parent 47d5b8e5b5
commit 6319a737b8
1 changed files with 6 additions and 6 deletions

View File

@ -236,7 +236,7 @@ def add_host(module, client, host_name, host_port, host_type, timeout=180, **kwa
cfg['members'].append(new_host)
admin_db.command('replSetReconfig', cfg)
return
except (OperationFailure, AutoReconnect), e:
except (OperationFailure, AutoReconnect) as e:
timeout = timeout - 5
if timeout <= 0:
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:
fail_msg = "couldn't find member with hostname: {0} in replica set members list".format(host_name)
module.fail_json(msg=fail_msg)
except (OperationFailure, AutoReconnect), e:
except (OperationFailure, AutoReconnect) as e:
timeout = timeout - 5
if timeout <= 0:
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)
replica_set_created = True
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))
except ConnectionFailure, e:
except ConnectionFailure as e:
module.fail_json(msg='unable to connect to database: %s' % str(e))
check_compatibility(module, client)
@ -394,13 +394,13 @@ def main():
priority = float(module.params['priority']),
slave_delay = module.params['slave_delay'],
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))
elif state == 'absent':
try:
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.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)