NixOS VM tests: Difference between revisions
imported>Asdf8dfafjk m link to keys |
imported>Teto updated it to reflect some python changes |
||
| Line 2: | Line 2: | ||
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. | ||
It will generate a test driver (a wrapper of nixos/lib/test-driver/test-driver. | 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). | 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`. | IPs are assigned declaratively according to the number of vlan via the function `assignIPAddresses`. | ||
| Line 10: | Line 10: | ||
Once the driver is loaded, depending on the environment variables `tests` it will run in an interactive mode or run some perl code (`testScript`). | 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 ` | In interactive mode, you can run `start_all` followed by `join_all` to start and keep the VM alive | ||
== 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 [https://nixos.org/manual/nixos/stable/index.html#sec-running-nixos-tests-interactively]. | ||
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 | 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`. | |||
| Line 24: | Line 26: | ||
You should purge the state present in rm -rf /tmp/vm-state-<VM_NAME> | 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: | 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. | 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. | ||