NixOS VM tests: Difference between revisions
imported>Teto updated it to reflect some python changes |
imported>Roberth Link to docs and add nixosTest |
||
Line 1: | Line 1: | ||
The test infrastructure entry point is nixos/lib/testing.nix. | The primary documentation for the [https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests NixOS VM testing framework] is in [https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests the NixOS manual]. | ||
The test infrastructure entry point is nixos/lib/testing.nix. Alternatively, for out-of-tree tests you can invoke it via Nixpkgs as the nixosTest function, which reuses your already evaluated Nixpkgs to generate your node configurations. | |||
The test infra relies on the qemu build-vm code to generate virtual machines. | The test infra relies on the qemu build-vm code to generate virtual machines. | ||
Revision as of 00:29, 5 November 2021
The primary documentation for the NixOS VM testing framework is in the NixOS manual.
The test infrastructure entry point is nixos/lib/testing.nix. Alternatively, for out-of-tree tests you can invoke it via Nixpkgs as the nixosTest function, which reuses your already evaluated Nixpkgs to generate your node configurations. 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.py) 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 `start_all` followed by `join_all` to start and keep the VM alive
How to debug tests ?
You can run the tests interactively as described in [1]. 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`.
I don't see any prompt ? (qemu window pitch black)
Check the output for `malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "\x{0}\x{0}\x{0}\x{0}...") at /nix/store/1hkp2n6hz3ybf2rvkjkwrzgbjkrrakzl-update-users-groups.pl line 11`. You should purge the state present in rm -rf /tmp/vm-state-<VM_NAME>
Setting `virtualisation.vlans` does not create the expected interfaces
There are two sides to the problem: 1. By default the qemu-vm setups a `user` based nic: virtualisation.qemu.networkingOptions. You need to override the option to get rid of this interface. 2. As of this writing nixpkgs will generate interfaces starting from `eth1` (instead of `eth0`).
Keys: https://en.wikibooks.org/wiki/QEMU/Monitor#sendkey_keys