Merge pull request #78241 from andrew-d/andrew/systemd-tests-python
nixosTests.systemd: port to Python
This commit is contained in:
commit
b46a1b5dec
1 changed files with 55 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
||||||
import ./make-test.nix ({ pkgs, ... }: {
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
name = "systemd";
|
name = "systemd";
|
||||||
|
|
||||||
machine = { lib, ... }: {
|
machine = { lib, ... }: {
|
||||||
|
@ -53,50 +53,69 @@ import ./make-test.nix ({ pkgs, ... }: {
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
$machine->waitForX;
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
machine.wait_for_x()
|
||||||
# wait for user services
|
# wait for user services
|
||||||
$machine->waitForUnit("default.target","alice");
|
machine.wait_for_unit("default.target", "alice")
|
||||||
|
|
||||||
# Regression test for https://github.com/NixOS/nixpkgs/issues/35415
|
# Regression test for https://github.com/NixOS/nixpkgs/issues/35415
|
||||||
subtest "configuration files are recognized by systemd", sub {
|
with subtest("configuration files are recognized by systemd"):
|
||||||
$machine->succeed('test -e /system_conf_read');
|
machine.succeed("test -e /system_conf_read")
|
||||||
$machine->succeed('test -e /home/alice/user_conf_read');
|
machine.succeed("test -e /home/alice/user_conf_read")
|
||||||
$machine->succeed('test -z $(ls -1 /var/log/journal)');
|
machine.succeed("test -z $(ls -1 /var/log/journal)")
|
||||||
};
|
|
||||||
|
|
||||||
# Regression test for https://github.com/NixOS/nixpkgs/issues/50273
|
# Regression test for https://github.com/NixOS/nixpkgs/issues/50273
|
||||||
subtest "DynamicUser actually allocates a user", sub {
|
with subtest("DynamicUser actually allocates a user"):
|
||||||
$machine->succeed('systemd-run --pty --property=Type=oneshot --property=DynamicUser=yes --property=User=iamatest whoami | grep iamatest');
|
assert "iamatest" in machine.succeed(
|
||||||
};
|
"systemd-run --pty --property=Type=oneshot --property=DynamicUser=yes --property=User=iamatest whoami"
|
||||||
|
)
|
||||||
|
|
||||||
# Regression test for https://github.com/NixOS/nixpkgs/issues/35268
|
# Regression test for https://github.com/NixOS/nixpkgs/issues/35268
|
||||||
subtest "file system with x-initrd.mount is not unmounted", sub {
|
with subtest("file system with x-initrd.mount is not unmounted"):
|
||||||
$machine->succeed('mountpoint -q /test-x-initrd-mount');
|
machine.succeed("mountpoint -q /test-x-initrd-mount")
|
||||||
$machine->shutdown;
|
machine.shutdown()
|
||||||
system('qemu-img', 'convert', '-O', 'raw',
|
|
||||||
'vm-state-machine/empty2.qcow2', 'x-initrd-mount.raw');
|
|
||||||
my $extinfo = `${pkgs.e2fsprogs}/bin/dumpe2fs x-initrd-mount.raw`;
|
|
||||||
die "File system was not cleanly unmounted: $extinfo"
|
|
||||||
unless $extinfo =~ /^Filesystem state: *clean$/m;
|
|
||||||
};
|
|
||||||
|
|
||||||
subtest "systemd-shutdown works", sub {
|
subprocess.check_call(
|
||||||
$machine->shutdown;
|
[
|
||||||
$machine->waitForUnit('multi-user.target');
|
"qemu-img",
|
||||||
$machine->succeed('test -e /tmp/shared/shutdown-test');
|
"convert",
|
||||||
};
|
"-O",
|
||||||
|
"raw",
|
||||||
|
"vm-state-machine/empty0.qcow2",
|
||||||
|
"x-initrd-mount.raw",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
extinfo = subprocess.check_output(
|
||||||
|
[
|
||||||
|
"${pkgs.e2fsprogs}/bin/dumpe2fs",
|
||||||
|
"x-initrd-mount.raw",
|
||||||
|
]
|
||||||
|
).decode("utf-8")
|
||||||
|
assert (
|
||||||
|
re.search(r"^Filesystem state: *clean$", extinfo, re.MULTILINE) is not None
|
||||||
|
), ("File system was not cleanly unmounted: " + extinfo)
|
||||||
|
|
||||||
# Test settings from /etc/sysctl.d/50-default.conf are applied
|
with subtest("systemd-shutdown works"):
|
||||||
subtest "systemd sysctl settings are applied", sub {
|
machine.shutdown()
|
||||||
$machine->waitForUnit('multi-user.target');
|
machine.wait_for_unit("multi-user.target")
|
||||||
$machine->succeed('sysctl net.core.default_qdisc | grep -q "fq_codel"');
|
machine.succeed("test -e /tmp/shared/shutdown-test")
|
||||||
};
|
|
||||||
|
|
||||||
# Test cgroup accounting is enabled
|
# Test settings from /etc/sysctl.d/50-default.conf are applied
|
||||||
subtest "systemd cgroup accounting is enabled", sub {
|
with subtest("systemd sysctl settings are applied"):
|
||||||
$machine->waitForUnit('multi-user.target');
|
machine.wait_for_unit("multi-user.target")
|
||||||
$machine->succeed('systemctl show testservice1.service -p IOAccounting | grep -q "yes"');
|
assert "fq_codel" in machine.succeed("sysctl net.core.default_qdisc")
|
||||||
$machine->succeed('systemctl status testservice1.service | grep -q "CPU:"');
|
|
||||||
};
|
# Test cgroup accounting is enabled
|
||||||
|
with subtest("systemd cgroup accounting is enabled"):
|
||||||
|
machine.wait_for_unit("multi-user.target")
|
||||||
|
assert "yes" in machine.succeed(
|
||||||
|
"systemctl show testservice1.service -p IOAccounting"
|
||||||
|
)
|
||||||
|
|
||||||
|
retcode, output = machine.execute("systemctl status testservice1.service")
|
||||||
|
assert retcode in [0, 3] # https://bugs.freedesktop.org/show_bug.cgi?id=77507
|
||||||
|
assert "CPU:" in output
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue