2015-07-12 13:09:40 +03:00
|
|
|
|
import ./make-test.nix ({ pkgs, version ? 4, ... }:
|
2010-06-08 20:02:22 +04:00
|
|
|
|
|
2010-06-09 17:18:49 +04:00
|
|
|
|
let
|
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
|
client =
|
2018-07-20 23:56:59 +03:00
|
|
|
|
{ pkgs, ... }:
|
2013-10-29 16:04:52 +04:00
|
|
|
|
{ fileSystems = pkgs.lib.mkVMOverride
|
2010-06-09 17:18:49 +04:00
|
|
|
|
[ { mountPoint = "/data";
|
2018-08-30 20:57:39 +03:00
|
|
|
|
# nfs4 exports the export with fsid=0 as a virtual root directory
|
|
|
|
|
device = if (version == 4) then "server:/" else "server:/data";
|
2010-06-09 17:18:49 +04:00
|
|
|
|
fsType = "nfs";
|
2015-10-21 20:37:14 +03:00
|
|
|
|
options = [ "vers=${toString version}" ];
|
2011-09-14 22:20:50 +04:00
|
|
|
|
}
|
2010-06-09 17:18:49 +04:00
|
|
|
|
];
|
2014-04-11 19:15:56 +04:00
|
|
|
|
networking.firewall.enable = false; # FIXME: only open statd
|
2010-06-09 17:18:49 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
2010-06-08 20:02:22 +04:00
|
|
|
|
{
|
2014-06-28 18:04:49 +04:00
|
|
|
|
name = "nfs";
|
2015-07-12 13:09:40 +03:00
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
2019-02-22 18:14:13 +03:00
|
|
|
|
maintainers = [ eelco ];
|
2015-07-12 13:09:40 +03:00
|
|
|
|
};
|
2010-06-08 20:02:22 +04:00
|
|
|
|
|
|
|
|
|
nodes =
|
2010-06-09 17:18:49 +04:00
|
|
|
|
{ client1 = client;
|
|
|
|
|
client2 = client;
|
2010-06-08 20:02:22 +04:00
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
|
server =
|
2018-07-20 23:56:59 +03:00
|
|
|
|
{ ... }:
|
2012-03-17 00:41:49 +04:00
|
|
|
|
{ services.nfs.server.enable = true;
|
|
|
|
|
services.nfs.server.exports =
|
2010-06-08 20:02:22 +04:00
|
|
|
|
''
|
2013-07-16 15:59:41 +04:00
|
|
|
|
/data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0)
|
2010-06-08 20:02:22 +04:00
|
|
|
|
'';
|
2012-03-17 00:41:49 +04:00
|
|
|
|
services.nfs.server.createMountPoints = true;
|
2014-04-11 19:15:56 +04:00
|
|
|
|
networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed
|
2010-06-08 20:02:22 +04:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
|
''
|
2017-02-05 12:40:41 +03:00
|
|
|
|
$server->waitForUnit("nfs-server");
|
2014-12-02 12:34:20 +03:00
|
|
|
|
$server->succeed("systemctl start network-online.target");
|
2014-12-02 04:17:46 +03:00
|
|
|
|
$server->waitForUnit("network-online.target");
|
2010-06-08 20:02:22 +04:00
|
|
|
|
|
2012-03-17 00:10:14 +04:00
|
|
|
|
startAll;
|
2010-06-08 20:02:22 +04:00
|
|
|
|
|
2012-10-24 20:22:53 +04:00
|
|
|
|
$client1->waitForUnit("data.mount");
|
2010-06-09 17:18:49 +04:00
|
|
|
|
$client1->succeed("echo bla > /data/foo");
|
2010-06-08 20:02:22 +04:00
|
|
|
|
$server->succeed("test -e /data/foo");
|
|
|
|
|
|
2012-10-24 20:22:53 +04:00
|
|
|
|
$client2->waitForUnit("data.mount");
|
2010-06-09 17:18:49 +04:00
|
|
|
|
$client2->succeed("echo bla > /data/bar");
|
|
|
|
|
$server->succeed("test -e /data/bar");
|
|
|
|
|
|
2017-02-05 12:40:41 +03:00
|
|
|
|
# Test whether restarting ‘nfs-server’ works correctly.
|
|
|
|
|
$server->succeed("systemctl restart nfs-server");
|
2012-03-17 00:10:14 +04:00
|
|
|
|
$client2->succeed("echo bla >> /data/bar"); # will take 90 seconds due to the NFS grace period
|
2011-10-13 18:08:00 +04:00
|
|
|
|
|
2012-03-17 00:10:14 +04:00
|
|
|
|
# Test whether we can get a lock.
|
2010-06-09 19:11:46 +04:00
|
|
|
|
$client2->succeed("time flock -n -s /data/lock true");
|
2011-09-14 22:20:50 +04:00
|
|
|
|
|
2010-06-09 17:18:49 +04:00
|
|
|
|
# Test locking: client 1 acquires an exclusive lock, so client 2
|
|
|
|
|
# should then fail to acquire a shared lock.
|
|
|
|
|
$client1->succeed("flock -x /data/lock -c 'touch locked; sleep 100000' &");
|
|
|
|
|
$client1->waitForFile("locked");
|
|
|
|
|
$client2->fail("flock -n -s /data/lock true");
|
2010-06-09 17:46:18 +04:00
|
|
|
|
|
|
|
|
|
# Test whether client 2 obtains the lock if we reset client 1.
|
2010-06-09 19:11:46 +04:00
|
|
|
|
$client2->succeed("flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &");
|
2010-06-09 17:46:18 +04:00
|
|
|
|
$client1->crash;
|
|
|
|
|
$client1->start;
|
|
|
|
|
$client2->waitForFile("locked");
|
2010-06-09 19:11:46 +04:00
|
|
|
|
|
|
|
|
|
# Test whether locks survive a reboot of the server.
|
2012-10-24 20:22:53 +04:00
|
|
|
|
$client1->waitForUnit("data.mount");
|
2010-06-09 19:11:46 +04:00
|
|
|
|
$server->shutdown;
|
|
|
|
|
$server->start;
|
|
|
|
|
$client1->succeed("touch /data/xyzzy");
|
|
|
|
|
$client1->fail("time flock -n -s /data/lock true");
|
2010-06-10 02:29:06 +04:00
|
|
|
|
|
2012-03-17 00:10:14 +04:00
|
|
|
|
# Test whether unmounting during shutdown happens quickly.
|
2010-06-10 02:29:06 +04:00
|
|
|
|
my $t1 = time;
|
|
|
|
|
$client1->shutdown;
|
|
|
|
|
my $duration = time - $t1;
|
|
|
|
|
die "shutdown took too long ($duration seconds)" if $duration > 30;
|
2010-06-08 20:02:22 +04:00
|
|
|
|
'';
|
2014-04-14 16:02:44 +04:00
|
|
|
|
})
|