From 6319a737b8e0b9351dd162b613310573b7ad52ce Mon Sep 17 00:00:00 2001 From: Sergei Antipov Date: Thu, 15 Feb 2018 15:41:55 +0700 Subject: [PATCH] Exception handling compatible with Python 3.x --- library/mongodb_replication.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/mongodb_replication.py b/library/mongodb_replication.py index 527e7f6..de58807 100644 --- a/library/mongodb_replication.py +++ b/library/mongodb_replication.py @@ -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)