Remove deprecated get_exception API

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2017-12-26 08:33:21 +05:30
committed by Brian Coca
parent caefe31125
commit 6bd0fbb63c
42 changed files with 284 additions and 409 deletions

View File

@@ -96,7 +96,8 @@ EXAMPLES = """
import os
import tempfile
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
try:
from passlib.apache import HtpasswdFile, htpasswd_context
from passlib.context import CryptContext
@@ -262,14 +263,9 @@ def main():
check_file_attrs(module, changed, msg)
module.exit_json(msg=msg, changed=changed)
except Exception:
e = get_exception()
module.fail_json(msg=str(e))
except Exception as e:
module.fail_json(msg=to_native(e))
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__':
main()

View File

@@ -276,7 +276,6 @@ state:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url, url_argument_spec
from ansible.module_utils._text import to_native
@@ -325,8 +324,7 @@ class JenkinsPlugin(object):
# Parse the JSON data
try:
json_data = json.loads(to_native(r.read()))
except Exception:
e = get_exception()
except Exception as e:
self.module.fail_json(
msg="Cannot parse %s JSON data." % what,
details=to_native(e))
@@ -350,8 +348,7 @@ class JenkinsPlugin(object):
if info['status'] != 200:
self.module.fail_json(msg=msg_status, details=info['msg'])
except Exception:
e = get_exception()
except Exception as e:
self.module.fail_json(msg=msg_exception, details=to_native(e))
return response
@@ -500,11 +497,10 @@ class JenkinsPlugin(object):
try:
sha1_old = hashlib.sha1(open(plugin_file, 'rb').read())
except Exception:
e = get_exception()
except Exception as e:
self.module.fail_json(
msg="Cannot calculate SHA1 of the old plugin.",
details=e.message)
details=to_native(e))
sha1sum_old = base64.b64encode(sha1_old.digest())
@@ -567,8 +563,7 @@ class JenkinsPlugin(object):
try:
os.close(update_fd)
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(
msg="Cannot close the tmp updates file %s." % updates_file,
details=to_native(e))
@@ -576,8 +571,7 @@ class JenkinsPlugin(object):
# Open the updates file
try:
f = open(updates_file)
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(
msg="Cannot open temporal updates file.",
details=to_native(e))
@@ -588,11 +582,10 @@ class JenkinsPlugin(object):
if i == 1:
try:
data = json.loads(line)
except Exception:
e = get_exception()
except Exception as e:
self.module.fail_json(
msg="Cannot load JSON data from the tmp updates file.",
details=e.message)
details=to_native(e))
break
@@ -604,11 +597,10 @@ class JenkinsPlugin(object):
if not os.path.isdir(updates_dir):
try:
os.makedirs(updates_dir, int('0700', 8))
except OSError:
e = get_exception()
except OSError as e:
self.module.fail_json(
msg="Cannot create temporal directory.",
details=e.message)
details=to_native(e))
self.module.atomic_move(updates_file, updates_file_orig)
@@ -639,8 +631,7 @@ class JenkinsPlugin(object):
try:
os.close(tmp_f_fd)
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(
msg='Cannot close the temporal plugin file %s.' % tmp_f,
details=to_native(e))
@@ -766,8 +757,7 @@ def main():
# Convert timeout to float
try:
module.params['timeout'] = float(module.params['timeout'])
except ValueError:
e = get_exception()
except ValueError as e:
module.fail_json(
msg='Cannot convert %s to float.' % module.params['timeout'],
details=to_native(e))

View File

@@ -117,7 +117,8 @@ EXAMPLES = '''
RETURN = '''# '''
from os import getenv
from os.path import isfile
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
try:
from taiga import TaigaAPI
from taiga.exceptions import TaigaException
@@ -235,9 +236,8 @@ def manage_issue(module, taiga_host, project_name, issue_subject, issue_priority
# More than 1 matching issue
return (False, changed, "More than one issue with subject %s in project %s" % (issue_subject, project_name), {})
except TaigaException:
exc = get_exception()
msg = "An exception happened: %s" % exc
except TaigaException as exc:
msg = "An exception happened: %s" % to_native(exc)
return (False, changed, msg, {})
@@ -307,8 +307,5 @@ def main():
module.fail_json(msg=msg)
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__':
main()