diff --git a/nixos/tests/clickhouse.nix b/nixos/tests/clickhouse.nix index 7d835069ec4..2d8a7cf7aa9 100644 --- a/nixos/tests/clickhouse.nix +++ b/nixos/tests/clickhouse.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +import ./make-test-python.nix ({ pkgs, ... }: { name = "clickhouse"; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ma27 ]; @@ -14,12 +14,18 @@ import ./make-test.nix ({ pkgs, ... }: { selectQuery = pkgs.writeText "select.sql" "SELECT * from `demo`"; in '' - $machine->start(); - $machine->waitForUnit("clickhouse.service"); - $machine->waitForOpenPort(9000); + machine.start() + machine.wait_for_unit("clickhouse.service") + machine.wait_for_open_port(9000) - $machine->succeed("cat ${tableDDL} | clickhouse-client"); - $machine->succeed("cat ${insertQuery} | clickhouse-client"); - $machine->succeed("cat ${selectQuery} | clickhouse-client | grep foo"); + machine.succeed( + "cat ${tableDDL} | clickhouse-client" + ) + machine.succeed( + "cat ${insertQuery} | clickhouse-client" + ) + machine.succeed( + "cat ${selectQuery} | clickhouse-client | grep foo" + ) ''; }) diff --git a/nixos/tests/deluge.nix b/nixos/tests/deluge.nix index b58030409b5..37689c3d913 100644 --- a/nixos/tests/deluge.nix +++ b/nixos/tests/deluge.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : { +import ./make-test-python.nix ({ pkgs, ...} : { name = "deluge"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ flokli ]; @@ -45,18 +45,20 @@ import ./make-test.nix ({ pkgs, ...} : { }; testScript = '' - startAll; + start_all() - $simple->waitForUnit("deluged"); - $simple->waitForUnit("delugeweb"); - $simple->waitForOpenPort("8112"); - $declarative->waitForUnit("network.target"); - $declarative->waitUntilSucceeds("curl --fail http://simple:8112"); + simple.wait_for_unit("deluged") + simple.wait_for_unit("delugeweb") + simple.wait_for_open_port("8112") + declarative.wait_for_unit("network.target") + declarative.wait_until_succeeds("curl --fail http://simple:8112") - $declarative->waitForUnit("deluged"); - $declarative->waitForUnit("delugeweb"); - $declarative->waitUntilSucceeds("curl --fail http://declarative:3142"); - $declarative->succeed("deluge-console 'help' | grep -q 'rm - Remove a torrent'"); - $declarative->succeed("deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm - Remove a torrent'"); + declarative.wait_for_unit("deluged") + declarative.wait_for_unit("delugeweb") + declarative.wait_until_succeeds("curl --fail http://declarative:3142") + declarative.succeed("deluge-console 'help' | grep -q 'rm - Remove a torrent'") + declarative.succeed( + "deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm - Remove a torrent'" + ) ''; }) diff --git a/nixos/tests/fancontrol.nix b/nixos/tests/fancontrol.nix index 83ddbb54c5b..356cd57ffa1 100644 --- a/nixos/tests/fancontrol.nix +++ b/nixos/tests/fancontrol.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... } : { +import ./make-test-python.nix ({ pkgs, ... } : { name = "fancontrol"; machine = @@ -19,7 +19,10 @@ import ./make-test.nix ({ pkgs, ... } : { # This configuration cannot be valid for the test VM, so it's expected to get an 'outdated' error. testScript = '' - $machine->waitForUnit("fancontrol.service"); - $machine->waitUntilSucceeds("journalctl -eu fancontrol | grep 'Configuration appears to be outdated'"); + start_all() + machine.wait_for_unit("fancontrol.service") + machine.wait_until_succeeds( + "journalctl -eu fancontrol | grep 'Configuration appears to be outdated'" + ) ''; }) diff --git a/nixos/tests/firewall.nix b/nixos/tests/firewall.nix index fcf758910e0..09a1fef852e 100644 --- a/nixos/tests/firewall.nix +++ b/nixos/tests/firewall.nix @@ -1,6 +1,6 @@ # Test the firewall module. -import ./make-test.nix ( { pkgs, ... } : { +import ./make-test-python.nix ( { pkgs, ... } : { name = "firewall"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ eelco ]; @@ -36,30 +36,30 @@ import ./make-test.nix ( { pkgs, ... } : { testScript = { nodes, ... }: let newSystem = nodes.walled2.config.system.build.toplevel; in '' - $walled->start; - $attacker->start; + start_all() - $walled->waitForUnit("firewall"); - $walled->waitForUnit("httpd"); - $attacker->waitForUnit("network.target"); + walled.wait_for_unit("firewall") + walled.wait_for_unit("httpd") + attacker.wait_for_unit("network.target") # Local connections should still work. - $walled->succeed("curl -v http://localhost/ >&2"); + walled.succeed("curl -v http://localhost/ >&2") # Connections to the firewalled machine should fail, but ping should succeed. - $attacker->fail("curl --fail --connect-timeout 2 http://walled/ >&2"); - $attacker->succeed("ping -c 1 walled >&2"); + attacker.fail("curl --fail --connect-timeout 2 http://walled/ >&2") + attacker.succeed("ping -c 1 walled >&2") # Outgoing connections/pings should still work. - $walled->succeed("curl -v http://attacker/ >&2"); - $walled->succeed("ping -c 1 attacker >&2"); + walled.succeed("curl -v http://attacker/ >&2") + walled.succeed("ping -c 1 attacker >&2") # If we stop the firewall, then connections should succeed. - $walled->stopJob("firewall"); - $attacker->succeed("curl -v http://walled/ >&2"); + walled.stop_job("firewall") + attacker.succeed("curl -v http://walled/ >&2") # Check whether activation of a new configuration reloads the firewall. - $walled->succeed("${newSystem}/bin/switch-to-configuration test 2>&1" . - " | grep -qF firewall.service"); + walled.succeed( + "${newSystem}/bin/switch-to-configuration test 2>&1 | grep -qF firewall.service" + ) ''; }) diff --git a/nixos/tests/fish.nix b/nixos/tests/fish.nix index 97c4e8e37ac..68fba428439 100644 --- a/nixos/tests/fish.nix +++ b/nixos/tests/fish.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +import ./make-test-python.nix ({ pkgs, ... }: { name = "fish"; machine = @@ -14,8 +14,11 @@ import ./make-test.nix ({ pkgs, ... }: { testScript = '' - $machine->waitForFile("/etc/fish/generated_completions/coreutils.fish"); - $machine->waitForFile("/etc/fish/generated_completions/kill.fish"); - $machine->succeed("fish -ic 'echo \$fish_complete_path' | grep -q '/share/fish/completions /etc/fish/generated_completions /root/.local/share/fish/generated_completions\$'"); + start_all() + machine.wait_for_file("/etc/fish/generated_completions/coreutils.fish") + machine.wait_for_file("/etc/fish/generated_completions/kill.fish") + machine.succeed( + "fish -ic 'echo $fish_complete_path' | grep -q '/share/fish/completions /etc/fish/generated_completions /root/.local/share/fish/generated_completions$'" + ) ''; }) diff --git a/nixos/tests/fluentd.nix b/nixos/tests/fluentd.nix index e5c4c3d2163..918f2f87db1 100644 --- a/nixos/tests/fluentd.nix +++ b/nixos/tests/fluentd.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, lib, ... }: { +import ./make-test-python.nix ({ pkgs, lib, ... }: { name = "fluentd"; machine = { pkgs, ... }: { @@ -33,14 +33,17 @@ import ./make-test.nix ({ pkgs, lib, ... }: { inherit testMessage; }); in '' - $machine->start; - $machine->waitForUnit('fluentd.service'); - $machine->waitForOpenPort(9880); + machine.start() + machine.wait_for_unit("fluentd.service") + machine.wait_for_open_port(9880) - $machine->succeed("curl -fsSL -X POST -H 'Content-type: application/json' -d @${payload} http://localhost:9880/test.tag"); + machine.succeed( + "curl -fsSL -X POST -H 'Content-type: application/json' -d @${payload} http://localhost:9880/test.tag" + ) - $machine->succeed("systemctl stop fluentd"); # blocking flush + # blocking flush + machine.succeed("systemctl stop fluentd") - $machine->succeed("grep '${testMessage}' /tmp/current-log"); + machine.succeed("grep '${testMessage}' /tmp/current-log") ''; }) diff --git a/nixos/tests/handbrake.nix b/nixos/tests/handbrake.nix index ae87e1f69a7..e5fb6b269b1 100644 --- a/nixos/tests/handbrake.nix +++ b/nixos/tests/handbrake.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: +import ./make-test-python.nix ({ pkgs, ... }: let # Download Big Buck Bunny example, licensed under CC Attribution 3.0. testMkv = pkgs.fetchurl { @@ -19,7 +19,13 @@ in { testScript = '' # Test MP4 and MKV transcoding. Since this is a short clip, transcoding typically # only takes a few seconds. - $machine->succeed("HandBrakeCLI -i ${testMkv} -o test.mp4 -e x264 -q 20 -B 160"); - $machine->succeed("HandBrakeCLI -i ${testMkv} -o test.mkv -e x264 -q 20 -B 160"); + start_all() + + machine.succeed( + "HandBrakeCLI -i ${testMkv} -o test.mp4 -e x264 -q 20 -B 160" + ) + machine.succeed( + "HandBrakeCLI -i ${testMkv} -o test.mkv -e x264 -q 20 -B 160" + ) ''; }) diff --git a/nixos/tests/hibernate.nix b/nixos/tests/hibernate.nix index 274aa7becc8..8251c6e7ef8 100644 --- a/nixos/tests/hibernate.nix +++ b/nixos/tests/hibernate.nix @@ -1,6 +1,6 @@ # Test whether hibernation from partition works. -import ./make-test.nix (pkgs: { +import ./make-test-python.nix (pkgs: { name = "hibernate"; nodes = { @@ -28,16 +28,17 @@ import ./make-test.nix (pkgs: { testScript = '' - $machine->waitForUnit("multi-user.target"); - $machine->succeed("mkswap /dev/vdb"); - $machine->succeed("swapon -a"); - $machine->startJob("listener"); - $machine->waitForOpenPort(4444); - $machine->succeed("systemctl hibernate &"); - $machine->waitForShutdown; - $probe->waitForUnit("multi-user.target"); - $machine->start; - $probe->waitUntilSucceeds("echo test | nc machine 4444 -N"); + machine.start() + machine.wait_for_unit("multi-user.target") + machine.succeed("mkswap /dev/vdb") + machine.succeed("swapon -a") + machine.start_job("listener") + machine.wait_for_open_port(4444) + machine.succeed("systemctl hibernate &") + machine.wait_for_shutdown() + probe.wait_for_unit("multi-user.target") + machine.start() + probe.wait_until_succeeds("echo test | nc machine 4444 -N") ''; }) diff --git a/nixos/tests/hound.nix b/nixos/tests/hound.nix index cb8e25332c0..27c65abdf27 100644 --- a/nixos/tests/hound.nix +++ b/nixos/tests/hound.nix @@ -1,5 +1,5 @@ # Test whether `houndd` indexes nixpkgs -import ./make-test.nix ({ pkgs, ... } : { +import ./make-test-python.nix ({ pkgs, ... } : { name = "hound"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ grahamc ]; @@ -46,13 +46,14 @@ import ./make-test.nix ({ pkgs, ... } : { }; }; - testScript = - '' startAll; + testScript = '' + start_all() - $machine->waitForUnit("network.target"); - $machine->waitForUnit("hound.service"); - $machine->waitForOpenPort(6080); - $machine->waitUntilSucceeds('curl http://127.0.0.1:6080/api/v1/search\?stats\=fosho\&repos\=\*\&rng=%3A20\&q\=hi\&files\=\&i=nope | grep "Filename" | grep "hello"'); - - ''; + machine.wait_for_unit("network.target") + machine.wait_for_unit("hound.service") + machine.wait_for_open_port(6080) + machine.wait_until_succeeds( + "curl http://127.0.0.1:6080/api/v1/search\?stats\=fosho\&repos\=\*\&rng=%3A20\&q\=hi\&files\=\&i=nope | grep 'Filename' | grep 'hello'" + ) + ''; }) diff --git a/nixos/tests/icingaweb2.nix b/nixos/tests/icingaweb2.nix index ea1b94c526b..2f65604539c 100644 --- a/nixos/tests/icingaweb2.nix +++ b/nixos/tests/icingaweb2.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +import ./make-test-python.nix ({ pkgs, ... }: { name = "icingaweb2"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ das_j ]; @@ -64,8 +64,8 @@ import ./make-test.nix ({ pkgs, ... }: { }; testScript = '' - startAll(); - $icingaweb2->waitForUnit("multi-user.target"); - $icingaweb2->succeed("curl -sSf http://icingaweb2/authentication/login"); + start_all() + icingaweb2.wait_for_unit("multi-user.target") + icingaweb2.succeed("curl -sSf http://icingaweb2/authentication/login") ''; }) diff --git a/nixos/tests/incron.nix b/nixos/tests/incron.nix index e39bbb5f096..b22ee4c9a03 100644 --- a/nixos/tests/incron.nix +++ b/nixos/tests/incron.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, lib, ... }: +import ./make-test-python.nix ({ pkgs, lib, ... }: { name = "incron"; @@ -19,34 +19,34 @@ import ./make-test.nix ({ pkgs, lib, ... }: }; testScript = '' - startAll; + start_all() - $machine->waitForUnit("multi-user.target"); - $machine->waitForUnit("incron.service"); + machine.wait_for_unit("multi-user.target") + machine.wait_for_unit("incron.service") - $machine->succeed("test -d /test"); + machine.succeed("test -d /test") # create some activity for incron to monitor - $machine->succeed("touch /test/file"); - $machine->succeed("echo foo >> /test/file"); - $machine->succeed("mv /test/file /root"); - $machine->succeed("mv /root/file /test"); + machine.succeed("touch /test/file") + machine.succeed("echo foo >> /test/file") + machine.succeed("mv /test/file /root") + machine.succeed("mv /root/file /test") - $machine->sleep(1); + machine.sleep(1) # touch /test/file - $machine->succeed("grep '/test/file IN_CREATE' /root/incron.log"); + machine.succeed("grep '/test/file IN_CREATE' /root/incron.log") # echo foo >> /test/file - $machine->succeed("grep '/test/file IN_MODIFY' /root/incron.log"); - $machine->succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log"); + machine.succeed("grep '/test/file IN_MODIFY' /root/incron.log") + machine.succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log") # mv /test/file /root - $machine->succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log"); + machine.succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log") # mv /root/file /test - $machine->succeed("grep '/test/file IN_MOVED_TO' /root/incron.log"); + machine.succeed("grep '/test/file IN_MOVED_TO' /root/incron.log") # ensure something unexpected is not present - $machine->fail("grep 'IN_OPEN' /root/incron.log"); + machine.fail("grep 'IN_OPEN' /root/incron.log") ''; }) diff --git a/nixos/tests/jackett.nix b/nixos/tests/jackett.nix index c749c32ad04..0a706c99b99 100644 --- a/nixos/tests/jackett.nix +++ b/nixos/tests/jackett.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ lib, ... }: +import ./make-test-python.nix ({ lib, ... }: with lib; @@ -11,8 +11,9 @@ with lib; { services.jackett.enable = true; }; testScript = '' - $machine->waitForUnit('jackett.service'); - $machine->waitForOpenPort('9117'); - $machine->succeed("curl --fail http://localhost:9117/"); + machine.start() + machine.wait_for_unit("jackett.service") + machine.wait_for_open_port(9117) + machine.succeed("curl --fail http://localhost:9117/") ''; }) diff --git a/nixos/tests/minidlna.nix b/nixos/tests/minidlna.nix index 7bf1bed69d0..d852c7f60bc 100644 --- a/nixos/tests/minidlna.nix +++ b/nixos/tests/minidlna.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ... }: { +import ./make-test-python.nix ({ pkgs, ... }: { name = "minidlna"; nodes = { @@ -29,11 +29,11 @@ import ./make-test.nix ({ pkgs, ... }: { testScript = '' - startAll; - $server->succeed("mkdir -p /tmp/stuff && chown minidlna: /tmp/stuff"); - $server->waitForUnit("minidlna"); - $server->waitForOpenPort("8200"); - $server->succeed("curl --fail http://localhost:8200/"); - $client->succeed("curl --fail http://server:8200/"); + start_all() + server.succeed("mkdir -p /tmp/stuff && chown minidlna: /tmp/stuff") + server.wait_for_unit("minidlna") + server.wait_for_open_port("8200") + server.succeed("curl --fail http://localhost:8200/") + client.succeed("curl --fail http://server:8200/") ''; }) diff --git a/nixos/tests/miniflux.nix b/nixos/tests/miniflux.nix index 19ab4803a1d..7d83d061a9d 100644 --- a/nixos/tests/miniflux.nix +++ b/nixos/tests/miniflux.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, lib, ... }: +import ./make-test-python.nix ({ pkgs, lib, ... }: let port = 3142; @@ -37,16 +37,20 @@ with lib; }; }; testScript = '' - startAll; + start_all() - $default->waitForUnit('miniflux.service'); - $default->waitForOpenPort(${toString defaultPort}); - $default->succeed("curl --fail 'http://localhost:${toString defaultPort}/healthcheck' | grep -q OK"); - $default->succeed("curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"); + default.wait_for_unit("miniflux.service") + default.wait_for_open_port(${toString defaultPort}) + default.succeed("curl --fail 'http://localhost:${toString defaultPort}/healthcheck' | grep -q OK") + default.succeed( + "curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'" + ) - $customized->waitForUnit('miniflux.service'); - $customized->waitForOpenPort(${toString port}); - $customized->succeed("curl --fail 'http://localhost:${toString port}/healthcheck' | grep -q OK"); - $customized->succeed("curl 'http://localhost:${toString port}/v1/me' -u '${username}:${password}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"); + customized.wait_for_unit("miniflux.service") + customized.wait_for_open_port(${toString port}) + customized.succeed("curl --fail 'http://localhost:${toString port}/healthcheck' | grep -q OK") + customized.succeed( + "curl 'http://localhost:${toString port}/v1/me' -u '${username}:${password}' -H Content-Type:application/json | grep -q '\"is_admin\":true'" + ) ''; })