New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test-driver: support testing user units #32845
Conversation
77d8c9d
to
0392283
Compare
To avoid any breaks I just checked some tests: the one I described above, the rabbitmq test and the statsd test (all of them use the |
0392283
to
116e892
Compare
nixos/lib/test-driver/Machine.pm
Outdated
$cmd = "XDG_RUNTIME_DIR=/run/user/`id -u` systemctl --user"; | ||
} | ||
|
||
my ($status, $lines) = $self->execute("su -l $user -c '$cmd $q'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we run into shell quoting issues, since a second shell is spawned?
116e892
to
90de1af
Compare
@Mic92 you're right. I changed the |
It is quite complicated to test services using the test-driver when declaring user services with `systemd.user.services` such as many X11-based services like `xautolock.service`. This change adds an optional `$user` parameter to each systemd-related function in the test-driver and runs `systemctl --user` commands using `su -l $user -c ...` and sets the `XDG_RUNTIME_DIR` variable accordingly and a new function named `systemctl` which is able to run a systemd command with or without a specified user. The change can be confirmed with a simple VM declaration like this: ``` import ./nixos/tests/make-test.nix ({ pkgs, lib }: with lib; { name = "systemd-user-test"; nodes.machine = { imports = [ ./nixos/tests/common/user-account.nix ]; services.xserver.enable = true; services.xserver.displayManager.auto.enable = true; services.xserver.displayManager.auto.user = "bob"; services.xserver.xautolock.enable = true; }; testScript = '' $machine->start; $machine->waitForX; $machine->waitForUnit("xautolock.service", "bob"); $machine->stopJob("xautolock.service", "bob"); $machine->startJob("xautolock.service", "bob"); $machine->systemctl("list-jobs --no-pager", "bob"); $machine->systemctl("show 'xautolock.service' --no-pager", "bob"); ''; }) ```
90de1af
to
e538e00
Compare
Motivation for this change
It is quite complicated to test services using the test-driver when
declaring user services with
systemd.user.services
such as manyX11-based services like
xautolock.service
.This change adds an optional
$user
parameter to each systemd-relatedfunction in the test-driver and runs
systemctl --user
commands usingsu -l $user -c ...
and sets theXDG_RUNTIME_DIR
variableaccordingly and a new function named
systemctl
which is able to run asystemd command with or without a specified user.
The change can be confirmed with a simple VM declaration like this:
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)