remove_dc: Allow remove_dns_references to ignore missing server names
authorGarming Sam <garming@catalyst.net.nz>
Tue, 30 Jan 2018 22:52:34 +0000 (11:52 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 8 Feb 2018 03:58:10 +0000 (04:58 +0100)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/dns.py
python/samba/remove_dc.py

index 5a5bd14757dd947485364f9b157ff821de0486d6..04c3d8bf2d18abf3ba20980e2e114426b987de65 100644 (file)
@@ -1111,7 +1111,8 @@ class cmd_cleanup_record(Command):
                       session_info=system_session(),
                       credentials=creds, lp=lp)
 
-        remove_dc.remove_dns_references(samdb, logger, dnshostname)
+        remove_dc.remove_dns_references(samdb, logger, dnshostname,
+                                        ignore_no_name=True)
 
 
 class cmd_dns(SuperCommand):
index 4c8ee89246431739bf485bb18d991e7d18a61067..f273a5158567e6a474250c14506ec83f92be471b 100644 (file)
@@ -84,7 +84,7 @@ def remove_sysvol_references(samdb, logger, dc_name):
                 raise
 
 
-def remove_dns_references(samdb, logger, dnsHostName):
+def remove_dns_references(samdb, logger, dnsHostName, ignore_no_name=False):
 
     # Check we are using in-database DNS
     zones = samdb.search(base="", scope=ldb.SCOPE_SUBTREE,
@@ -100,7 +100,11 @@ def remove_dns_references(samdb, logger, dnsHostName):
         (dn, primary_recs) = samdb.dns_lookup(dnsHostName)
     except RuntimeError as (enum, estr):
         if enum == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST:
-              return
+            if ignore_no_name:
+                remove_hanging_dns_references(samdb, logger,
+                                              dnsHostNameUpper,
+                                              zones)
+            return
         raise DemoteException("lookup of %s failed: %s" % (dnsHostName, estr))
     samdb.dns_replace(dnsHostName, [])
 
@@ -154,6 +158,11 @@ def remove_dns_references(samdb, logger, dnsHostName):
                 (a_name, len(a_recs), orig_num_recs - len(a_recs)))
             samdb.dns_replace(a_name, a_recs)
 
+    remove_hanging_dns_references(samdb, logger, dnsHostNameUpper, zones)
+
+
+def remove_hanging_dns_references(samdb, logger, dnsHostNameUpper, zones):
+
     # Find all the CNAME, NS, PTR and SRV records that point at the
     # name we are removing
 
@@ -194,6 +203,7 @@ def remove_dns_references(samdb, logger, dnsHostName):
                 # has been done in the list comprehension above
                 samdb.dns_replace_by_dn(record.dn, values)
 
+
 def offline_remove_server(samdb, logger,
                           server_dn,
                           remove_computer_obj=False,