|
|
2e9388 |
From 7623bc99813156ce11167ae429a756f920258151 Mon Sep 17 00:00:00 2001
|
|
|
2e9388 |
From: Martin Basti <mbasti@redhat.com>
|
|
|
2e9388 |
Date: Fri, 20 Nov 2015 11:53:06 +0100
|
|
|
2e9388 |
Subject: [PATCH] upgrade: fix migration of old dns forward zones
|
|
|
2e9388 |
|
|
|
2e9388 |
Plugins should call self.api not the global one during upgrade
|
|
|
2e9388 |
|
|
|
2e9388 |
https://fedorahosted.org/freeipa/ticket/5472
|
|
|
2e9388 |
|
|
|
2e9388 |
Reviewed-By: Petr Spacek <pspacek@redhat.com>
|
|
|
2e9388 |
---
|
|
|
2e9388 |
ipalib/plugins/dns.py | 51 +++++++++++++++++++++++++++------------------------
|
|
|
2e9388 |
1 file changed, 27 insertions(+), 24 deletions(-)
|
|
|
2e9388 |
|
|
|
2e9388 |
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
|
|
|
2e9388 |
index a3d562edb186682a872073e6c83a416b6a4cbc09..37a2c64cbacae5cc5626f17fac68848768af3242 100644
|
|
|
2e9388 |
--- a/ipalib/plugins/dns.py
|
|
|
2e9388 |
+++ b/ipalib/plugins/dns.py
|
|
|
2e9388 |
@@ -1735,7 +1735,7 @@ def _normalize_zone(zone):
|
|
|
2e9388 |
return zone
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
-def _get_auth_zone_ldap(name):
|
|
|
2e9388 |
+def _get_auth_zone_ldap(api, name):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
Find authoritative zone in LDAP for name. Only active zones are considered.
|
|
|
2e9388 |
:param name:
|
|
|
2e9388 |
@@ -1781,7 +1781,7 @@ def _get_auth_zone_ldap(name):
|
|
|
2e9388 |
return max(matched_auth_zones, key=len), truncated
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
-def _get_longest_match_ns_delegation_ldap(zone, name):
|
|
|
2e9388 |
+def _get_longest_match_ns_delegation_ldap(api, zone, name):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
Searches for deepest delegation for name in LDAP zone.
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -1857,7 +1857,7 @@ def _get_longest_match_ns_delegation_ldap(zone, name):
|
|
|
2e9388 |
return max(matched_records, key=len), truncated
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
-def _find_subtree_forward_zones_ldap(name, child_zones_only=False):
|
|
|
2e9388 |
+def _find_subtree_forward_zones_ldap(api, name, child_zones_only=False):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
Search for forwardzone <name> and all child forwardzones
|
|
|
2e9388 |
Filter: (|(*.<name>.)(<name>.))
|
|
|
2e9388 |
@@ -1911,7 +1911,7 @@ def _find_subtree_forward_zones_ldap(name, child_zones_only=False):
|
|
|
2e9388 |
return result, truncated
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
-def _get_zone_which_makes_fw_zone_ineffective(fwzonename):
|
|
|
2e9388 |
+def _get_zone_which_makes_fw_zone_ineffective(api, fwzonename):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
Check if forward zone is effective.
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -1936,12 +1936,12 @@ def _get_zone_which_makes_fw_zone_ineffective(fwzonename):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
assert isinstance(fwzonename, DNSName)
|
|
|
2e9388 |
|
|
|
2e9388 |
- auth_zone, truncated_zone = _get_auth_zone_ldap(fwzonename)
|
|
|
2e9388 |
+ auth_zone, truncated_zone = _get_auth_zone_ldap(api, fwzonename)
|
|
|
2e9388 |
if not auth_zone:
|
|
|
2e9388 |
return None, truncated_zone
|
|
|
2e9388 |
|
|
|
2e9388 |
delegation_record_name, truncated_ns =\
|
|
|
2e9388 |
- _get_longest_match_ns_delegation_ldap(auth_zone, fwzonename)
|
|
|
2e9388 |
+ _get_longest_match_ns_delegation_ldap(api, auth_zone, fwzonename)
|
|
|
2e9388 |
|
|
|
2e9388 |
truncated = truncated_ns or truncated_zone
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -1951,12 +1951,12 @@ def _get_zone_which_makes_fw_zone_ineffective(fwzonename):
|
|
|
2e9388 |
return auth_zone, truncated
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
-def _add_warning_fw_zone_is_not_effective(result, fwzone, version):
|
|
|
2e9388 |
+def _add_warning_fw_zone_is_not_effective(api, result, fwzone, version):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
Adds warning message to result, if required
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
authoritative_zone, truncated = \
|
|
|
2e9388 |
- _get_zone_which_makes_fw_zone_ineffective(fwzone)
|
|
|
2e9388 |
+ _get_zone_which_makes_fw_zone_ineffective(api, fwzone)
|
|
|
2e9388 |
if authoritative_zone:
|
|
|
2e9388 |
# forward zone is not effective and forwarding will not work
|
|
|
2e9388 |
messages.add_message(
|
|
|
2e9388 |
@@ -2072,7 +2072,7 @@ class DNSZoneBase(LDAPObject):
|
|
|
2e9388 |
def _remove_permission(self, zone):
|
|
|
2e9388 |
permission_name = self.permission_name(zone)
|
|
|
2e9388 |
try:
|
|
|
2e9388 |
- api.Command['permission_del'](permission_name, force=True)
|
|
|
2e9388 |
+ self.api.Command['permission_del'](permission_name, force=True)
|
|
|
2e9388 |
except errors.NotFound, e:
|
|
|
2e9388 |
if zone == DNSName.root: # special case root zone
|
|
|
2e9388 |
raise
|
|
|
2e9388 |
@@ -2082,7 +2082,8 @@ class DNSZoneBase(LDAPObject):
|
|
|
2e9388 |
zone.relativize(DNSName.root)
|
|
|
2e9388 |
)
|
|
|
2e9388 |
try:
|
|
|
2e9388 |
- api.Command['permission_del'](permission_name_rel, force=True)
|
|
|
2e9388 |
+ self.api.Command['permission_del'](permission_name_rel,
|
|
|
2e9388 |
+ force=True)
|
|
|
2e9388 |
except errors.NotFound:
|
|
|
2e9388 |
raise e # re-raise original exception
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -2272,7 +2273,8 @@ class DNSZoneBase_add_permission(LDAPQuery):
|
|
|
2e9388 |
keys[-1].relativize(DNSName.root)
|
|
|
2e9388 |
)
|
|
|
2e9388 |
try:
|
|
|
2e9388 |
- api.Object['permission'].get_dn_if_exists(permission_name_rel)
|
|
|
2e9388 |
+ self.api.Object['permission'].get_dn_if_exists(
|
|
|
2e9388 |
+ permission_name_rel)
|
|
|
2e9388 |
except errors.NotFound:
|
|
|
2e9388 |
pass
|
|
|
2e9388 |
else:
|
|
|
2e9388 |
@@ -2283,7 +2285,7 @@ class DNSZoneBase_add_permission(LDAPQuery):
|
|
|
2e9388 |
}
|
|
|
2e9388 |
)
|
|
|
2e9388 |
|
|
|
2e9388 |
- permission = api.Command['permission_add_noaci'](permission_name,
|
|
|
2e9388 |
+ permission = self.api.Command['permission_add_noaci'](permission_name,
|
|
|
2e9388 |
ipapermissiontype=u'SYSTEM'
|
|
|
2e9388 |
)['result']
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -2643,12 +2645,12 @@ class dnszone(DNSZoneBase):
|
|
|
2e9388 |
"""
|
|
|
2e9388 |
zone = keys[-1]
|
|
|
2e9388 |
affected_fw_zones, truncated = _find_subtree_forward_zones_ldap(
|
|
|
2e9388 |
- zone, child_zones_only=True)
|
|
|
2e9388 |
+ self.api, zone, child_zones_only=True)
|
|
|
2e9388 |
if not affected_fw_zones:
|
|
|
2e9388 |
return
|
|
|
2e9388 |
|
|
|
2e9388 |
for fwzone in affected_fw_zones:
|
|
|
2e9388 |
- _add_warning_fw_zone_is_not_effective(result, fwzone,
|
|
|
2e9388 |
+ _add_warning_fw_zone_is_not_effective(self.api, result, fwzone,
|
|
|
2e9388 |
options['version'])
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -2686,7 +2688,8 @@ class dnszone_add(DNSZoneBase_add):
|
|
|
2e9388 |
dn = super(dnszone_add, self).pre_callback(
|
|
|
2e9388 |
ldap, dn, entry_attrs, attrs_list, *keys, **options)
|
|
|
2e9388 |
|
|
|
2e9388 |
- nameservers = [normalize_zone(x) for x in api.Object.dnsrecord.get_dns_masters()]
|
|
|
2e9388 |
+ nameservers = [normalize_zone(x) for x in
|
|
|
2e9388 |
+ self.api.Object.dnsrecord.get_dns_masters()]
|
|
|
2e9388 |
server = normalize_zone(api.env.host)
|
|
|
2e9388 |
zone = keys[-1]
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -2735,7 +2738,7 @@ class dnszone_add(DNSZoneBase_add):
|
|
|
2e9388 |
not zone.is_reverse() and
|
|
|
2e9388 |
zone != DNSName.root):
|
|
|
2e9388 |
try:
|
|
|
2e9388 |
- api.Command['realmdomains_mod'](add_domain=unicode(zone),
|
|
|
2e9388 |
+ self.api.Command['realmdomains_mod'](add_domain=unicode(zone),
|
|
|
2e9388 |
force=True)
|
|
|
2e9388 |
except (errors.EmptyModlist, errors.ValidationError):
|
|
|
2e9388 |
pass
|
|
|
2e9388 |
@@ -2769,8 +2772,8 @@ class dnszone_del(DNSZoneBase_del):
|
|
|
2e9388 |
not zone.is_reverse() and zone != DNSName.root
|
|
|
2e9388 |
):
|
|
|
2e9388 |
try:
|
|
|
2e9388 |
- api.Command['realmdomains_mod'](del_domain=unicode(zone),
|
|
|
2e9388 |
- force=True)
|
|
|
2e9388 |
+ self.api.Command['realmdomains_mod'](
|
|
|
2e9388 |
+ del_domain=unicode(zone), force=True)
|
|
|
2e9388 |
except (errors.AttrValueNotFound, errors.ValidationError):
|
|
|
2e9388 |
pass
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -3476,12 +3479,12 @@ class dnsrecord(LDAPObject):
|
|
|
2e9388 |
record_name_absolute = record_name_absolute.derelativize(zone)
|
|
|
2e9388 |
|
|
|
2e9388 |
affected_fw_zones, truncated = _find_subtree_forward_zones_ldap(
|
|
|
2e9388 |
- record_name_absolute)
|
|
|
2e9388 |
+ self.api, record_name_absolute)
|
|
|
2e9388 |
if not affected_fw_zones:
|
|
|
2e9388 |
return
|
|
|
2e9388 |
|
|
|
2e9388 |
for fwzone in affected_fw_zones:
|
|
|
2e9388 |
- _add_warning_fw_zone_is_not_effective(result, fwzone,
|
|
|
2e9388 |
+ _add_warning_fw_zone_is_not_effective(self.api, result, fwzone,
|
|
|
2e9388 |
options['version'])
|
|
|
2e9388 |
|
|
|
2e9388 |
|
|
|
2e9388 |
@@ -3831,7 +3834,7 @@ class dnsrecord_mod(LDAPUpdate):
|
|
|
2e9388 |
|
|
|
2e9388 |
# get DNS record first so that the NotFound exception is raised
|
|
|
2e9388 |
# before the helper would start
|
|
|
2e9388 |
- dns_record = api.Command['dnsrecord_show'](kw['dnszoneidnsname'], kw['idnsname'])['result']
|
|
|
2e9388 |
+ dns_record = self.api.Command['dnsrecord_show'](kw['dnszoneidnsname'], kw['idnsname'])['result']
|
|
|
2e9388 |
rec_types = [rec_type for rec_type in dns_record if rec_type in _record_attributes]
|
|
|
2e9388 |
|
|
|
2e9388 |
self.Backend.textui.print_plain(_("No option to modify specific record provided."))
|
|
|
2e9388 |
@@ -4019,7 +4022,7 @@ class dnsrecord_del(LDAPUpdate):
|
|
|
2e9388 |
|
|
|
2e9388 |
# get DNS record first so that the NotFound exception is raised
|
|
|
2e9388 |
# before the helper would start
|
|
|
2e9388 |
- dns_record = api.Command['dnsrecord_show'](kw['dnszoneidnsname'], kw['idnsname'])['result']
|
|
|
2e9388 |
+ dns_record = self.api.Command['dnsrecord_show'](kw['dnszoneidnsname'], kw['idnsname'])['result']
|
|
|
2e9388 |
rec_types = [rec_type for rec_type in dns_record if rec_type in _record_attributes]
|
|
|
2e9388 |
|
|
|
2e9388 |
self.Backend.textui.print_plain(_("No option to delete specific record provided."))
|
|
|
2e9388 |
@@ -4334,7 +4337,7 @@ class dnsforwardzone(DNSZoneBase):
|
|
|
2e9388 |
|
|
|
2e9388 |
def _warning_fw_zone_is_not_effective(self, result, *keys, **options):
|
|
|
2e9388 |
fwzone = keys[-1]
|
|
|
2e9388 |
- _add_warning_fw_zone_is_not_effective(result, fwzone,
|
|
|
2e9388 |
+ _add_warning_fw_zone_is_not_effective(self.api, result, fwzone,
|
|
|
2e9388 |
options['version'])
|
|
|
2e9388 |
|
|
|
2e9388 |
def _warning_if_forwarders_do_not_work(self, result, new_zone,
|
|
|
2e9388 |
@@ -4374,7 +4377,7 @@ class dnsforwardzone(DNSZoneBase):
|
|
|
2e9388 |
# validation is configured just in named.conf per replica
|
|
|
2e9388 |
|
|
|
2e9388 |
ipa_dns_masters = [normalize_zone(x) for x in
|
|
|
2e9388 |
- api.Object.dnsrecord.get_dns_masters()]
|
|
|
2e9388 |
+ self.api.Object.dnsrecord.get_dns_masters()]
|
|
|
2e9388 |
|
|
|
2e9388 |
if not ipa_dns_masters:
|
|
|
2e9388 |
# something very bad happened, DNS is installed, but no IPA DNS
|
|
|
2e9388 |
--
|
|
|
2e9388 |
2.4.3
|
|
|
2e9388 |
|