On 13.04.2016 16:01, Petr Spacek wrote:
On 1.4.2016 18:30, Martin Basti wrote:
https://fedorahosted.org/freeipa/ticket/5675

Patches attached.
NACK, it breaks if the client does not have any corresponding DNS record.

[root@vm-033 git]# ipa host-add host.test. --force
----------------------
Added host "host.test"
----------------------
   Host name: host.test
   Principal name: host/host.t...@dom-033.abc.idm.lab.eng.brq.redhat.com
   Password: False
   Keytab: False
   Managed by: host.test

[root@vm-033 git]# ipa host-del host.test. --updatedns
ipa: ERROR: host.test: host not found

I think we already had a ticket to prevent this kind of error, no?


This will be resolved in https://fedorahosted.org/freeipa/ticket/5627

Patch 460 attached, feel free to review both tickets :)
(Patch requires my previous DNS patches)

Martin^2
From c533b677a6fe6e303c28004ef321460be7622c19 Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 2 Mar 2016 13:29:27 +0100
Subject: [PATCH] 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
---
 ipalib/messages.py     | 11 +++++++++++
 ipalib/plugins/host.py | 26 ++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/ipalib/messages.py b/ipalib/messages.py
index 5cd0ea1769920c076c62729ed5fe359cd1680723..872b455c1a1b65fb9e75c3d03293422ce70972c9 100644
--- a/ipalib/messages.py
+++ b/ipalib/messages.py
@@ -360,6 +360,17 @@ class ResultFormattingError(PublicMessage):
     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):
     """Return a tuple with all subclasses
     """
diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py
index 20b5776dd9b7fba231155237231d9f5f505e1297..04bb2991a1d463e17b1ed11e06b35dc3a9829073 100644
--- a/ipalib/plugins/host.py
+++ b/ipalib/plugins/host.py
@@ -23,6 +23,7 @@ import string
 import six
 
 from ipalib import api, errors, util
+from ipalib import messages
 from ipalib import Str, Flag, Bytes
 from ipalib.plugable import Registry
 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):
+    """
+    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)
     try:
         revzone, revname = get_reverse_zone(ipaddr)
@@ -134,6 +139,9 @@ def remove_ptr_rec(ipaddr, host, domain):
         api.Command['dnsrecord_del'](revzone, revname, **delkw)
     except errors.NotFound:
         api.log.debug('PTR record of ipaddr %s not found', ipaddr)
+        return False
+
+    return True
 
 
 def update_sshfp_record(zone, record, entry_attrs):
@@ -760,16 +768,20 @@ class host_del(LDAPDelete):
             parts = fqdn.split('.')
             domain = unicode('.'.join(parts[1:]))
             # Get all resources for this host
+            rec_removed = False
             try:
                 record = api.Command['dnsrecord_show'](
                     domain, parts[0])['result']
             except errors.NotFound:
-                self.obj.handle_not_found(*keys)
+                pass
             else:
                 # remove PTR records first
                 for attr in ('arecord', 'aaaarecord'):
                     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:
                     # remove all A, AAAA, SSHFP records of the host
                     api.Command['dnsrecord_mod'](
@@ -781,6 +793,16 @@ class host_del(LDAPDelete):
                         )
                 except errors.EmptyModlist:
                     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']:
             try:
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to