Commit Graph

18 Commits

Author SHA1 Message Date
Maximilian Bosch
d9befc6484 nixos/test-driver: fix deprecation behavior
We have a lot of changes in the style of

    def foo(
      self,
      new: dt.timedelta | None = None,
      old: float | None = None,
    )

which is OK for cases where the API is used as

    foo(old=23.5)

however for named arguments that actually falls short in the `ty`-stage:

    foo(23.5)

As a workaround I flipped the order of old/new and changed the type of
`old` to accept both a timedelta and the old type, i.e.

    def foo(
      self,
      old: float | dt.timedelta | None = None,
      new: dt.timedelta | None = None,
    )

and only give a deprecation warning if `old` is not of type `dt.timedelta | None`.

That way, both

    foo(old=23.5)
    foo(23.5)

are still accepted, at the same time, both

    foo(new=timedelta(...))
    foo(timedelta(...))

are OK.
2026-08-07 15:52:09 +02:00
jtrrll
f31483b7b2 nixos/test-driver: use timedelta for timeouts and durations 2026-08-05 10:07:38 -04:00
Maximilian Bosch
3e075f434a nixos/lib/nixos-test-script-prepend: fix log definition
It's an instance of AbstractLogger, not a function.
2026-05-03 15:57:18 +02:00
Jacek Galowicz
392f3f8fc1 nixos-test-driver: Use ty anf ruff instead of mypy and pyflakes 2026-05-02 15:40:02 +02:00
Maximilian Bosch
1987c483d8 nixos/test-driver: use vhost-device-vsock for SSH backdoor
`vhost-device-vsock`[1] is a custom implementation of AF_VSOCK, but the
application on the host-side uses a UNIX domain-socket. This gives us
the following nice properties:

* We don't need to do `--arg sandbox-paths /dev/vhost-vsock` anymore for
  debugging builds within the sandbox. That means, untrusted users can
  also debug these kinds of tests now.

* This prevents CID conflicts on the host-side, i.e. there's no need for
  using `sshBackdoor.vsockOffset` for tests anymore.

A big shout-out goes to Allison Karlitskaya, the developer of test.thing[2]
who talked about this approach to do AF_VSOCK on All Systems Go 2025.

This patch requires systemd 258[3] because this contains `vhost-mux` in
its SSH config which is needed to connect to the VMs from now on.

To not blow up the patches even more, this only uses AF_VSOCK for the
debugger. A potential follow-up for the future would be a removal of the
current `backdoor.service` and replace it entirely by this
functionality.

The internal implementation tries to be consistent with how VLANs and
machines are handled, i.e. the processes are started when the Driver's
context is entered and cleaned up in __exit__().

I decided to push the process management and creation of sockets for
vhost-device-vsock into its own class, that's an implementation detail
and not a concern for the test-driver. In fact, `vhost-device-vsock` is
something we can drop once QEMU implements native support for using
AF_UNIX on the host-side[4]. `VsockPair` is its own class since
returning e.g. a triple of `(Path, Path, Int)` would be ambiguous in
what is the guest and what the host path (and frankly, I found it hard
to distinguish the two when reading the docs of `vhost-device-vsock`
initially).

Finally, now that we can do the SSH backdoor without adding additional
devices to the sandbox, I figured, it's time to write a test-case for
it.

[1] https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-vsock/README.md
[2] https://codeberg.org/lis/test.thing
[3] https://github.com/NixOS/nixpkgs/pull/427968
[4] https://gitlab.com/qemu-project/qemu/-/issues/2095
2026-04-15 15:45:33 +01:00
Maximilian Bosch
01d640b494 nixos/test-driver: fix create_machine return type (#504626) 2026-04-01 13:56:06 +00:00
Alyssa Ross
5fd1a7194e nixos/test-driver: fix create_machine return type
This always returns a QemuMachine, which may need to have
QEMU-specific methods called on it.

Fixes: 23f1e6370d ("nixos/test-driver: add support for nspawn containers")
Fixes: 799cafcc23 ("nixos/test-driver: refactor Machine to BaseMachine and QemuMachine")
2026-03-29 10:32:30 +02:00
Kierán Meinhardt
ccdcdd7cb6 nixos/test-driver: provide machines, machines_qemu, machines_nspawn to testScript 2026-03-24 16:03:28 +01:00
Kierán Meinhardt
d90e24b238 nixos/test-driver: deprecate --keep-vm-state in favour of --keep-machine-state 2026-01-28 11:28:33 +01:00
Kierán Meinhardt
23f1e6370d nixos/test-driver: add support for nspawn containers
Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
2026-01-28 11:28:32 +01:00
Kierán Meinhardt
799cafcc23 nixos/test-driver: refactor Machine to BaseMachine and QemuMachine
This prepares the driver for non-QEMU backends by abstracting
the machine logic.

Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
2026-01-28 11:28:32 +01:00
Jonathan Davies
aa14673b7a nixos/test-driver: Adjust __call__ timeout parameter to match new name 2026-01-10 15:44:51 +00:00
Jacek Galowicz
d6b326d659 test-driver: Implement debugging breakpoint hooks
Co-authored-by: Maximilian Bosch <maximilian@mbosch.me>
2025-07-18 17:39:01 +02:00
Maximilian Bosch
a1dfaf51e2 nixos/test-driver: integrate Python unittest assertions
Replaces / Closes #345948

I tried to integrate `pytest` assertions because I like the reporting,
but I only managed to get the very basic thing and even that was messing
around a lot with its internals.

The approach in #345948 shifts too much maintenance effort to us, so
it's not really desirable either.

After discussing with Benoit on Ocean Sprint about this, we decided that
it's probably the best compromise to integrate `unittest`: it also
provides good diffs when needed, but the downside is that existing tests
don't benefit from it.

This patch essentially does the following things:

* Add a new global `t` that is an instance of a `unittest.TestCase`
  class. I decided to just go for `t` given that e.g.
  `tester.assertEqual` (or any other longer name) seems quite verbose.

* Use a special class for errors that get special treatment:
  * The traceback is minimized to only include frames from the
    testScript: in this case I don't really care about anything else and
    IMHO that's just visual noise.

    This is not the case for other exceptions since these may indicate a
    bug and then people should be able to send the full traceback to the
    maintainers.
  * Display the error, but with `!!!` as prefix to make sure it's
    easier to spot in between other logs.

This looks e.g. like

    !!! Traceback (most recent call last):
    !!!   File "<string>", line 7, in <module>
    !!!     foo()
    !!!   File "<string>", line 5, in foo
    !!!     t.assertEqual({"foo":[1,2,{"foo":"bar"}]},{"foo":[1,2,{"bar":"foo"}],"bar":[1,2,3,4,"foo"]})
    !!!
    !!! NixOSAssertionError: {'foo': [1, 2, {'foo': 'bar'}]} != {'foo': [1, 2, {'bar': 'foo'}], 'bar': [1, 2, 3, 4, 'foo']}
    !!! - {'foo': [1, 2, {'foo': 'bar'}]}
    !!! + {'bar': [1, 2, 3, 4, 'foo'], 'foo': [1, 2, {'bar': 'foo'}]}
    cleanup
    kill machine (pid 9)
    qemu-system-x86_64: terminating on signal 15 from pid 6 (/nix/store/wz0j2zi02rvnjiz37nn28h3gfdq61svz-python3-3.12.9/bin/python3.12)
    kill vlan (pid 7)
    (finished: cleanup, in 0.00 seconds)

Co-authored-by: bew <bew@users.noreply.github.com>
2025-03-20 12:30:58 +00:00
Stefan Hertrampf
9d90df51a9 nixos/test-driver: Separate XML and Terminal log
We use the newly AbstractLogger class and separate the XML and Terminal
logging that is currently mixed into one class. We restore the old
behavior by introducing a CompositeLogger that takes care of logging
both to terminal and XML.
2024-05-07 15:17:16 +02:00
K900
bdacdc46e4 nixos/lib/test-driver: provide legacy path for create_machine({"startCommand": "..."}) 2024-02-28 09:32:11 +03:00
K900
423098c284 nixos/lib/test-driver: drop LegacyStartCommand, clean up create_machine API
We can finally do this now that it's no longer used.
2024-02-27 23:15:59 +03:00
Michael Schneider
814027378b nixos/test-driver: Typecheck TestScript 2022-06-02 10:05:45 +02:00