mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Include error exception in AnsibleError
- Use to_native instead of str Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
cce133b14f
commit
f9b836a901
5 changed files with 11 additions and 9 deletions
|
@ -43,7 +43,7 @@ from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils.six.moves import input
|
from ansible.module_utils.six.moves import input
|
||||||
from ansible.plugins.connection import ConnectionBase
|
from ansible.plugins.connection import ConnectionBase
|
||||||
from ansible.utils.path import makedirs_safe
|
from ansible.utils.path import makedirs_safe
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes, to_native
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -376,7 +376,7 @@ class Connection(ConnectionBase):
|
||||||
try:
|
try:
|
||||||
self.sftp = self._connect_sftp()
|
self.sftp = self._connect_sftp()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError("failed to open a SFTP connection (%s)", e)
|
raise AnsibleError("failed to open a SFTP connection (%s)" % to_native(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.sftp.get(to_bytes(in_path, errors='surrogate_or_strict'), to_bytes(out_path, errors='surrogate_or_strict'))
|
self.sftp.get(to_bytes(in_path, errors='surrogate_or_strict'), to_bytes(out_path, errors='surrogate_or_strict'))
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Connection(ConnectionBase):
|
||||||
def _search_executable(executable):
|
def _search_executable(executable):
|
||||||
cmd = distutils.spawn.find_executable(executable)
|
cmd = distutils.spawn.find_executable(executable)
|
||||||
if not cmd:
|
if not cmd:
|
||||||
raise AnsibleError("%s command not found in PATH") % executable
|
raise AnsibleError("%s command not found in PATH" % executable)
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def list_zones(self):
|
def list_zones(self):
|
||||||
|
|
|
@ -19,6 +19,7 @@ __metaclass__ = type
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -146,7 +147,7 @@ class LookupModule(LookupBase):
|
||||||
nsaddr = dns.resolver.query(ns)[0].address
|
nsaddr = dns.resolver.query(ns)[0].address
|
||||||
nameservers.append(nsaddr)
|
nameservers.append(nsaddr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError("dns lookup NS: ", str(e))
|
raise AnsibleError("dns lookup NS: %s" % to_native(e))
|
||||||
myres.nameservers = nameservers
|
myres.nameservers = nameservers
|
||||||
continue
|
continue
|
||||||
if '=' in t:
|
if '=' in t:
|
||||||
|
@ -163,7 +164,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
rdclass = dns.rdataclass.from_text(arg)
|
rdclass = dns.rdataclass.from_text(arg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise errors.AnsibleError("dns lookup illegal CLASS: ", str(e))
|
raise AnsibleError("dns lookup illegal CLASS: %s" % to_native(e))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ class LookupModule(LookupBase):
|
||||||
except dns.exception.SyntaxError:
|
except dns.exception.SyntaxError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError("dns.reversename unhandled exception", str(e))
|
raise AnsibleError("dns.reversename unhandled exception %s" % to_native(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
answers = myres.query(domain, qtype, rdclass=rdclass)
|
answers = myres.query(domain, qtype, rdclass=rdclass)
|
||||||
|
@ -216,6 +217,6 @@ class LookupModule(LookupBase):
|
||||||
except dns.resolver.Timeout:
|
except dns.resolver.Timeout:
|
||||||
ret.append('')
|
ret.append('')
|
||||||
except dns.exception.DNSException as e:
|
except dns.exception.DNSException as e:
|
||||||
raise AnsibleError("dns.resolver unhandled exception", e)
|
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -27,6 +27,7 @@ except ImportError:
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
# ==============================================================
|
# ==============================================================
|
||||||
# DNSTXT: DNS TXT records
|
# DNSTXT: DNS TXT records
|
||||||
|
@ -57,7 +58,7 @@ class LookupModule(LookupBase):
|
||||||
except dns.resolver.Timeout:
|
except dns.resolver.Timeout:
|
||||||
string = ''
|
string = ''
|
||||||
except DNSException as e:
|
except DNSException as e:
|
||||||
raise AnsibleError("dns.resolver unhandled exception", e)
|
raise AnsibleError("dns.resolver unhandled exception %s" % to_native(e))
|
||||||
|
|
||||||
ret.append(''.join(string))
|
ret.append(''.join(string))
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ class LookupModule(LookupBase):
|
||||||
yield formatted
|
yield formatted
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
raise AnsibleError(
|
raise AnsibleError(
|
||||||
"problem formatting %r with %r" % self.format
|
"problem formatting %r with %r" % (i, self.format)
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self, terms, variables, **kwargs):
|
def run(self, terms, variables, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue