From 415c2d4591e8db4f5d382bf52afe238c1dc40bf8 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sat, 15 Oct 2016 17:21:01 +0200 Subject: [PATCH] Make sensu_check compile on python 3 (#3177) --- lib/ansible/modules/extras/monitoring/sensu_check.py | 7 +++++-- .../extras/test/utils/shippable/sanity-skip-python3.txt | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/monitoring/sensu_check.py b/lib/ansible/modules/extras/monitoring/sensu_check.py index 7cf3850966..dff8d19652 100644 --- a/lib/ansible/modules/extras/monitoring/sensu_check.py +++ b/lib/ansible/modules/extras/monitoring/sensu_check.py @@ -206,7 +206,8 @@ def sensu_check(module, path, name, state='present', backup=False): try: stream = open(path, 'r') config = json.load(stream) - except IOError, e: + except IOError: + e = get_exception() if e.errno is 2: # File not found, non-fatal if state == 'absent': reasons.append('file did not exist and state is `absent\'') @@ -327,7 +328,8 @@ def sensu_check(module, path, name, state='present', backup=False): try: stream = open(path, 'w') stream.write(json.dumps(config, indent=2) + '\n') - except IOError, e: + except IOError: + e = get_exception() module.fail_json(msg=str(e)) finally: if stream: @@ -381,4 +383,5 @@ def main(): module.exit_json(path=path, changed=changed, msg='OK', name=name, reasons=reasons) from ansible.module_utils.basic import * +from ansible.module_utils.pycompat24 import get_exception main() diff --git a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt index 1deede9a26..5e73527740 100644 --- a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt +++ b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt @@ -63,7 +63,6 @@ /monitoring/circonus_annotation.py /monitoring/datadog_monitor.py /monitoring/rollbar_deployment.py -/monitoring/sensu_check.py /monitoring/stackdriver.py /monitoring/zabbix_group.py /monitoring/zabbix_host.py