diff --git a/nixos/doc/manual/development/running-nixos-tests-interactively.xml b/nixos/doc/manual/development/running-nixos-tests-interactively.xml index e390d62fde2..ea3ba0e4bf7 100644 --- a/nixos/doc/manual/development/running-nixos-tests-interactively.xml +++ b/nixos/doc/manual/development/running-nixos-tests-interactively.xml @@ -14,14 +14,14 @@ starting VDE switch for network 1 > - You can then take any Perl statement, e.g. + You can then take any Python statement, e.g. -> startAll -> testScript -> $machine->succeed("touch /tmp/foo") -> print($machine->succeed("pwd")) # Show stdout of command +> start_all() +> test_script() +> machine.succeed("touch /tmp/foo") +> print(machine.succeed("pwd")) # Show stdout of command - The function testScript executes the entire test script + The function test_script executes the entire test script and drops you back into the test driver command line upon its completion. This allows you to inspect the state of the VMs after the test (e.g. to debug the test script). diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml index 6be2d0a4d23..24efd2e3273 100644 --- a/nixos/doc/manual/development/writing-nixos-tests.xml +++ b/nixos/doc/manual/development/writing-nixos-tests.xml @@ -8,7 +8,7 @@ A NixOS test is a Nix expression that has the following structure: -import ./make-test.nix { +import ./make-test-python.nix { # Either the configuration of a single machine: machine = @@ -27,11 +27,11 @@ import ./make-test.nix { testScript = '' - Perl code… + Python code… ''; } - The attribute testScript is a bit of Perl code that + The attribute testScript is a bit of Python code that executes the test (described below). During the test, it will start one or more virtual machines, the configuration of which is described by the attribute machine (if you need only one machine in your @@ -96,26 +96,27 @@ xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualis - The test script is a sequence of Perl statements that perform various + The test script is a sequence of Python statements that perform various actions, such as starting VMs, executing commands in the VMs, and so on. Each virtual machine is represented as an object stored in the variable - $name, where - name is the identifier of the machine (which is - just machine if you didn’t specify multiple machines - using the nodes attribute). For instance, the following - starts the machine, waits until it has finished booting, then executes a - command and checks that the output is more-or-less correct: + name if this is also the + identifier of the machine in the declarative config. + If you didn't specify multiple machines using the nodes + attribute, it is just machine. + The following example starts the machine, waits until it has finished booting, + then executes a command and checks that the output is more-or-less correct: -$machine->start; -$machine->waitForUnit("default.target"); -$machine->succeed("uname") =~ /Linux/ or die; +machine.start() +machine.wait_for_unit("default.target") +if not "Linux" in machine.succeed("uname"): + raise Exception("Wrong OS") The first line is actually unnecessary; machines are implicitly started when - you first execute an action on them (such as waitForUnit + you first execute an action on them (such as wait_for_unit or succeed). If you have multiple machines, you can speed up the test by starting them in parallel: -startAll; +start_all() @@ -187,7 +188,7 @@ startAll; - getScreenText + get_screen_text @@ -204,7 +205,7 @@ startAll; - sendMonitorCommand + send_monitor_command @@ -215,23 +216,23 @@ startAll; - sendKeys + send_keys Simulate pressing keys on the virtual keyboard, e.g., - sendKeys("ctrl-alt-delete"). + send_keys("ctrl-alt-delete"). - sendChars + send_chars Simulate typing a sequence of characters on the virtual keyboard, e.g., - sendKeys("foobar\n") will type the string + send_keys("foobar\n") will type the string foobar followed by the Enter key. @@ -272,7 +273,7 @@ startAll; - waitUntilSucceeds + wait_until_succeeds @@ -282,7 +283,7 @@ startAll; - waitUntilFails + wait_until_fails @@ -292,7 +293,7 @@ startAll; - waitForUnit + wait_for_unit @@ -302,7 +303,7 @@ startAll; - waitForFile + wait_for_file @@ -312,7 +313,7 @@ startAll; - waitForOpenPort + wait_for_open_port @@ -323,7 +324,7 @@ startAll; - waitForClosedPort + wait_for_closed_port @@ -333,7 +334,7 @@ startAll; - waitForX + wait_for_x @@ -343,13 +344,13 @@ startAll; - waitForText + wait_for_text Wait until the supplied regular expressions matches the textual contents of the screen by using optical character recognition (see - getScreenText). + get_screen_text). @@ -361,23 +362,23 @@ startAll; - waitForWindow + wait_for_window Wait until an X11 window has appeared whose name matches the given - regular expression, e.g., waitForWindow(qr/Terminal/). + regular expression, e.g., wait_for_window("Terminal"). - copyFileFromHost + copy_file_from_host Copies a file from host to machine, e.g., - copyFileFromHost("myfile", "/etc/my/important/file"). + copy_file_from_host("myfile", "/etc/my/important/file"). The first argument is the file on the host. The file needs to be @@ -397,8 +398,8 @@ startAll; -$machine->systemctl("list-jobs --no-pager"); // runs `systemctl list-jobs --no-pager` -$machine->systemctl("list-jobs --no-pager", "any-user"); // spawns a shell for `any-user` and runs `systemctl --user list-jobs --no-pager` +machine.systemctl("list-jobs --no-pager") # runs `systemctl list-jobs --no-pager` +machine.systemctl("list-jobs --no-pager", "any-user") # spawns a shell for `any-user` and runs `systemctl --user list-jobs --no-pager` @@ -408,14 +409,14 @@ $machine->systemctl("list-jobs --no-pager", "any-user"); // spawns a shell for ` To test user units declared by systemd.user.services the - optional $user argument can be used: + optional user argument can be used: -$machine->start; -$machine->waitForX; -$machine->waitForUnit("xautolock.service", "x-session-user"); +machine.start() +machine.wait_for_x() +machine.wait_for_unit("xautolock.service", "x-session-user") - This applies to systemctl, getUnitInfo, - waitForUnit, startJob and - stopJob. + This applies to systemctl, get_unit_info, + wait_for_unit, start_job and + stop_job.