|
| 1 | +{ |
| 2 | + pkgs ? import <nixpkgs> { }, |
| 3 | + diskoLib ? pkgs.callPackage ../lib { }, |
| 4 | +}: |
| 5 | +diskoLib.testLib.makeDiskoTest { |
| 6 | + inherit pkgs; |
| 7 | + name = "zfs-multi-raidz3"; |
| 8 | + disko-config = ../example/zfs-multi-raidz3.nix; |
| 9 | + extraInstallerConfig.networking.hostId = "8425e349"; |
| 10 | + extraSystemConfig = { |
| 11 | + networking.hostId = "8425e349"; |
| 12 | + # It looks like the 60s of NixOS is sometimes not enough for our virtio-based zpool. |
| 13 | + # This fixes the flakeiness of the test. |
| 14 | + boot.initrd.postResumeCommands = '' |
| 15 | + for i in $(seq 1 120); do |
| 16 | + if zpool list | grep -q zroot || zpool import -N zroot; then |
| 17 | + break |
| 18 | + fi |
| 19 | + done |
| 20 | + ''; |
| 21 | + }; |
| 22 | + extraTestScript = '' |
| 23 | + def assert_property(ds, property, expected_value): |
| 24 | + out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip() |
| 25 | + assert ( |
| 26 | + out == expected_value |
| 27 | + ), f"Expected {property}={expected_value} on {ds}, got: {out}" |
| 28 | +
|
| 29 | + assert_property("zroot", "compression", "zstd") |
| 30 | + assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") |
| 31 | + assert_property("zroot/zfs_fs", "compression", "zstd") |
| 32 | + machine.succeed("mountpoint /zfs_fs"); |
| 33 | +
|
| 34 | + # Verify the pool has 36 devices total (33 in raidz3 vdevs + 3 spares) |
| 35 | + status_output = machine.succeed("zpool status -P zroot") |
| 36 | +
|
| 37 | + # Count the number of disk devices in the pool |
| 38 | + device_count = 0 |
| 39 | + for line in status_output.split("\n"): |
| 40 | + if "/dev/disk/by-partlabel/disk-" in line: |
| 41 | + device_count += 1 |
| 42 | +
|
| 43 | + assert device_count == 36, f"Expected 36 devices in pool, found {device_count}" |
| 44 | +
|
| 45 | + # Verify we have 3 raidz3 vdevs |
| 46 | + raidz3_count = status_output.count("raidz3") |
| 47 | + assert raidz3_count == 3, f"Expected 3 raidz3 vdevs, found {raidz3_count}" |
| 48 | +
|
| 49 | + # Verify we have 3 spares |
| 50 | + spares_count = 0 |
| 51 | + in_spares_section = False |
| 52 | + for line in status_output.split("\n"): |
| 53 | + if line.strip().startswith("spares"): |
| 54 | + in_spares_section = True |
| 55 | + elif in_spares_section and "/dev/disk/by-partlabel/disk-" in line: |
| 56 | + spares_count += 1 |
| 57 | + elif in_spares_section and line.strip() and not line.startswith("\t"): |
| 58 | + in_spares_section = False |
| 59 | +
|
| 60 | + assert spares_count == 3, f"Expected 3 spare devices, found {spares_count}" |
| 61 | +
|
| 62 | + # Verify pool health |
| 63 | + pool_state = machine.succeed("zpool list -H -o health zroot").strip() |
| 64 | + assert pool_state == "ONLINE", f"Expected pool health ONLINE, got {pool_state}" |
| 65 | + ''; |
| 66 | +} |
0 commit comments