about summary refs log tree commit diff
path: root/tests/aszlig/dnyarri
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2020-08-29 00:57:47 +0200
committeraszlig <aszlig@nix.build>2020-08-29 01:08:17 +0200
commit0e72073cb6b5f2d6c3b1ec0eb87412dce809f48c (patch)
treeeb28b1d0d148821d46fa11a84dae5ccfa1d73643 /tests/aszlig/dnyarri
parentecbf74ae6117197f3b7560753f7db73e363f5991 (diff)
tests: Switch all tests to Python test driver
Since the removal[1] of the Perl test driver, our tests will no longer
run or even evaluate.

Fortunately, the test API is more or less the same, so the transition to
Python was not very involved.

However, I did add a "# fmt: off" on top of every testScript, since
formatting with black not only has issues with parameterised
antiquotations but is also plain ugly to mix 2 spaces of indentation
with 4 spaces of indentation.

Additionally, I'd like to have a maximum line length of 79 characters in
my Nix expressions while black on the other side even *insists* of using
longer lines.

[1]: https://github.com/NixOS/nixpkgs/commit/0620184f3f94f1bf8de014ab168

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'tests/aszlig/dnyarri')
-rw-r--r--tests/aszlig/dnyarri/luks2-bcache.nix143
1 files changed, 67 insertions, 76 deletions
diff --git a/tests/aszlig/dnyarri/luks2-bcache.nix b/tests/aszlig/dnyarri/luks2-bcache.nix
index 0347a0da..1c7fd5fc 100644
--- a/tests/aszlig/dnyarri/luks2-bcache.nix
+++ b/tests/aszlig/dnyarri/luks2-bcache.nix
@@ -37,33 +37,32 @@
     uuid1 = "07b821b9-0912-4f03-9ebc-89f41704caff";
     uuid2 = "d140fd40-bb3c-48b5-98e0-b75878dbce66";
   in ''
-    $machine->waitForUnit('multi-user.target');
+    # fmt: off
+    machine.wait_for_unit('multi-user.target')
 
-    $machine->nest('setting up LUKS2 and bcache backing devices', sub {
-      $machine->succeed('dd if=/dev/urandom of=/dev/vdb bs=1 count=200');
+    with machine.nested('setting up LUKS2 and bcache backing devices'):
+      machine.succeed('dd if=/dev/urandom of=/dev/vdb bs=1 count=200')
 
-      $machine->succeed('make-bcache -B /dev/vdc');
-      $machine->succeed('make-bcache -B /dev/vdd');
+      machine.succeed('make-bcache -B /dev/vdc')
+      machine.succeed('make-bcache -B /dev/vdd')
 
-      $machine->waitUntilSucceeds(
+      machine.wait_until_succeeds(
         '[ $(echo /dev/bcache[0-9]* | wc -w) -eq 2 ]'
-      );
-      my $bcache1 = $machine->succeed('ls -1 /dev/bcache[0-9]* | head -n1');
-      chomp $bcache1;
-      my $bcache2 = $machine->succeed('ls -1 /dev/bcache[0-9]* | tail -n1');
-      chomp $bcache2;
-
-      $machine->succeed(
-        "${luksFormat} $bcache1 --uuid ${uuid1} /dev/vdb",
-        "cryptsetup open $bcache1 l1 --key-file=/dev/vdb",
-      );
-
-      $machine->succeed(
-        "${luksFormat} $bcache2 --uuid ${uuid2} /dev/vdb",
-        "cryptsetup open $bcache2 l2 --key-file=/dev/vdb",
-      );
-
-      $machine->succeed(
+      )
+      bcache1 = machine.succeed('ls -1 /dev/bcache[0-9]* | head -n1').strip()
+      bcache2 = machine.succeed('ls -1 /dev/bcache[0-9]* | tail -n1').strip()
+
+      machine.succeed(
+        f"${luksFormat} {bcache1} --uuid ${uuid1} /dev/vdb",
+        f"cryptsetup open {bcache1} l1 --key-file=/dev/vdb",
+      )
+
+      machine.succeed(
+        f"${luksFormat} {bcache2} --uuid ${uuid2} /dev/vdb",
+        f"cryptsetup open {bcache2} l2 --key-file=/dev/vdb",
+      )
+
+      machine.succeed(
         'mkfs.btrfs -L testfs -m raid1 -d raid1 /dev/mapper/l1 /dev/mapper/l2',
         'btrfs dev scan',
         'mkdir /mnt-test',
@@ -72,61 +71,53 @@
         'umount /mnt-test',
         'cryptsetup close l1',
         'cryptsetup close l2',
-      );
-    });
-
-    $machine->nest('rebooting into new configuration', sub {
-      $machine->shutdown;
-      $newmachine->{stateDir} = $machine->{stateDir};
-      $newmachine->waitForUnit('multi-user.target');
-    });
-
-    my $bcache1 =
-      $newmachine->succeed('cd /dev; ls -1 bcache[0-9]* | head -n1');
-    chomp $bcache1;
-    my $bcache2 =
-      $newmachine->succeed('cd /dev; ls -1 bcache[0-9]* | tail -n1');
-    chomp $bcache2;
-
-    $machine->nest('attaching bcache cache device', sub {
-      my $csetuuid = $newmachine->succeed(
+      )
+
+    with machine.nested('rebooting into new configuration'):
+      machine.shutdown()
+      newmachine.state_dir = machine.state_dir
+      newmachine.wait_for_unit('multi-user.target')
+
+    bcache1 = newmachine.succeed(
+      'cd /dev; ls -1 bcache[0-9]* | head -n1'
+    ).strip()
+    bcache2 = newmachine.succeed(
+      'cd /dev; ls -1 bcache[0-9]* | tail -n1'
+    ).strip()
+
+    with machine.nested('attaching bcache cache device'):
+      csetuuid = newmachine.succeed(
         'make-bcache -C /dev/vde | sed -n -e "s/^Set UUID:[^a-f0-9]*//p"'
-      );
-      chomp $csetuuid;
-
-      $newmachine->nest('wait for cache device to appear', sub {
-        $newmachine->waitUntilSucceeds("test -e /sys/fs/bcache/$csetuuid");
-      });
-
-      $newmachine->succeed(
-        "echo $csetuuid > /sys/block/$bcache1/bcache/attach",
-        "echo writeback > /sys/block/$bcache1/bcache/cache_mode",
-        "echo $csetuuid > /sys/block/$bcache2/bcache/attach",
-        "echo writeback > /sys/block/$bcache2/bcache/cache_mode"
-      );
-    });
-
-    $machine->nest('write random files to test file system', sub {
-      $newmachine->succeed(
-        'for i in $(seq 100); do'.
-        ' dd if=/dev/urandom of="/test/randfile.$i" bs=1 count=100;'.
-        ' sha256sum "/test/randfile.$i" > "/test/randfile.$i.sha256"; '.
+      ).strip()
+
+      with newmachine.nested('wait for cache device to appear'):
+        newmachine.wait_until_succeeds(f"test -e /sys/fs/bcache/{csetuuid}")
+
+      newmachine.succeed(
+        f"echo {csetuuid} > /sys/block/{bcache1}/bcache/attach",
+        f"echo writeback > /sys/block/{bcache1}/bcache/cache_mode",
+        f"echo {csetuuid} > /sys/block/{bcache2}/bcache/attach",
+        f"echo writeback > /sys/block/{bcache2}/bcache/cache_mode",
+      )
+
+    with machine.nested('write random files to test file system'):
+      newmachine.succeed(
+        'for i in $(seq 100); do'
+        ' dd if=/dev/urandom of="/test/randfile.$i" bs=1 count=100;'
+        ' sha256sum "/test/randfile.$i" > "/test/randfile.$i.sha256"; '
         'done'
-      );
-    });
-
-    $machine->nest('reboot to clear disk buffers', sub {
-      $newmachine->shutdown;
-      $newmachine->waitForUnit('multi-user.target');
-    });
-
-    $machine->nest('verifying contents of random files created earlier', sub {
-      $newmachine->succeed(
-        'for i in $(seq 100); do'.
-        ' sha256sum "/test/randfile.$i" | cmp - "/test/randfile.$i.sha256"'.
-        ' || exit 1; '.
+      )
+
+    with machine.nested('reboot to clear disk buffers'):
+      newmachine.shutdown()
+      newmachine.wait_for_unit('multi-user.target')
+
+    with machine.nested('verifying contents of random files created earlier'):
+      newmachine.succeed(
+        'for i in $(seq 100); do'
+        ' sha256sum "/test/randfile.$i" | cmp - "/test/randfile.$i.sha256"'
+        ' || exit 1; '
         'done'
-      );
-    });
+      )
   '';
 }