···55```nix
66import ./make-test-python.nix {
7788- # Either the configuration of a single machine:
99- machine =
1010- { config, pkgs, ... }:
1111- { configuration…
1212- };
1313-1414- # Or a set of machines:
88+ # One or more machines:
159 nodes =
1616- { machine1 =
1010+ { machine =
1711 { config, pkgs, ... }: { … };
1812 machine2 =
1913 { config, pkgs, ... }: { … };
···29233024The attribute `testScript` is a bit of Python code that executes the
3125test (described below). During the test, it will start one or more
3232-virtual machines, the configuration of which is described by the
3333-attribute `machine` (if you need only one machine in your test) or by
3434-the attribute `nodes` (if you need multiple machines). For instance,
3535-[`login.nix`](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix)
3636-only needs a single machine to test whether users can log in
2626+virtual machines, the configuration of which is described by
2727+the attribute `nodes`.
2828+2929+An example of a single-node test is
3030+[`login.nix`](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix).
3131+It only needs a single machine to test whether users can log in
3732on the virtual console, whether device ownership is correctly maintained
3838-when switching between consoles, and so on. On the other hand,
3939-[`nfs/simple.nix`](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nfs/simple.nix),
4040-which tests NFS client and server functionality in the
4141-Linux kernel (including whether locks are maintained across server
4242-crashes), requires three machines: a server and two clients.
3333+when switching between consoles, and so on. An interesting multi-node test is
3434+[`nfs/simple.nix`](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nfs/simple.nix).
3535+It uses two client nodes to test correct locking across server crashes.
43364437There are a few special NixOS configuration options for test VMs:
4538···6760actions, such as starting VMs, executing commands in the VMs, and so on.
6861Each virtual machine is represented as an object stored in the variable
6962`name` if this is also the identifier of the machine in the declarative
7070-config. If you didn\'t specify multiple machines using the `nodes`
7171-attribute, it is just `machine`. The following example starts the
6363+config. If you specified a node `nodes.machine`, the following example starts the
7264machine, waits until it has finished booting, then executes a command
7365and checks that the output is more-or-less correct:
7466···7971 raise Exception("Wrong OS")
8072```
81738282-The first line is actually unnecessary; machines are implicitly started
7474+The first line is technically unnecessary; machines are implicitly started
8375when you first execute an action on them (such as `wait_for_unit` or
8476`succeed`). If you have multiple machines, you can speed up the test by
8577starting them in parallel:
···303295```nix
304296import ./make-test-python.nix {
305297 skipLint = true;
306306- machine =
298298+ nodes.machine =
307299 { config, pkgs, ... }:
308300 { configuration…
309301 };
···66 <programlisting language="bash">
77import ./make-test-python.nix {
8899- # Either the configuration of a single machine:
1010- machine =
1111- { config, pkgs, ... }:
1212- { configuration…
1313- };
1414-1515- # Or a set of machines:
99+ # One or more machines:
1610 nodes =
1717- { machine1 =
1111+ { machine =
1812 { config, pkgs, ... }: { … };
1913 machine2 =
2014 { config, pkgs, ... }: { … };
···3125 The attribute <literal>testScript</literal> is a bit of Python code
3226 that executes the test (described below). During the test, it will
3327 start one or more virtual machines, the configuration of which is
3434- described by the attribute <literal>machine</literal> (if you need
3535- only one machine in your test) or by the attribute
3636- <literal>nodes</literal> (if you need multiple machines). For
3737- instance,
3838- <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix"><literal>login.nix</literal></link>
3939- only needs a single machine to test whether users can log in on the
4040- virtual console, whether device ownership is correctly maintained
4141- when switching between consoles, and so on. On the other hand,
4242- <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nfs/simple.nix"><literal>nfs/simple.nix</literal></link>,
4343- which tests NFS client and server functionality in the Linux kernel
4444- (including whether locks are maintained across server crashes),
4545- requires three machines: a server and two clients.
2828+ described by the attribute <literal>nodes</literal>.
2929+ </para>
3030+ <para>
3131+ An example of a single-node test is
3232+ <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix"><literal>login.nix</literal></link>.
3333+ It only needs a single machine to test whether users can log in on
3434+ the virtual console, whether device ownership is correctly
3535+ maintained when switching between consoles, and so on. An
3636+ interesting multi-node test is
3737+ <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nfs/simple.nix"><literal>nfs/simple.nix</literal></link>.
3838+ It uses two client nodes to test correct locking across server
3939+ crashes.
4640 </para>
4741 <para>
4842 There are a few special NixOS configuration options for test VMs:
···9488 various actions, such as starting VMs, executing commands in the
9589 VMs, and so on. Each virtual machine is represented as an object
9690 stored in the variable <literal>name</literal> if this is also the
9797- identifier of the machine in the declarative config. If you didn't
9898- specify multiple machines using the <literal>nodes</literal>
9999- attribute, it is just <literal>machine</literal>. The following
9191+ identifier of the machine in the declarative config. If you
9292+ specified a node <literal>nodes.machine</literal>, the following
10093 example starts the machine, waits until it has finished booting,
10194 then executes a command and checks that the output is more-or-less
10295 correct:
···108101 raise Exception("Wrong OS")
109102</programlisting>
110103 <para>
111111- The first line is actually unnecessary; machines are implicitly
104104+ The first line is technically unnecessary; machines are implicitly
112105 started when you first execute an action on them (such as
113106 <literal>wait_for_unit</literal> or <literal>succeed</literal>). If
114107 you have multiple machines, you can speed up the test by starting
···554547 <programlisting language="bash">
555548import ./make-test-python.nix {
556549 skipLint = true;
557557- machine =
550550+ nodes.machine =
558551 { config, pkgs, ... }:
559552 { configuration…
560553 };
+1
nixos/lib/testing-python.nix
···206206 )];
207207 };
208208 in
209209+ lib.warnIf (t?machine) "In test `${name}': The `machine' attribute in NixOS tests (pkgs.nixosTest / make-test-pyton.nix / testing-python.nix / makeTest) is deprecated. Please use the equivalent `nodes.machine'."
209210 build-vms.buildVirtualNetwork (
210211 nodes // lib.optionalAttrs (machine != null) { inherit machine; }
211212 );