]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use isctest.asyncserver in the "nsupdate" test
authorŠtěpán Balážik <stepan@isc.org>
Thu, 28 Aug 2025 16:13:36 +0000 (18:13 +0200)
committerŠtěpán Balážik <stepan@isc.org>
Thu, 23 Oct 2025 11:44:20 +0000 (11:44 +0000)
Reimplement the custom server written in Perl in Python using the
AsyncDnsServer class.

bin/tests/system/nsupdate/ans4/ans.pl [deleted file]
bin/tests/system/nsupdate/ans4/ans.py [new file with mode: 0644]

diff --git a/bin/tests/system/nsupdate/ans4/ans.pl b/bin/tests/system/nsupdate/ans4/ans.pl
deleted file mode 100644 (file)
index 30c792f..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
-#
-# SPDX-License-Identifier: MPL-2.0
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0.  If a copy of the MPL was not distributed with this
-# file, you can obtain one at https://mozilla.org/MPL/2.0/.
-#
-# See the COPYRIGHT file distributed with this work for additional
-# information regarding copyright ownership.
-
-use IO::Socket;
-use IO::File;
-use strict;
-
-# Ignore SIGPIPE so we won't fail if peer closes a TCP socket early
-local $SIG{PIPE} = 'IGNORE';
-
-# Flush logged output after every line
-local $| = 1;
-
-my $server_addr = "10.53.0.4";
-if (@ARGV > 0) {
-       $server_addr = @ARGV[0];
-}
-
-my $localport = int($ENV{'PORT'});
-if (!$localport) { $localport = 5300; }
-
-my $udpsock = IO::Socket::INET->new(LocalAddr => "$server_addr",
-   LocalPort => $localport, Proto => "udp", Reuse => 1) or die "$!";
-my $tcpsock = IO::Socket::INET->new(LocalAddr => "$server_addr",
-   LocalPort => $localport, Proto => "tcp", Listen => 5, Reuse => 1) or die "$!";
-
-print "listening on $server_addr:$localport.\n";
-
-my $pidf = new IO::File "ans.pid", "w" or die "cannot open pid file: $!";
-print $pidf "$$\n" or die "cannot write pid file: $!";
-$pidf->close or die "cannot close pid file: $!";;
-sub rmpid { unlink "ans.pid"; exit 1; };
-
-$SIG{INT} = \&rmpid;
-$SIG{TERM} = \&rmpid;
-
-# Main
-for (;;) {
-       my $rin;
-       my $rout;
-
-       $rin = '';
-       vec($rin, fileno($udpsock), 1) = 1;
-       vec($rin, fileno($tcpsock), 1) = 1;
-
-       select($rout = $rin, undef, undef, undef);
-
-       if (vec($rout, fileno($udpsock), 1)) {
-               printf "UDP request\n";
-               my $buf;
-               $udpsock->recv($buf, 512);
-       } elsif (vec($rout, fileno($tcpsock), 1)) {
-               printf "TCP request\n";
-       }
-}
diff --git a/bin/tests/system/nsupdate/ans4/ans.py b/bin/tests/system/nsupdate/ans4/ans.py
new file mode 100644 (file)
index 0000000..ab066c4
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from isctest.asyncserver import (
+    AsyncDnsServer,
+    IgnoreAllConnections,
+    IgnoreAllQueries,
+)
+
+
+def main() -> None:
+    server = AsyncDnsServer()
+    server.install_connection_handler(IgnoreAllConnections())
+    server.install_response_handler(IgnoreAllQueries())
+    server.run()
+
+
+if __name__ == "__main__":
+    main()