From 0c75df4bf3784eae08f41c176bbaab44c6d510a7 Mon Sep 17 00:00:00 2001 From: Petr Spacek Date: Tue, 17 May 2016 17:06:32 +0200 Subject: Move check_zone_overlap() from ipapython.ipautil to ipapython.dnsutil This is preparatory work to avoid (future) cyclic import between ipapython.dnsutil and ipapython.ipautil. https://fedorahosted.org/freeipa/ticket/5710 Reviewed-By: Martin Basti --- ipapython/dnsutil.py | 35 +++++++++++++++++++++++++++++++++++ ipapython/ipautil.py | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) (limited to 'ipapython') diff --git a/ipapython/dnsutil.py b/ipapython/dnsutil.py index 240b7c9cd..6287e3eef 100644 --- a/ipapython/dnsutil.py +++ b/ipapython/dnsutil.py @@ -19,6 +19,7 @@ import dns.name import dns.exception +import dns.resolver import copy import six @@ -228,3 +229,37 @@ def inside_auto_empty_zone(name): if name.is_subdomain(aez): return True return False + + +def check_zone_overlap(zone, raise_on_error=True): + root_logger.info("Checking DNS domain %s, please wait ..." % zone) + if not isinstance(zone, DNSName): + zone = DNSName(zone).make_absolute() + + # automatic empty zones always exist so checking them is pointless, + # do not report them to avoid meaningless error messages + if is_auto_empty_zone(zone): + return + + try: + containing_zone = dns.resolver.zone_for_name(zone) + except dns.exception.DNSException as e: + msg = ("DNS check for domain %s failed: %s." % (zone, e)) + if raise_on_error: + raise ValueError(msg) + else: + root_logger.warning(msg) + return + + if containing_zone == zone: + try: + ns = [ans.to_text() for ans in dns.resolver.query(zone, 'NS')] + except dns.exception.DNSException as e: + root_logger.debug("Failed to resolve nameserver(s) for domain" + " {0}: {1}".format(zone, e)) + ns = [] + + msg = u"DNS zone {0} already exists in DNS".format(zone) + if ns: + msg += u" and is handled by server(s): {0}".format(', '.join(ns)) + raise ValueError(msg) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index d4c8e8b82..34e05d366 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -53,7 +53,6 @@ from ipapython.ipa_log_manager import root_logger from ipapython import config from ipaplatform.paths import paths from ipapython.dn import DN -from ipapython.dnsutil import DNSName, is_auto_empty_zone SHARE_DIR = paths.USR_SHARE_IPA_DIR PLUGINS_SHARE_DIR = paths.IPA_PLUGINS @@ -1018,40 +1017,6 @@ def reverse_record_exists(ip_address): return True -def check_zone_overlap(zone, raise_on_error=True): - root_logger.info("Checking DNS domain %s, please wait ..." % zone) - if not isinstance(zone, DNSName): - zone = DNSName(zone).make_absolute() - - # automatic empty zones always exist so checking them is pointless, - # do not report them to avoid meaningless error messages - if is_auto_empty_zone(zone): - return - - try: - containing_zone = resolver.zone_for_name(zone) - except DNSException as e: - msg = ("DNS check for domain %s failed: %s." % (zone, e)) - if raise_on_error: - raise ValueError(msg) - else: - root_logger.warning(msg) - return - - if containing_zone == zone: - try: - ns = [ans.to_text() for ans in resolver.query(zone, 'NS')] - except DNSException as e: - root_logger.debug("Failed to resolve nameserver(s) for domain" - " {0}: {1}".format(zone, e)) - ns = [] - - msg = u"DNS zone {0} already exists in DNS".format(zone) - if ns: - msg += u" and is handled by server(s): {0}".format(', '.join(ns)) - raise ValueError(msg) - - def config_replace_variables(filepath, replacevars=dict(), appendvars=dict()): """ Take a key=value based configuration file, and write new version -- cgit