mirror of
https://github.com/nix-community/disko.git
synced 2026-12-03 22:43:28 +01:00
tests/zfs-with-vdevs: fix not all vdevs detected
This commit is contained in:
1 parent
e40d944dec
commit
6795806dbc
2 files changed
+55
-43
No files matched your search
+4
-1
@@ -190,7 +190,10 @@ let
|
|||||||
"cache=loose"
|
"cache=loose"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
# /dev/disk-by-id is empty in QEMU VMs, /dev/disk/by-uuid only shows one entry
|
||||||
|
# per ZFS pool as members use the pool's GUID, /dev/disk/by-partuuid only shows
|
||||||
|
# partitions so LVM backed members are missed. /dev is the only thing that catches all.
|
||||||
|
boot.zfs.devNodes = "/dev";
|
||||||
|
|
||||||
# Silence mdadm warning about missing MAILADDR or PROGRAM
|
# Silence mdadm warning about missing MAILADDR or PROGRAM
|
||||||
boot.swraid.mdadmConf = "PROGRAM ${pkgs.coreutils}/bin/true";
|
boot.swraid.mdadmConf = "PROGRAM ${pkgs.coreutils}/bin/true";
|
||||||
|
|||||||
+51
-42
@@ -9,23 +9,22 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
extraInstallerConfig.networking.hostId = "8425e349";
|
extraInstallerConfig.networking.hostId = "8425e349";
|
||||||
extraSystemConfig = {
|
extraSystemConfig = {
|
||||||
networking.hostId = "8425e349";
|
networking.hostId = "8425e349";
|
||||||
# It looks like the 60s of NixOS is sometimes not enough for our virtio-based zpool.
|
|
||||||
# This fixes the flakeiness of the test.
|
|
||||||
boot.initrd.postResumeCommands = ''
|
|
||||||
for i in $(seq 1 120); do
|
|
||||||
if zpool list | grep -q zroot || zpool import -N zroot; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
|
import json
|
||||||
|
|
||||||
def assert_property(ds, property, expected_value):
|
def assert_property(ds, property, expected_value):
|
||||||
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
||||||
assert (
|
assert (
|
||||||
out == expected_value
|
out == expected_value
|
||||||
), f"Expected {property}={expected_value} on {ds}, got: {out}"
|
), f"Expected {property}={expected_value} on {ds}, got: {out}"
|
||||||
|
|
||||||
|
def canonical_path(path):
|
||||||
|
return machine.succeed(f"readlink -f {shlex.quote(path)}").strip()
|
||||||
|
|
||||||
|
def by_partlabel(label):
|
||||||
|
return canonical_path(f"/dev/disk/by-partlabel/{label}")
|
||||||
|
|
||||||
# These fields are 0 if l2arc is disabled
|
# These fields are 0 if l2arc is disabled
|
||||||
assert (
|
assert (
|
||||||
machine.succeed(
|
machine.succeed(
|
||||||
@@ -40,39 +39,49 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||||
machine.succeed("mountpoint /zfs_fs");
|
machine.succeed("mountpoint /zfs_fs");
|
||||||
|
|
||||||
# Take the status output and flatten it so that each device is on a single line prefixed with with the group (either
|
# `zpool status -j` groups vdevs by class at the pool level: `vdevs` (normal data, wrapped under
|
||||||
# the pool name or a designation like log/cache/spare/dedup/special) and first portion of the vdev name (empty for a
|
# the `zroot` root vdev) plus `dedup`, `special`, `logs`, `l2cache`, `spares`. Each entry in a
|
||||||
# disk from a single vdev, mirror for devices in a mirror. This makes it easy to verify that the layout is as
|
# group is either a leaf (just a device path) or a mirror vdev with nested `vdevs`. Bucket each
|
||||||
# expected.
|
# leaf into (class, in_mirror, canonical path) and diff against the expected layout.
|
||||||
group = ""
|
def collect_leaves(class_name, entries):
|
||||||
vdev = ""
|
out = []
|
||||||
actual = []
|
for name, entry in entries.items():
|
||||||
for line in machine.succeed("zpool status -P zroot").split("\n"):
|
if entry.get("vdev_type") == "mirror":
|
||||||
first_word = line.strip().split(" ", 1)[0]
|
out.extend((class_name, "mirror", canonical_path(child)) for child in entry["vdevs"])
|
||||||
if line.startswith("\t ") and first_word.startswith("/"):
|
else:
|
||||||
actual.append(f"{group}{vdev}{first_word}")
|
out.append((class_name, "single", canonical_path(name)))
|
||||||
elif line.startswith("\t "):
|
return out
|
||||||
vdev = f"{first_word.split('-', 1)[0]} "
|
|
||||||
elif line.startswith("\t"):
|
data = json.loads(machine.succeed("zpool status -P -L -j zroot"))
|
||||||
group = f"{first_word} "
|
pool = next(iter(data["pools"].values()))
|
||||||
vdev = ""
|
actual_leaves = sorted(
|
||||||
actual.sort()
|
collect_leaves("normal", pool["vdevs"]["zroot"]["vdevs"])
|
||||||
expected=sorted([
|
+ collect_leaves("dedup", pool.get("dedup", {}))
|
||||||
'zroot /dev/disk/by-partlabel/disk-data1-zfs',
|
+ collect_leaves("special", pool.get("special", {}))
|
||||||
'zroot mirror /dev/disk/by-partlabel/disk-data2-zfs',
|
+ collect_leaves("log", pool.get("logs", {}))
|
||||||
'zroot mirror /dev/disk/by-partlabel/disk-data3-zfs',
|
+ collect_leaves("l2cache", pool.get("l2cache", {}))
|
||||||
'dedup /dev/disk/by-partlabel/disk-dedup3-zfs',
|
+ collect_leaves("spare", pool.get("spares", {}))
|
||||||
'dedup mirror /dev/disk/by-partlabel/disk-dedup1-zfs',
|
)
|
||||||
'dedup mirror /dev/disk/by-partlabel/disk-dedup2-zfs',
|
expected_leaves = sorted([
|
||||||
'special /dev/disk/by-partlabel/disk-special3-zfs',
|
("normal", "single", by_partlabel("disk-data1-zfs")),
|
||||||
'special mirror /dev/disk/by-partlabel/disk-special1-zfs',
|
("normal", "mirror", by_partlabel("disk-data2-zfs")),
|
||||||
'special mirror /dev/disk/by-partlabel/disk-special2-zfs',
|
("normal", "mirror", by_partlabel("disk-data3-zfs")),
|
||||||
'logs /dev/disk/by-partlabel/disk-log3-zfs',
|
("dedup", "single", by_partlabel("disk-dedup3-zfs")),
|
||||||
'logs mirror /dev/disk/by-partlabel/disk-log1-zfs',
|
("dedup", "mirror", by_partlabel("disk-dedup1-zfs")),
|
||||||
'logs mirror /dev/disk/by-partlabel/disk-log2-zfs',
|
("dedup", "mirror", by_partlabel("disk-dedup2-zfs")),
|
||||||
'cache /dev/disk/by-partlabel/disk-cache-zfs',
|
("special", "single", by_partlabel("disk-special3-zfs")),
|
||||||
'spares /dev/disk/by-partlabel/disk-spare-zfs',
|
("special", "mirror", by_partlabel("disk-special1-zfs")),
|
||||||
|
("special", "mirror", by_partlabel("disk-special2-zfs")),
|
||||||
|
("log", "single", by_partlabel("disk-log3-zfs")),
|
||||||
|
("log", "mirror", by_partlabel("disk-log1-zfs")),
|
||||||
|
("log", "mirror", by_partlabel("disk-log2-zfs")),
|
||||||
|
("l2cache", "single", by_partlabel("disk-cache-zfs")),
|
||||||
|
("spare", "single", by_partlabel("disk-spare-zfs")),
|
||||||
])
|
])
|
||||||
assert actual == expected, f"Incorrect pool layout. Expected:\n\t{'\n\t'.join(expected)}\nActual:\n\t{'\n\t'.join(actual)}"
|
assert actual_leaves == expected_leaves, (
|
||||||
|
"Incorrect pool layout."
|
||||||
|
f"\nExpected: {json.dumps(expected_leaves, indent=2)}"
|
||||||
|
f"\nActual: {json.dumps(actual_leaves, indent=2)}"
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user