]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool dns: add --allow-existing to not complain if records exist
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 4 Jun 2025 03:43:40 +0000 (15:43 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 5 Jun 2025 23:06:37 +0000 (23:06 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13613

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
Reviewed-by: Rowland Penny <rpenny@samba.org>
python/samba/netcmd/dns.py
selftest/knownfail.d/samba-tool-dns-add-duplicate-record [deleted file]

index 693fc9aa65f3d2ec24048359d22a150452503598..e9ee988949eed722559c180f9afa625c69c4e051 100644 (file)
@@ -1159,8 +1159,13 @@ class cmd_add_record(Command):
         "credopts": options.CredentialsOptions,
     }
 
-    def run(self, server, zone, name, rtype, data, sambaopts=None,
-            credopts=None, versionopts=None):
+    takes_options = [
+        Option("--allow-existing", help="no error if record already exists",
+               action="store_true"),
+    ]
+
+    def run(self, server, zone, name, rtype, data, allow_existing=False,
+            sambaopts=None, credopts=None, versionopts=None):
 
         if rtype.upper() not in ('A', 'AAAA', 'PTR', 'CNAME', 'NS', 'MX', 'SRV', 'TXT'):
             raise CommandError('Adding record of type %s is not supported' % rtype)
@@ -1183,9 +1188,16 @@ class cmd_add_record(Command):
                 'Record already exists; record could not be added. '
                 f'zone[{zone}] name[{name}]')
         }
-        dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
-                                     0, server, zone, name, add_rec_buf, None,
-                                     messages=messages)
+        try:
+            dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
+                                         0, server, zone, name, add_rec_buf, None,
+                                         messages=messages)
+        except CommandError as e:
+            if e.inner_exception.args[0] == werror.WERR_DNS_ERROR_RECORD_ALREADY_EXISTS:
+                if allow_existing:
+                    self.outf.write('Record already exists, not adding\n')
+                    return
+            raise
 
         self.outf.write('Record added successfully\n')
 
diff --git a/selftest/knownfail.d/samba-tool-dns-add-duplicate-record b/selftest/knownfail.d/samba-tool-dns-add-duplicate-record
deleted file mode 100644 (file)
index cfb441a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-samba.tests.samba_tool.dnscmd.+DnsCmdTestCase.test_add_duplicate_record