Skip to content

Commit 6319a73

Browse files
committed
Exception handling compatible with Python 3.x
1 parent 47d5b8e commit 6319a73

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/mongodb_replication.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def add_host(module, client, host_name, host_port, host_type, timeout=180, **kwa
236236
cfg['members'].append(new_host)
237237
admin_db.command('replSetReconfig', cfg)
238238
return
239-
except (OperationFailure, AutoReconnect), e:
239+
except (OperationFailure, AutoReconnect) as e:
240240
timeout = timeout - 5
241241
if timeout <= 0:
242242
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):
265265
else:
266266
fail_msg = "couldn't find member with hostname: {0} in replica set members list".format(host_name)
267267
module.fail_json(msg=fail_msg)
268-
except (OperationFailure, AutoReconnect), e:
268+
except (OperationFailure, AutoReconnect) as e:
269269
timeout = timeout - 5
270270
if timeout <= 0:
271271
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
@@ -374,9 +374,9 @@ def main():
374374
wait_for_ok_and_master(module, client)
375375
replica_set_created = True
376376
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
377-
except OperationFailure, e:
377+
except OperationFailure as e:
378378
module.fail_json(msg='Unable to initiate replica set: %s' % str(e))
379-
except ConnectionFailure, e:
379+
except ConnectionFailure as e:
380380
module.fail_json(msg='unable to connect to database: %s' % str(e))
381381

382382
check_compatibility(module, client)
@@ -394,13 +394,13 @@ def main():
394394
priority = float(module.params['priority']),
395395
slave_delay = module.params['slave_delay'],
396396
votes = module.params['votes'])
397-
except OperationFailure, e:
397+
except OperationFailure as e:
398398
module.fail_json(msg='Unable to add new member to replica set: %s' % str(e))
399399

400400
elif state == 'absent':
401401
try:
402402
remove_host(module, client, host_name)
403-
except OperationFailure, e:
403+
except OperationFailure as e:
404404
module.fail_json(msg='Unable to remove member of replica set: %s' % str(e))
405405

406406
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)

0 commit comments

Comments
 (0)