111 lines
3.2 KiB
Nix
111 lines
3.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
inputs,
|
|
...
|
|
}:
|
|
let
|
|
# Create pkgs with ensureZfsMounts overlay
|
|
testPkgs = pkgs.appendOverlays [ (import ../overlays.nix) ];
|
|
in
|
|
testPkgs.testers.runNixOSTest {
|
|
name = "zfs test";
|
|
|
|
nodes.machine =
|
|
{ pkgs, ... }:
|
|
{
|
|
imports = [
|
|
# 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;
|
|
boot.zfs.package = config.boot.zfs.package;
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
parted
|
|
ensureZfsMounts
|
|
];
|
|
|
|
systemd.services."test-service" = {
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
ExecStart = lib.getExe pkgs.bash;
|
|
};
|
|
};
|
|
|
|
systemd.services."invalid-service" = {
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
ExecStart = lib.getExe pkgs.bash;
|
|
};
|
|
};
|
|
};
|
|
|
|
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"
|
|
)
|
|
|
|
# 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("zfs create -o mountpoint=/mnt/rpool_data rpool/data")
|
|
|
|
machine.succeed("zfs create -o mountpoint=/mnt/rpool2_data rpool2/data")
|
|
|
|
# Test that valid service starts successfully
|
|
machine.succeed("systemctl start test-service")
|
|
|
|
# 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)
|
|
|
|
dataset = machine.succeed("zfs list -H -o name,mountpoint | awk '/\\/mnt\\/rpool_data/ { print $1 }'")
|
|
print("DATASET FOR /mnt/rpool_data:")
|
|
print(dataset)
|
|
|
|
# Test that invalid-service mount service fails validation
|
|
machine.fail("systemctl start invalid-service.service")
|
|
|
|
# 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)
|
|
|
|
# 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
|
|
|
|
print("SUCCESS: Runtime validation correctly detected zpool mismatch!")
|
|
'';
|
|
}
|