From e13f4057e4a3dc5acfd5726caa8755ddb14376e1 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 5 Nov 2019 15:21:04 +0100 Subject: [PATCH 1/3] nixos/babeld: port test to python --- nixos/tests/babeld.nix | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/nixos/tests/babeld.nix b/nixos/tests/babeld.nix index 5242cf395d7..fafa788ba57 100644 --- a/nixos/tests/babeld.nix +++ b/nixos/tests/babeld.nix @@ -1,5 +1,5 @@ -import ./make-test.nix ({ pkgs, lib, ...} : { +import ./make-test-python.nix ({ pkgs, lib, ...} : { name = "babeld"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ hexa ]; @@ -21,7 +21,7 @@ import ./make-test.nix ({ pkgs, lib, ...} : { }; }; - localRouter = { pkgs, lib, ... }: + local_router = { pkgs, lib, ... }: { virtualisation.vlans = [ 10 20 ]; @@ -70,7 +70,7 @@ import ./make-test.nix ({ pkgs, lib, ...} : { ''; }; }; - remoteRouter = { pkgs, lib, ... }: + remote_router = { pkgs, lib, ... }: { virtualisation.vlans = [ 20 30 ]; @@ -124,25 +124,25 @@ import ./make-test.nix ({ pkgs, lib, ...} : { testScript = '' - startAll; + start_all() - $client->waitForUnit("network-online.target"); - $localRouter->waitForUnit("network-online.target"); - $remoteRouter->waitForUnit("network-online.target"); + client.wait_for_unit("network-online.target") + local_router.wait_for_unit("network-online.target") + remote_router.wait_for_unit("network-online.target") - $localRouter->waitForUnit("babeld.service"); - $remoteRouter->waitForUnit("babeld.service"); + local_router.wait_for_unit("babeld.service") + remote_router.wait_for_unit("babeld.service") - $localRouter->waitUntilSucceeds("ip route get 192.168.30.1"); - $localRouter->waitUntilSucceeds("ip route get 2001:db8:30::1"); + local_router.wait_until_succeeds("ip route get 192.168.30.1") + local_router.wait_until_succeeds("ip route get 2001:db8:30::1") - $remoteRouter->waitUntilSucceeds("ip route get 192.168.10.1"); - $remoteRouter->waitUntilSucceeds("ip route get 2001:db8:10::1"); + remote_router.wait_until_succeeds("ip route get 192.168.10.1") + remote_router.wait_until_succeeds("ip route get 2001:db8:10::1") - $client->succeed("ping -c1 192.168.30.1"); - $client->succeed("ping -c1 2001:db8:30::1"); + client.succeed("ping -c1 192.168.30.1") + client.succeed("ping -c1 2001:db8:30::1") - $remoteRouter->succeed("ping -c1 192.168.10.2"); - $remoteRouter->succeed("ping -c1 2001:db8:10::2"); + remote_router.succeed("ping -c1 192.168.10.2") + remote_router.succeed("ping -c1 2001:db8:10::2") ''; }) From 76df6d67eacf67d48485cd1d3bb7e3ae6922edae Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 5 Nov 2019 16:02:01 +0100 Subject: [PATCH 2/3] nixos/knot: port test to python --- nixos/tests/knot.nix | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/nixos/tests/knot.nix b/nixos/tests/knot.nix index e46159836cc..7032bfc20a1 100644 --- a/nixos/tests/knot.nix +++ b/nixos/tests/knot.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, lib, ...} : +import ./make-test-python.nix ({ pkgs, lib, ...} : let common = { networking.firewall.enable = false; @@ -161,37 +161,35 @@ in { slave4 = (lib.head nodes.slave.config.networking.interfaces.eth1.ipv4.addresses).address; slave6 = (lib.head nodes.slave.config.networking.interfaces.eth1.ipv6.addresses).address; in '' - startAll; + import re - $client->waitForUnit("network.target"); - $master->waitForUnit("knot.service"); - $slave->waitForUnit("knot.service"); + start_all() - sub assertResponse { - my ($knot, $query_type, $query, $expected) = @_; - my $out = $client->succeed("khost -t $query_type $query $knot"); - $client->log("$knot replies with: $out"); - chomp $out; - die "DNS query for $query ($query_type) against $knot gave '$out' instead of '$expected'" - if ($out !~ $expected); - } + client.wait_for_unit("network.target") + master.wait_for_unit("knot.service") + slave.wait_for_unit("knot.service") - foreach ("${master4}", "${master6}", "${slave4}", "${slave6}") { - subtest $_, sub { - assertResponse($_, "SOA", "example.com", qr/start of authority.*?noc\.example\.com/); - assertResponse($_, "A", "example.com", qr/has no [^ ]+ record/); - assertResponse($_, "AAAA", "example.com", qr/has no [^ ]+ record/); - assertResponse($_, "A", "www.example.com", qr/address 192.0.2.1$/); - assertResponse($_, "AAAA", "www.example.com", qr/address 2001:db8::1$/); + def test(host, query_type, query, pattern): + out = client.succeed(f"khost -t {query_type} {query} {host}").strip() + client.log(f"{host} replied with: {out}") + assert re.search(pattern, out), f'Did not match "{pattern}"' - assertResponse($_, "NS", "sub.example.com", qr/nameserver is ns\d\.example\.com.$/); - assertResponse($_, "A", "sub.example.com", qr/address 192.0.2.2$/); - assertResponse($_, "AAAA", "sub.example.com", qr/address 2001:db8::2$/); - assertResponse($_, "RRSIG", "www.example.com", qr/RR set signature is/); - assertResponse($_, "DNSKEY", "example.com", qr/DNSSEC key is/); - }; - } + for host in ("${master4}", "${master6}", "${slave4}", "${slave6}"): + with subtest(f"Interrogate {host}"): + test(host, "SOA", "example.com", r"start of authority.*noc\.example\.com\.") + test(host, "A", "example.com", r"has no [^ ]+ record") + test(host, "AAAA", "example.com", r"has no [^ ]+ record") + + test(host, "A", "www.example.com", r"address 192.0.2.1$") + test(host, "AAAA", "www.example.com", r"address 2001:db8::1$") + + test(host, "NS", "sub.example.com", r"nameserver is ns\d\.example\.com.$") + test(host, "A", "sub.example.com", r"address 192.0.2.2$") + test(host, "AAAA", "sub.example.com", r"address 2001:db8::2$") + + test(host, "RRSIG", "www.example.com", r"RR set signature is") + test(host, "DNSKEY", "example.com", r"DNSSEC key is") ''; }) From 014970bc17d6cb7718737041e1c4a8a10ef56503 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Tue, 5 Nov 2019 16:03:21 +0100 Subject: [PATCH 3/3] nixos/knot: add myself as maintainer for test --- nixos/tests/knot.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/tests/knot.nix b/nixos/tests/knot.nix index 7032bfc20a1..0588cf86ac0 100644 --- a/nixos/tests/knot.nix +++ b/nixos/tests/knot.nix @@ -30,6 +30,10 @@ let }; in { name = "knot"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ hexa ]; + }; + nodes = { master = { lib, ... }: {