zfs: HEAVILY REFACTOR subvolume handling
This commit is contained in:
@@ -7,29 +7,29 @@
|
||||
}:
|
||||
let
|
||||
# Create pkgs with ensureZfsMounts overlay
|
||||
testPkgs = import inputs.nixpkgs {
|
||||
system = pkgs.system;
|
||||
overlays = [ (import ../overlays.nix) ];
|
||||
};
|
||||
testPkgs = pkgs.appendOverlays [ (import ../overlays.nix) ];
|
||||
in
|
||||
testPkgs.testers.runNixOSTest {
|
||||
name = "zfs folder dependency and mounting test";
|
||||
name = "zfs test";
|
||||
|
||||
nodes.machine =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
(lib.serviceMountDeps "foobar" [ "/mnt/foobar_data" ])
|
||||
(lib.serviceMountDeps "foobarSadge" [
|
||||
"/mnt/foobar_data"
|
||||
"/mnt/does_not_exist_lol"
|
||||
])
|
||||
# Test valid paths within zpool
|
||||
(lib.serviceMountWithZpool "test-service" "rpool" [ "/mnt/rpool_data" ])
|
||||
|
||||
# Test service with paths outside zpool (should fail assertion)
|
||||
(lib.serviceMountWithZpool "invalid-service" "rpool2" [ "/mnt/rpool_data" ])
|
||||
];
|
||||
|
||||
virtualisation = {
|
||||
emptyDiskImages = [
|
||||
4096
|
||||
4096
|
||||
];
|
||||
# Add this to avoid ZFS hanging issues
|
||||
additionalPaths = [ pkgs.zfs ];
|
||||
};
|
||||
networking.hostId = "deadbeef";
|
||||
boot.kernelPackages = config.boot.kernelPackages;
|
||||
@@ -41,7 +41,7 @@ testPkgs.testers.runNixOSTest {
|
||||
ensureZfsMounts
|
||||
];
|
||||
|
||||
systemd.services.foobar = {
|
||||
systemd.services."test-service" = {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
@@ -49,7 +49,7 @@ testPkgs.testers.runNixOSTest {
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.foobarSadge = {
|
||||
systemd.services."invalid-service" = {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
@@ -61,38 +61,50 @@ testPkgs.testers.runNixOSTest {
|
||||
testScript = ''
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
# Setup ZFS pool
|
||||
machine.succeed(
|
||||
"parted --script /dev/vdb mklabel msdos",
|
||||
"parted --script /dev/vdb -- mkpart primary 1024M -1s",
|
||||
"zpool create rpool /dev/vdb1"
|
||||
)
|
||||
|
||||
machine.fail("zfsEnsureMounted")
|
||||
machine.fail("zfsEnsureMounted /mnt/test_mountpoint")
|
||||
# Setup ZFS pool 2
|
||||
machine.succeed(
|
||||
"parted --script /dev/vdc mklabel msdos",
|
||||
"parted --script /dev/vdc -- mkpart primary 1024M -1s",
|
||||
"zpool create rpool2 /dev/vdc1"
|
||||
)
|
||||
|
||||
machine.succeed("zpool create rpool /dev/vdb1")
|
||||
machine.succeed("zfs create -o mountpoint=/mnt/test_mountpoint rpool/test")
|
||||
machine.succeed("zfs create -o mountpoint=/mnt/rpool_data rpool/data")
|
||||
|
||||
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint")
|
||||
machine.succeed("zfs create -o mountpoint=/mnt/rpool2_data rpool2/data")
|
||||
|
||||
machine.fail("zfsEnsureMounted /mnt/does_not_exist_lol")
|
||||
machine.fail("zfsEnsureMounted /mnt/test_mountpoint /mnt/does_not_exist_lol")
|
||||
# Test that valid service starts successfully
|
||||
machine.succeed("systemctl start test-service")
|
||||
|
||||
machine.succeed("zfs create -o mountpoint=/mnt/test_mountpoint_dos rpool/test2")
|
||||
# Manually test our validation logic by checking the debug output
|
||||
zfs_output = machine.succeed("zfs list -H -o name,mountpoint")
|
||||
print("ZFS LIST OUTPUT:")
|
||||
print(zfs_output)
|
||||
|
||||
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint /mnt/test_mountpoint_dos")
|
||||
dataset = machine.succeed("zfs list -H -o name,mountpoint | awk '/\\/mnt\\/rpool_data/ { print $1 }'")
|
||||
print("DATASET FOR /mnt/rpool_data:")
|
||||
print(dataset)
|
||||
|
||||
machine.succeed("zfs create -o mountpoint='/mnt/test path with spaces' rpool/test3")
|
||||
# Test that invalid-service mount service fails validation
|
||||
machine.fail("systemctl start invalid-service.service")
|
||||
|
||||
machine.succeed("zfsEnsureMounted '/mnt/test path with spaces'")
|
||||
# Check the journal for our detailed validation error message
|
||||
journal_output = machine.succeed("journalctl -u invalid-service-mounts.service --no-pager")
|
||||
print("JOURNAL OUTPUT:")
|
||||
print(journal_output)
|
||||
|
||||
machine.succeed("zfs create -o mountpoint='/mnt/test escaped spaces' rpool/test4")
|
||||
machine.succeed("zfsEnsureMounted /mnt/test\ escaped\ spaces")
|
||||
# Verify our validation error is in the journal using Python string matching
|
||||
assert "ERROR: ZFS pool mismatch for /mnt/rpool_data" in journal_output
|
||||
assert "Expected pool: rpool2" in journal_output
|
||||
assert "Actual pool: rpool" in journal_output
|
||||
|
||||
machine.succeed("zfsEnsureMounted /mnt/test_mountpoint '/mnt/test path with spaces' /mnt/test_mountpoint_dos")
|
||||
|
||||
machine.succeed("zfs create -o mountpoint=/mnt/foobar_data rpool/foobar")
|
||||
machine.succeed("systemctl start foobar")
|
||||
|
||||
machine.fail("systemctl start foobarSadge")
|
||||
print("SUCCESS: Runtime validation correctly detected zpool mismatch!")
|
||||
'';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user