summary refs log tree commit diff
path: root/nixos/tests/systemd.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-08-31 06:30:50 +0200
committerSamuel Leathers <disasm@gmail.com>2019-08-31 00:30:50 -0400
commitd7c7fc460300e30cbb105bf2e0d9021f368be492 (patch)
tree8dfd0c7d6277b0446f0a040445edb3127b2ba0bb /nixos/tests/systemd.nix
parent5a581c420c33f1188484f9d45d1cba6e97ae1d45 (diff)
downloadnixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar.gz
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar.bz2
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar.lz
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar.xz
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.tar.zst
nixpkgs-d7c7fc460300e30cbb105bf2e0d9021f368be492.zip
nixos/tests/systemd: Fix x-initrd-mount flakiness (#67798)
It turns out that checking for the last mount time of an ext4 file
system isn't a very reliable way to check whether the file system was
properly unmounted.

When creating that test in the first place (88530e02b6fa9b5429dc09972b),
I was reluctant to inspect the file system when the VM is down and was
searching for a way to check for a clean unmount *after* the file system
was mounted again to make sure we don't need to create a 512 MB raw
image on the host.

Fortunately however, when converting from qcow2, qemu-img actually
writes a sparse file, so for most file systems (that is, file systems
supporting sparse files) this shouldn't waste a lot of disk space.

So when investigating the flakiness, I found that whenever the test is
failing, the unmount of /test-x-initrd-mount was done *before* the final
step during which systemd remounts+unmounts all the remaining file
systems.

I haven't investigated why this is the case, but the test is a
regression test for https://github.com/NixOS/nixpkgs/issues/35268, which
actually didn't unmount the file system *at* *all*, so really all we
need to take care here is whether the unmount has happened and not
*how*.

To make sure that checking the filesystem state is enough for this, I
temporarily replaced the $machine->shutdown call with $machine->crash
and verified that the file system state is "not clean".

Signed-off-by: aszlig <aszlig@nix.build>
Fixes: https://github.com/NixOS/nixpkgs/issues/67555
Diffstat (limited to 'nixos/tests/systemd.nix')
-rw-r--r--nixos/tests/systemd.nix10
1 files changed, 6 insertions, 4 deletions
diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix
index 1c201e3b5dc..4b71b4d6759 100644
--- a/nixos/tests/systemd.nix
+++ b/nixos/tests/systemd.nix
@@ -71,11 +71,13 @@ import ./make-test.nix ({ pkgs, ... }: {
 
     # Regression test for https://github.com/NixOS/nixpkgs/issues/35268
     subtest "file system with x-initrd.mount is not unmounted", sub {
+      $machine->succeed('mountpoint -q /test-x-initrd-mount');
       $machine->shutdown;
-      $machine->waitForUnit('multi-user.target');
-      # If the file system was unmounted during the shutdown the file system
-      # has a last mount time, because the file system wasn't checked.
-      $machine->fail('dumpe2fs /dev/vdb | grep -q "^Last mount time: *n/a"');
+      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 {