NixOS VM tests: Difference between revisions

From NixOS Wiki
imported>Teto
random notes as I was trying to reuse the nixos test infra (especially the VDE logic) within nixos-shell
 
imported>Teto
m cleanup
Line 7: Line 7:


The driver (of the form /nix/store/668bqxvsv6rn9hy8n4nmaps9ma2i5k4r-nixos-test-driver-<TESTNAME>) will launch the different vms passed as arguments.
The driver (of the form /nix/store/668bqxvsv6rn9hy8n4nmaps9ma2i5k4r-nixos-test-driver-<TESTNAME>) will launch the different vms passed as arguments.
This is the role of the wrapper bin/nixos-run-vms to start the driver with the correct VM script as arguments.
The wrapper `bin/nixos-run-vms` is in charge to start the driver with the correct VM script as arguments.


If only one VM is specified then, the driver will drop you into
Once the driver is loaded, depending on the environment variables `tests` it will run in an interactive mode or run some perl code (`testScript`).
In interactive mode, you can run `startAll` followed by `joinAll` to start and keep the VM alive


Once the driver


How to debug tests ?
== How to debug tests ? ==
 
You can run the tests interactively as described in nixos manual.
You can run the tests interactively as described in nixos manual.
When you run `nix-build ./nixos/tests/login.nix`, the resulting output gives you a summary of the results, but to gain access to the VM, you can run `nix repl ./nixos/tests/login.nix` and see the ran VM via `driver.outPath`.
When you run `nix-build ./nixos/tests/login.nix`, the resulting output gives you a summary of the results, but to gain access to the VM, you can run `nix repl ./nixos/tests/login.nix` and see the ran VM via `driver.outPath`.

Revision as of 10:04, 8 July 2019

The test infrastructure entry point is nixos/lib/testing.nix. The test infra relies on the qemu build-vm code to generate virtual machines.

It will generate a test driver (a wrapper of nixos/lib/test-driver/test-driver.pl) in charge of creating the network. It will start one vde-switch and its associated socket per vlan (defined in virtualisation.vlans). IPs are assigned declaratively according to the number of vlan via the function `assignIPAddresses`.

The driver (of the form /nix/store/668bqxvsv6rn9hy8n4nmaps9ma2i5k4r-nixos-test-driver-<TESTNAME>) will launch the different vms passed as arguments. The wrapper `bin/nixos-run-vms` is in charge to start the driver with the correct VM script as arguments.

Once the driver is loaded, depending on the environment variables `tests` it will run in an interactive mode or run some perl code (`testScript`). In interactive mode, you can run `startAll` followed by `joinAll` to start and keep the VM alive


How to debug tests ?

You can run the tests interactively as described in nixos manual. When you run `nix-build ./nixos/tests/login.nix`, the resulting output gives you a summary of the results, but to gain access to the VM, you can run `nix repl ./nixos/tests/login.nix` and see the ran VM via `driver.outPath`.