summaryrefslogtreecommitdiffstats
path: root/ipalib/util.py
diff options
context:
space:
mode:
authorPetr Spacek <pspacek@redhat.com>2016-05-17 17:28:36 +0200
committerMartin Basti <mbasti@redhat.com>2016-05-30 20:14:32 +0200
commit70794c7b1d001ce331d4a64c77d23abcc02c541e (patch)
tree457edeb05408201a251a165a3c871c7eeb42ccf0 /ipalib/util.py
parentdc405005f537cf278fd6ddfe6b87060bd13d9a67 (diff)
downloadfreeipa-70794c7b1d001ce331d4a64c77d23abcc02c541e.tar.gz
freeipa-70794c7b1d001ce331d4a64c77d23abcc02c541e.tar.xz
freeipa-70794c7b1d001ce331d4a64c77d23abcc02c541e.zip
Turn verify_host_resolvable() into a wrapper around ipapython.dnsutil
The code was duplicate and less generic anyway. As a side-effect I had to re-wrap dns.exception.DNSException into a PublicError so it can be displayed to the user. DNSError is now a super class for other DNS-related errors. Errors from DNS resolver are re-raised as DNSResolverError. https://fedorahosted.org/freeipa/ticket/5710 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipalib/util.py')
-rw-r--r--ipalib/util.py32
1 files changed, 7 insertions, 25 deletions
diff --git a/ipalib/util.py b/ipalib/util.py
index 7d3a502e4..3fb46b298 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -42,8 +42,8 @@ from ipalib.text import _
from ipapython.ssh import SSHPublicKey
from ipapython.dn import DN, RDN
from ipapython.dnsutil import DNSName
+from ipapython.dnsutil import resolve_ip_addresses
from ipapython.graph import Graph
-from ipapython.ipa_log_manager import root_logger
if six.PY3:
unicode = str
@@ -67,30 +67,12 @@ def json_serialize(obj):
def verify_host_resolvable(fqdn):
- """
- See if the hostname has a DNS A/AAAA record.
- """
- if not isinstance(fqdn, DNSName):
- fqdn = DNSName(fqdn)
-
- fqdn = fqdn.make_absolute()
- for rdtype in ('A', 'AAAA'):
- try:
- answers = resolver.query(fqdn, rdtype)
- root_logger.debug(
- 'IPA: found %d %s records for %s: %s' % (len(answers),
- rdtype, fqdn, ' '.join(str(answer) for answer in answers))
- )
- except DNSException:
- root_logger.debug(
- 'IPA: DNS %s record lookup failed for %s' %
- (rdtype, fqdn)
- )
- continue
- else:
- return
- # dns lookup failed in both tries
- raise errors.DNSNotARecordError()
+ try:
+ if not resolve_ip_addresses(fqdn):
+ raise errors.DNSNotARecordError(hostname=fqdn)
+ except dns.exception.DNSException as ex:
+ # wrap DNSException in a PublicError
+ raise errors.DNSResolverError(exception=ex)
def has_soa_or_ns_record(domain):