summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJacek Galowicz <jacek@galowicz.de>2020-02-13 16:34:02 +0100
committerJacek Galowicz <jacek@galowicz.de>2020-02-13 16:34:02 +0100
commitde9bac3b86f69500e9a5293e235f0ec17bc2625d (patch)
tree88aac81c3556338cf75f91af6f0fcbc206d48b08 /nixos
parent21b31c4e51b43c3ba7c30d09492e08e9cbdc875a (diff)
downloadnixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar.gz
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar.bz2
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar.lz
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar.xz
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.tar.zst
nixpkgs-de9bac3b86f69500e9a5293e235f0ec17bc2625d.zip
nixosTests.nsd: Port to python
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/nsd.nix52
1 files changed, 25 insertions, 27 deletions
diff --git a/nixos/tests/nsd.nix b/nixos/tests/nsd.nix
index c3c91e71b5c..bcc14e817a8 100644
--- a/nixos/tests/nsd.nix
+++ b/nixos/tests/nsd.nix
@@ -5,7 +5,7 @@ let
     # for a host utility with IPv6 support
     environment.systemPackages = [ pkgs.bind ];
   };
-in import ./make-test.nix ({ pkgs, ...} : {
+in import ./make-test-python.nix ({ pkgs, ...} : {
   name = "nsd";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ aszlig ];
@@ -65,37 +65,35 @@ in import ./make-test.nix ({ pkgs, ...} : {
   };
 
   testScript = ''
-    startAll;
+    start_all()
 
-    $clientv4->waitForUnit("network.target");
-    $clientv6->waitForUnit("network.target");
-    $server->waitForUnit("nsd.service");
+    clientv4.wait_for_unit("network.target")
+    clientv6.wait_for_unit("network.target")
+    server.wait_for_unit("nsd.service")
 
-    sub assertHost {
-      my ($type, $rr, $query, $expected) = @_;
-      my $self = $type eq 4 ? $clientv4 : $clientv6;
-      my $out = $self->succeed("host -$type -t $rr $query");
-      $self->log("output: $out");
-      chomp $out;
-      die "DNS IPv$type query on $query gave '$out' instead of '$expected'"
-        if ($out !~ $expected);
-    }
 
-    foreach (4, 6) {
-      subtest "ipv$_", sub {
-        assertHost($_, "a", "example.com", qr/has no [^ ]+ record/);
-        assertHost($_, "aaaa", "example.com", qr/has no [^ ]+ record/);
+    def assert_host(type, rr, query, expected):
+        self = clientv4 if type == 4 else clientv6
+        out = self.succeed(f"host -{type} -t {rr} {query}").rstrip()
+        self.log(f"output: {out}")
+        assert re.search(
+            expected, out
+        ), f"DNS IPv{type} query on {query} gave '{out}' instead of '{expected}'"
 
-        assertHost($_, "soa", "example.com", qr/SOA.*?noc\.example\.com/);
-        assertHost($_, "a", "ipv4.example.com", qr/address 1.2.3.4$/);
-        assertHost($_, "aaaa", "ipv6.example.com", qr/address abcd::eeff$/);
 
-        assertHost($_, "a", "deleg.example.com", qr/address 9.8.7.6$/);
-        assertHost($_, "aaaa", "deleg.example.com", qr/address fedc::bbaa$/);
+    for ipv in 4, 6:
+        with subtest(f"IPv{ipv}"):
+            assert_host(ipv, "a", "example.com", "has no [^ ]+ record")
+            assert_host(ipv, "aaaa", "example.com", "has no [^ ]+ record")
 
-        assertHost($_, "a", "root", qr/address 1.8.7.4$/);
-        assertHost($_, "aaaa", "root", qr/address acbd::4$/);
-      };
-    }
+            assert_host(ipv, "soa", "example.com", "SOA.*?noc\.example\.com")
+            assert_host(ipv, "a", "ipv4.example.com", "address 1.2.3.4$")
+            assert_host(ipv, "aaaa", "ipv6.example.com", "address abcd::eeff$")
+
+            assert_host(ipv, "a", "deleg.example.com", "address 9.8.7.6$")
+            assert_host(ipv, "aaaa", "deleg.example.com", "address fedc::bbaa$")
+
+            assert_host(ipv, "a", "root", "address 1.8.7.4$")
+            assert_host(ipv, "aaaa", "root", "address acbd::4$")
   '';
 })