From e30049d113ed281e17079e315d6924e49ebb2970 Mon Sep 17 00:00:00 2001 From: Chris Weber Date: Thu, 2 Jun 2016 11:58:38 -0700 Subject: [PATCH] Fixed exceptions to use python 2.4 helper function and added import also works on python 3 (#2363) --- .../web_infrastructure/deploy_helper.py | 9 ++++++--- .../web_infrastructure/ejabberd_user.py | 19 ++++++++++++------- .../modules/extras/web_infrastructure/jira.py | 10 +++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/extras/web_infrastructure/deploy_helper.py b/lib/ansible/modules/extras/web_infrastructure/deploy_helper.py index ebf5b54a8bd..b956e38d260 100644 --- a/lib/ansible/modules/extras/web_infrastructure/deploy_helper.py +++ b/lib/ansible/modules/extras/web_infrastructure/deploy_helper.py @@ -226,6 +226,9 @@ procedure to remove it during cleanup. - debug: var=deploy_helper ''' +# import module snippets +from ansible.module_utils.basic import * +from ansible.module_utils.pycompat24 import get_exception class DeployHelper(object): @@ -282,7 +285,8 @@ class DeployHelper(object): if not self.module.check_mode: try: shutil.rmtree(path, ignore_errors=False) - except Exception, e: + except Exception: + e = get_exception() self.module.fail_json(msg="rmtree failed: %s" % str(e)) return True @@ -468,8 +472,7 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/extras/web_infrastructure/ejabberd_user.py b/lib/ansible/modules/extras/web_infrastructure/ejabberd_user.py index bf86806ad52..85e5eda8e5f 100644 --- a/lib/ansible/modules/extras/web_infrastructure/ejabberd_user.py +++ b/lib/ansible/modules/extras/web_infrastructure/ejabberd_user.py @@ -68,6 +68,8 @@ Example playbook entries using the ejabberd_user module to manage users state. action: ejabberd_user username=test host=server state=absent ''' import syslog +from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.basic import * class EjabberdUserException(Exception): """ Base exeption for EjabberdUser class object """ @@ -98,7 +100,8 @@ class EjabberdUser(object): try: options = [self.user, self.host, self.pwd] (rc, out, err) = self.run_command('check_password', options) - except EjabberdUserException, e: + except EjabberdUserException: + e = get_exception() (rc, out, err) = (1, None, "required attribute(s) missing") return rc @@ -111,7 +114,8 @@ class EjabberdUser(object): try: options = [self.user, self.host] (rc, out, err) = self.run_command('check_account', options) - except EjabberdUserException, e: + except EjabberdUserException: + e = get_exception() (rc, out, err) = (1, None, "required attribute(s) missing") return not bool(int(rc)) @@ -139,7 +143,8 @@ class EjabberdUser(object): try: options = [self.user, self.host, self.pwd] (rc, out, err) = self.run_command('change_password', options) - except EjabberdUserException, e: + except EjabberdUserException: + e = get_exception() (rc, out, err) = (1, None, "required attribute(s) missing") return (rc, out, err) @@ -150,7 +155,8 @@ class EjabberdUser(object): try: options = [self.user, self.host, self.pwd] (rc, out, err) = self.run_command('register', options) - except EjabberdUserException, e: + except EjabberdUserException: + e = get_exception() (rc, out, err) = (1, None, "required attribute(s) missing") return (rc, out, err) @@ -160,7 +166,8 @@ class EjabberdUser(object): try: options = [self.user, self.host] (rc, out, err) = self.run_command('unregister', options) - except EjabberdUserException, e: + except EjabberdUserException: + e = get_exception() (rc, out, err) = (1, None, "required attribute(s) missing") return (rc, out, err) @@ -209,6 +216,4 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * main() diff --git a/lib/ansible/modules/extras/web_infrastructure/jira.py b/lib/ansible/modules/extras/web_infrastructure/jira.py index 42d5e092974..0053e0a32cd 100755 --- a/lib/ansible/modules/extras/web_infrastructure/jira.py +++ b/lib/ansible/modules/extras/web_infrastructure/jira.py @@ -171,6 +171,10 @@ except ImportError: import base64 +from ansible.module_utils.basic import * +from ansible.module_utils.urls import * +from ansible.module_utils.pycompat24 import get_exception + def request(url, user, passwd, data=None, method=None): if data: data = json.dumps(data) @@ -343,13 +347,13 @@ def main(): ret = method(restbase, user, passwd, module.params) - except Exception, e: + except Exception: + e = get_exception() return module.fail_json(msg=e.message) module.exit_json(changed=True, meta=ret) -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + main()