host-del --updatedns: print warnings instead of error

When DNS records do not exist, print warnings instead of hard error

https://fedorahosted.org/freeipa/ticket/5627

Reviewed-By: Petr Spacek <pspacek@redhat.com>
This commit is contained in:
Martin Basti 2016-03-02 13:29:27 +01:00
parent 54e3859595
commit b23ad42269
2 changed files with 35 additions and 2 deletions

View File

@ -360,6 +360,17 @@ class ResultFormattingError(PublicMessage):
type = "warning" type = "warning"
class FailedToRemoveHostDNSRecords(PublicMessage):
"""
**13020** Failed to remove host DNS records
"""
errno = 13020
type = "warning"
format = _("DNS record(s) of host %(host)s could not be removed. "
"(%(reason)s)")
def iter_messages(variables, base): def iter_messages(variables, base):
"""Return a tuple with all subclasses """Return a tuple with all subclasses
""" """

View File

@ -23,6 +23,7 @@ import string
import six import six
from ipalib import api, errors, util from ipalib import api, errors, util
from ipalib import messages
from ipalib import Str, Flag, Bytes from ipalib import Str, Flag, Bytes
from ipalib.plugable import Registry from ipalib.plugable import Registry
from ipalib.plugins.baseldap import (LDAPQuery, LDAPObject, LDAPCreate, from ipalib.plugins.baseldap import (LDAPQuery, LDAPObject, LDAPCreate,
@ -122,6 +123,10 @@ host_pwd_chars = string.digits + string.ascii_letters + '_,.@+-='
def remove_ptr_rec(ipaddr, host, domain): def remove_ptr_rec(ipaddr, host, domain):
"""
Remove PTR record of IP address (ipaddr)
:return: True if PTR record was removed, False if record was not found
"""
api.log.debug('deleting PTR record of ipaddr %s', ipaddr) api.log.debug('deleting PTR record of ipaddr %s', ipaddr)
try: try:
revzone, revname = get_reverse_zone(ipaddr) revzone, revname = get_reverse_zone(ipaddr)
@ -134,6 +139,9 @@ def remove_ptr_rec(ipaddr, host, domain):
api.Command['dnsrecord_del'](revzone, revname, **delkw) api.Command['dnsrecord_del'](revzone, revname, **delkw)
except errors.NotFound: except errors.NotFound:
api.log.debug('PTR record of ipaddr %s not found', ipaddr) api.log.debug('PTR record of ipaddr %s not found', ipaddr)
return False
return True
def update_sshfp_record(zone, record, entry_attrs): def update_sshfp_record(zone, record, entry_attrs):
@ -760,16 +768,20 @@ class host_del(LDAPDelete):
parts = fqdn.split('.') parts = fqdn.split('.')
domain = unicode('.'.join(parts[1:])) domain = unicode('.'.join(parts[1:]))
# Get all resources for this host # Get all resources for this host
rec_removed = False
try: try:
record = api.Command['dnsrecord_show']( record = api.Command['dnsrecord_show'](
domain, parts[0])['result'] domain, parts[0])['result']
except errors.NotFound: except errors.NotFound:
self.obj.handle_not_found(*keys) pass
else: else:
# remove PTR records first # remove PTR records first
for attr in ('arecord', 'aaaarecord'): for attr in ('arecord', 'aaaarecord'):
for val in record.get(attr, []): for val in record.get(attr, []):
remove_ptr_rec(val, parts[0], domain) rec_removed = (
remove_ptr_rec(val, parts[0], domain) or
rec_removed
)
try: try:
# remove all A, AAAA, SSHFP records of the host # remove all A, AAAA, SSHFP records of the host
api.Command['dnsrecord_mod']( api.Command['dnsrecord_mod'](
@ -781,6 +793,16 @@ class host_del(LDAPDelete):
) )
except errors.EmptyModlist: except errors.EmptyModlist:
pass pass
else:
rec_removed = True
if not rec_removed:
self.add_message(
messages.FailedToRemoveHostDNSRecords(
host=fqdn,
reason=_("No A, AAAA, SSHFP or PTR records found.")
)
)
if self.api.Command.ca_is_enabled()['result']: if self.api.Command.ca_is_enabled()['result']:
try: try: