1 import ../make-test-python.nix ({ pkgs, version ? 4, ... }:
7 { virtualisation.fileSystems =
9 { # nfs4 exports the export with fsid=0 as a virtual root directory
10 device = if (version == 4) then "server:/" else "server:/data";
12 options = [ "vers=${toString version}" ];
15 networking.firewall.enable = false; # FIXME: only open statd
22 meta = with pkgs.lib.maintainers; {
23 maintainers = [ eelco ];
32 { services.nfs.server.enable = true;
33 services.nfs.server.exports =
35 /data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0)
37 services.nfs.server.createMountPoints = true;
38 networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed
46 server.wait_for_unit("nfs-server")
47 server.succeed("systemctl start network-online.target")
48 server.wait_for_unit("network-online.target")
52 client1.wait_for_unit("data.mount")
53 client1.succeed("echo bla > /data/foo")
54 server.succeed("test -e /data/foo")
56 client2.wait_for_unit("data.mount")
57 client2.succeed("echo bla > /data/bar")
58 server.succeed("test -e /data/bar")
60 with subtest("restarting 'nfs-server' works correctly"):
61 server.succeed("systemctl restart nfs-server")
62 # will take 90 seconds due to the NFS grace period
63 client2.succeed("echo bla >> /data/bar")
65 with subtest("can get a lock"):
66 client2.succeed("time flock -n -s /data/lock true")
68 with subtest("client 2 fails to acquire lock held by client 1"):
69 client1.succeed("flock -x /data/lock -c 'touch locked; sleep 100000' >&2 &")
70 client1.wait_for_file("locked")
71 client2.fail("flock -n -s /data/lock true")
73 with subtest("client 2 obtains lock after resetting client 1"):
75 "flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &"
79 client2.wait_for_file("locked")
81 with subtest("locks survive server reboot"):
82 client1.wait_for_unit("data.mount")
85 client1.succeed("touch /data/xyzzy")
86 client1.fail("time flock -n -s /data/lock true")
88 with subtest("unmounting during shutdown happens quickly"):
91 duration = time.monotonic() - t1
92 assert duration < 30, f"shutdown took too long ({duration} seconds)"