git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #75701 from kampka/port-tests-2

Port NixOS tests to python

commit9faa37cfdf30bd740c6275f507b8719bb48d3433 authorDmitry Kalinkin <dmitry.kalinkin@gmail.com> dateTue 17 Dec 2019, 21:51 (7 years ago) parentfc47ec6229a0af
10 files changed+80−66
nixos/tests/paperless.nix+18−11 nixos/tests/pdns-recursor.nix+3−3 nixos/tests/peerflix.nix+4−4 nixos/tests/pgmanage.nix+7−5 nixos/tests/php-pcre.nix+5−4 nixos/tests/postgis.nix+6−6 nixos/tests/quagga.nix+14−14 nixos/tests/sonarr.nix+4−4 nixos/tests/switch-test.nix+7−3 nixos/tests/systemd-timesyncd.nix+12−12
nixos/tests/paperless.nix+18−11
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ lib, ... } : {
1+import ./make-test-python.nix ({ lib, ... } : {
22 name = "paperless";
33 meta = with lib.maintainers; {
44 maintainers = [ earvstedt ];
@@ -13,17 +13,24 @@ import ./make-test.nix ({ lib, ... } : {
1313 };
1414
1515 testScript = ''
16− $machine->waitForUnit("paperless-consumer.service");
16+ machine.wait_for_unit("paperless-consumer.service")
17+
1718 # Create test doc
18− $machine->succeed('convert -size 400x40 xc:white -font "DejaVu-Sans" -pointsize 20 -fill black \
19− -annotate +5+20 "hello world 16-10-2005" /var/lib/paperless/consume/doc.png');
19+ machine.succeed(
20+ "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black -annotate +5+20 'hello world 16-10-2005' /var/lib/paperless/consume/doc.png"
21+ )
22+
23+ with subtest("Service gets ready"):
24+ machine.wait_for_unit("paperless-server.service")
25+ # Wait until server accepts connections
26+ machine.wait_until_succeeds("curl -s localhost:28981")
2027
21− $machine->waitForUnit("paperless-server.service");
22− # Wait until server accepts connections
23− $machine->waitUntilSucceeds("curl -s localhost:28981");
24− # Wait until document is consumed
25− $machine->waitUntilSucceeds('(($(curl -s localhost:28981/api/documents/ | jq .count) == 1))');
26− $machine->succeed("curl -s localhost:28981/api/documents/ | jq '.results | .[0] | .created'")
27− =~ /2005-10-16/ or die;
28+ with subtest("Test document is consumed"):
29+ machine.wait_until_succeeds(
30+ "(($(curl -s localhost:28981/api/documents/ | jq .count) == 1))"
31+ )
32+ assert "2005-10-16" in machine.succeed(
33+ "curl -s localhost:28981/api/documents/ | jq '.results | .[0] | .created'"
34+ )
2835 '';
2936})
nixos/tests/pdns-recursor.nix+3−3
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ... }: {
1+import ./make-test-python.nix ({ pkgs, ... }: {
22 name = "powerdns";
33
44 nodes.server = { ... }: {
@@ -6,7 +6,7 @@ import ./make-test.nix ({ pkgs, ... }: {
66 };
77
88 testScript = ''
9− $server->waitForUnit("pdns-recursor");
10− $server->waitForOpenPort("53");
9+ server.wait_for_unit("pdns-recursor")
10+ server.wait_for_open_port("53")
1111 '';
1212})
nixos/tests/peerflix.nix+4−4
@@ -1,6 +1,6 @@
11# This test runs peerflix and checks if peerflix starts
22
3−import ./make-test.nix ({ pkgs, ...} : {
3+import ./make-test-python.nix ({ pkgs, ...} : {
44 name = "peerflix";
55 meta = with pkgs.stdenv.lib.maintainers; {
66 maintainers = [ offline ];
@@ -15,9 +15,9 @@ import ./make-test.nix ({ pkgs, ...} : {
1515 };
1616
1717 testScript = ''
18− startAll;
18+ start_all()
1919
20− $peerflix->waitForUnit("peerflix.service");
21− $peerflix->waitUntilSucceeds("curl localhost:9000");
20+ peerflix.wait_for_unit("peerflix.service")
21+ peerflix.wait_until_succeeds("curl localhost:9000")
2222 '';
2323})
nixos/tests/pgmanage.nix+7−5
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ... } :
1+import ./make-test-python.nix ({ pkgs, ... } :
22let
33 role = "test";
44 password = "secret";
@@ -29,11 +29,13 @@ in
2929 };
3030
3131 testScript = ''
32− startAll;
33− $one->waitForUnit("default.target");
34− $one->requireActiveUnit("pgmanage.service");
32+ start_all()
33+ one.wait_for_unit("default.target")
34+ one.require_unit_state("pgmanage.service", "active")
3535
3636 # Test if we can log in.
37− $one->waitUntilSucceeds("curl 'http://localhost:8080/pgmanage/auth' --data 'action=login&connname=${conn}&username=${role}&password=${password}' --fail");
37+ one.wait_until_succeeds(
38+ "curl 'http://localhost:8080/pgmanage/auth' --data 'action=login&connname=${conn}&username=${role}&password=${password}' --fail"
39+ )
3840 '';
3941})
nixos/tests/php-pcre.nix+5−4
@@ -1,7 +1,7 @@
11
22let testString = "can-use-subgroups"; in
33
4−import ./make-test.nix ({ ...}: {
4+import ./make-test-python.nix ({ ...}: {
55 name = "php-httpd-pcre-jit-test";
66 machine = { lib, pkgs, ... }: {
77 time.timeZone = "UTC";
@@ -31,9 +31,10 @@ import ./make-test.nix ({ ...}: {
3131 };
3232 testScript = { ... }:
3333 ''
34− $machine->waitForUnit('httpd.service');
34+ machine.wait_for_unit("httpd.service")
3535 # Ensure php evaluation by matching on the var_dump syntax
36− $machine->succeed('curl -vvv -s http://127.0.0.1:80/index.php \
37− | grep "string(${toString (builtins.stringLength testString)}) \"${testString}\""');
36+ assert 'string(${toString (builtins.stringLength testString)}) "${testString}"' in machine.succeed(
37+ "curl -vvv -s http://127.0.0.1:80/index.php"
38+ )
3839 '';
3940})
nixos/tests/postgis.nix+6−6
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ...} : {
1+import ./make-test-python.nix ({ pkgs, ...} : {
22 name = "postgis";
33 meta = with pkgs.stdenv.lib.maintainers; {
44 maintainers = [ lsix ];
@@ -20,10 +20,10 @@ import ./make-test.nix ({ pkgs, ...} : {
2020 };
2121
2222 testScript = ''
23− startAll;
24− $master->waitForUnit("postgresql");
25− $master->sleep(10); # Hopefully this is long enough!!
26− $master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'");
27− $master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis_topology;'");
23+ start_all()
24+ master.wait_for_unit("postgresql")
25+ master.sleep(10) # Hopefully this is long enough!!
26+ master.succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'")
27+ master.succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis_topology;'")
2828 '';
2929})
nixos/tests/quagga.nix+14−14
@@ -5,7 +5,7 @@
55#
66# All interfaces are in OSPF Area 0.
77
8−import ./make-test.nix ({ pkgs, ... }:
8+import ./make-test-python.nix ({ pkgs, ... }:
99 let
1010
1111 ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
@@ -74,23 +74,23 @@ import ./make-test.nix ({ pkgs, ... }:
7474 testScript =
7575 { ... }:
7676 ''
77− startAll;
77+ start_all()
7878
7979 # Wait for the networking to start on all machines
80− $_->waitForUnit("network.target") foreach values %vms;
80+ for machine in client, router1, router2, server:
81+ machine.wait_for_unit("network.target")
8182
82− # Wait for OSPF to form adjacencies
83− for my $gw ($router1, $router2) {
84− $gw->waitForUnit("ospfd");
85− $gw->waitUntilSucceeds("vtysh -c 'show ip ospf neighbor' | grep Full");
86− $gw->waitUntilSucceeds("vtysh -c 'show ip route' | grep '^O>'");
87− }
83+ with subtest("Wait for OSPF to form adjacencies"):
84+ for gw in router1, router2:
85+ gw.wait_for_unit("ospfd")
86+ gw.wait_until_succeeds("vtysh -c 'show ip ospf neighbor' | grep Full")
87+ gw.wait_until_succeeds("vtysh -c 'show ip route' | grep '^O>'")
8888
89− # Test ICMP.
90− $client->succeed("ping -c 3 server >&2");
89+ with subtest("Test ICMP"):
90+ client.wait_until_succeeds("ping -c 3 server >&2")
9191
92− # Test whether HTTP works.
93− $server->waitForUnit("httpd");
94− $client->succeed("curl --fail http://server/ >&2");
92+ with subtest("Test whether HTTP works"):
93+ server.wait_for_unit("httpd")
94+ client.succeed("curl --fail http://server/ >&2")
9595 '';
9696 })
nixos/tests/sonarr.nix+4−4
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ lib, ... }:
1+import ./make-test-python.nix ({ lib, ... }:
22
33with lib;
44
@@ -11,8 +11,8 @@ with lib;
1111 { services.sonarr.enable = true; };
1212
1313 testScript = ''
14− $machine->waitForUnit('sonarr.service');
15− $machine->waitForOpenPort('8989');
16− $machine->succeed("curl --fail http://localhost:8989/");
14+ machine.wait_for_unit("sonarr.service")
15+ machine.wait_for_open_port("8989")
16+ machine.succeed("curl --fail http://localhost:8989/")
1717 '';
1818})
nixos/tests/switch-test.nix+7−3
@@ -1,6 +1,6 @@
11# Test configuration switching.
22
3−import ./make-test.nix ({ pkgs, ...} : {
3+import ./make-test-python.nix ({ pkgs, ...} : {
44 name = "switch-test";
55 meta = with pkgs.stdenv.lib.maintainers; {
66 maintainers = [ gleber ];
@@ -28,7 +28,11 @@ import ./make-test.nix ({ pkgs, ...} : {
2828 exec env -i "$@" | tee /dev/stderr
2929 '';
3030 in ''
31− $machine->succeed("${stderrRunner} ${originalSystem}/bin/switch-to-configuration test");
32− $machine->succeed("${stderrRunner} ${otherSystem}/bin/switch-to-configuration test");
31+ machine.succeed(
32+ "${stderrRunner} ${originalSystem}/bin/switch-to-configuration test"
33+ )
34+ machine.succeed(
35+ "${stderrRunner} ${otherSystem}/bin/switch-to-configuration test"
36+ )
3337 '';
3438})
nixos/tests/systemd-timesyncd.nix+12−12
@@ -1,7 +1,7 @@
11# Regression test for systemd-timesync having moved the state directory without
22# upstream providing a migration path. https://github.com/systemd/systemd/issues/12131
33
4−import ./make-test.nix (let
4+import ./make-test-python.nix (let
55 common = { lib, ... }: {
66 # override the `false` value from the qemu-vm base profile
77 services.timesyncd.enable = lib.mkForce true;
@@ -25,28 +25,28 @@ in {
2525 };
2626
2727 testScript = ''
28− startAll;
29− $current->succeed('systemctl status systemd-timesyncd.service');
28+ start_all()
29+ current.succeed("systemctl status systemd-timesyncd.service")
3030 # on a new install with a recent systemd there should not be any
3131 # leftovers from the dynamic user mess
32− $current->succeed('test -e /var/lib/systemd/timesync');
33− $current->succeed('test ! -L /var/lib/systemd/timesync');
32+ current.succeed("test -e /var/lib/systemd/timesync")
33+ current.succeed("test ! -L /var/lib/systemd/timesync")
3434
3535 # timesyncd should be running on the upgrading system since we fixed the
3636 # file bits in the activation script
37− $pre1909->succeed('systemctl status systemd-timesyncd.service');
37+ pre1909.succeed("systemctl status systemd-timesyncd.service")
3838
3939 # the path should be gone after the migration
40− $pre1909->succeed('test ! -e /var/lib/private/systemd/timesync');
40+ pre1909.succeed("test ! -e /var/lib/private/systemd/timesync")
4141
4242 # and the new path should no longer be a symlink
43− $pre1909->succeed('test -e /var/lib/systemd/timesync');
44− $pre1909->succeed('test ! -L /var/lib/systemd/timesync');
43+ pre1909.succeed("test -e /var/lib/systemd/timesync")
44+ pre1909.succeed("test ! -L /var/lib/systemd/timesync")
4545
4646 # after a restart things should still work and not fail in the activation
4747 # scripts and cause the boot to fail..
48− $pre1909->shutdown;
49− $pre1909->start;
50− $pre1909->succeed('systemctl status systemd-timesyncd.service');
48+ pre1909.shutdown()
49+ pre1909.start()
50+ pre1909.succeed("systemctl status systemd-timesyncd.service")
5151 '';
5252})