2019-11-27 14:37:27 +00:00
|
|
|
import ../make-test-python.nix ({ pkgs, version ? 4, ... }:
|
2010-06-08 17:02:22 +01:00
|
|
|
|
2010-06-09 14:18:49 +01:00
|
|
|
let
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
client =
|
2018-07-20 21:56:59 +01:00
|
|
|
{ pkgs, ... }:
|
2021-02-14 11:23:50 +00:00
|
|
|
{ virtualisation.fileSystems =
|
2020-02-17 08:57:35 +00:00
|
|
|
{ "/data" =
|
|
|
|
{ # nfs4 exports the export with fsid=0 as a virtual root directory
|
|
|
|
device = if (version == 4) then "server:/" else "server:/data";
|
|
|
|
fsType = "nfs";
|
|
|
|
options = [ "vers=${toString version}" ];
|
|
|
|
};
|
|
|
|
};
|
2014-04-11 16:15:56 +01:00
|
|
|
networking.firewall.enable = false; # FIXME: only open statd
|
2010-06-09 14:18:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2010-06-08 17:02:22 +01:00
|
|
|
{
|
2014-06-28 15:04:49 +01:00
|
|
|
name = "nfs";
|
2021-01-10 19:08:30 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2019-02-22 15:14:13 +00:00
|
|
|
maintainers = [ eelco ];
|
2015-07-12 11:09:40 +01:00
|
|
|
};
|
2010-06-08 17:02:22 +01:00
|
|
|
|
|
|
|
nodes =
|
2010-06-09 14:18:49 +01:00
|
|
|
{ client1 = client;
|
|
|
|
client2 = client;
|
2010-06-08 17:02:22 +01:00
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
server =
|
2018-07-20 21:56:59 +01:00
|
|
|
{ ... }:
|
2012-03-16 20:41:49 +00:00
|
|
|
{ services.nfs.server.enable = true;
|
|
|
|
services.nfs.server.exports =
|
2010-06-08 17:02:22 +01:00
|
|
|
''
|
2013-07-16 12:59:41 +01:00
|
|
|
/data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0)
|
2010-06-08 17:02:22 +01:00
|
|
|
'';
|
2012-03-16 20:41:49 +00:00
|
|
|
services.nfs.server.createMountPoints = true;
|
2014-04-11 16:15:56 +01:00
|
|
|
networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed
|
2010-06-08 17:02:22 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
2019-11-23 19:33:42 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
server.wait_for_unit("nfs-server")
|
|
|
|
server.succeed("systemctl start network-online.target")
|
|
|
|
server.wait_for_unit("network-online.target")
|
|
|
|
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
client1.wait_for_unit("data.mount")
|
|
|
|
client1.succeed("echo bla > /data/foo")
|
|
|
|
server.succeed("test -e /data/foo")
|
|
|
|
|
|
|
|
client2.wait_for_unit("data.mount")
|
|
|
|
client2.succeed("echo bla > /data/bar")
|
|
|
|
server.succeed("test -e /data/bar")
|
|
|
|
|
|
|
|
with subtest("restarting 'nfs-server' works correctly"):
|
|
|
|
server.succeed("systemctl restart nfs-server")
|
|
|
|
# will take 90 seconds due to the NFS grace period
|
|
|
|
client2.succeed("echo bla >> /data/bar")
|
|
|
|
|
|
|
|
with subtest("can get a lock"):
|
|
|
|
client2.succeed("time flock -n -s /data/lock true")
|
|
|
|
|
|
|
|
with subtest("client 2 fails to acquire lock held by client 1"):
|
2021-11-05 00:43:22 +00:00
|
|
|
client1.succeed("flock -x /data/lock -c 'touch locked; sleep 100000' >&2 &")
|
2019-11-23 19:33:42 +00:00
|
|
|
client1.wait_for_file("locked")
|
|
|
|
client2.fail("flock -n -s /data/lock true")
|
|
|
|
|
|
|
|
with subtest("client 2 obtains lock after resetting client 1"):
|
|
|
|
client2.succeed(
|
|
|
|
"flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &"
|
|
|
|
)
|
|
|
|
client1.crash()
|
|
|
|
client1.start()
|
|
|
|
client2.wait_for_file("locked")
|
|
|
|
|
|
|
|
with subtest("locks survive server reboot"):
|
|
|
|
client1.wait_for_unit("data.mount")
|
|
|
|
server.shutdown()
|
|
|
|
server.start()
|
|
|
|
client1.succeed("touch /data/xyzzy")
|
|
|
|
client1.fail("time flock -n -s /data/lock true")
|
|
|
|
|
|
|
|
with subtest("unmounting during shutdown happens quickly"):
|
|
|
|
t1 = time.monotonic()
|
|
|
|
client1.shutdown()
|
|
|
|
duration = time.monotonic() - t1
|
|
|
|
assert duration < 30, f"shutdown took too long ({duration} seconds)"
|
2010-06-08 17:02:22 +01:00
|
|
|
'';
|
2014-04-14 13:02:44 +01:00
|
|
|
})
|