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
commit 6bd0fbb63c
42 changed files with 284 additions and 409 deletions

View file

@ -252,7 +252,6 @@ import sys
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_bytes, to_native
from ansible.module_utils.urls import fetch_url
@ -588,9 +587,8 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated
# to install so they're all done in one shot
deps_to_install.extend(pkg.missing_deps)
except Exception:
e = get_exception()
m.fail_json(msg="Unable to install package: %s" % str(e))
except Exception as e:
m.fail_json(msg="Unable to install package: %s" % to_native(e))
# and add this deb to the list of packages to install
pkgs_to_install.append(deb_file)
@ -805,9 +803,8 @@ def download(module, deb):
f.write(data)
f.close()
deb = package
except Exception:
e = get_exception()
module.fail_json(msg="Failure downloading %s, %s" % (deb, e))
except Exception as e:
module.fail_json(msg="Failure downloading %s, %s" % (deb, to_native(e)))
return deb
@ -843,8 +840,7 @@ def get_cache(module):
cache = None
try:
cache = apt.Cache()
except SystemError:
e = get_exception()
except SystemError as e:
if '/var/lib/apt/lists/' in str(e).lower():
# update cache until files are fixed or retries exceeded
retries = 0

View file

@ -107,7 +107,11 @@ import os
import re
import sys
import tempfile
import json
# import module snippets
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_native
try:
import apt
import apt_pkg
@ -292,9 +296,8 @@ class SourcesList(object):
try:
f.write(line)
except IOError:
err = get_exception()
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
except IOError as err:
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, to_native(err)))
self.module.atomic_move(tmp_path, filename)
# allow the user to override the default mode
@ -510,9 +513,8 @@ def main():
sourceslist.add_source(repo)
elif state == 'absent':
sourceslist.remove_source(repo)
except InvalidSource:
err = get_exception()
module.fail_json(msg='Invalid repository string: %s' % unicode(err))
except InvalidSource as err:
module.fail_json(msg='Invalid repository string: %s' % to_native(err))
sources_after = sourceslist.dump()
changed = sources_before != sources_after
@ -533,15 +535,11 @@ def main():
if update_cache:
cache = apt.Cache()
cache.update()
except OSError:
err = get_exception()
module.fail_json(msg=unicode(err))
except OSError as err:
module.fail_json(msg=to_native(err))
module.exit_json(changed=changed, repo=repo, state=state, diff=diff)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__':
main()

View file

@ -448,7 +448,7 @@ state:
import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_native
from ansible.module_utils.six.moves import configparser
@ -566,32 +566,29 @@ class YumRepo(object):
# Write data into the file
try:
fd = open(self.params['dest'], 'w')
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(
msg="Cannot open repo file %s." % self.params['dest'],
details=str(e))
details=to_native(e))
self.repofile.write(fd)
try:
fd.close()
except IOError:
e = get_exception()
except IOError as e:
self.module.fail_json(
msg="Cannot write repo file %s." % self.params['dest'],
details=str(e))
details=to_native(e))
else:
# Remove the file if there are not repos
try:
os.remove(self.params['dest'])
except OSError:
e = get_exception()
except OSError as e:
self.module.fail_json(
msg=(
"Cannot remove empty repo file %s." %
self.params['dest']),
details=str(e))
details=to_native(e))
def remove(self):
# Remove section if exists