2010-06-08 16:02:22 +00:00
|
|
|
|
{ pkgs, ... }:
|
|
|
|
|
|
2010-06-09 13:18:49 +00:00
|
|
|
|
let
|
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
|
client =
|
2010-06-09 13:18:49 +00:00
|
|
|
|
{ config, pkgs, ... }:
|
2011-09-14 18:20:50 +00:00
|
|
|
|
{ fileSystems = pkgs.lib.mkOverride 50
|
2010-06-09 13:18:49 +00:00
|
|
|
|
[ { mountPoint = "/data";
|
|
|
|
|
device = "server:/data";
|
|
|
|
|
fsType = "nfs";
|
2012-10-24 16:10:58 +00:00
|
|
|
|
options = "vers=3";
|
2011-09-14 18:20:50 +00:00
|
|
|
|
}
|
2010-06-09 13:18:49 +00:00
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
2010-06-08 16:02:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
nodes =
|
2010-06-09 13:18:49 +00:00
|
|
|
|
{ client1 = client;
|
|
|
|
|
client2 = client;
|
2010-06-08 16:02:22 +00:00
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
|
server =
|
2010-06-08 16:02:22 +00:00
|
|
|
|
{ config, pkgs, ... }:
|
2012-03-16 20:41:49 +00:00
|
|
|
|
{ services.nfs.server.enable = true;
|
|
|
|
|
services.nfs.server.exports =
|
2010-06-08 16:02:22 +00:00
|
|
|
|
''
|
|
|
|
|
/data 192.168.1.0/255.255.255.0(rw,no_root_squash)
|
|
|
|
|
'';
|
2012-03-16 20:41:49 +00:00
|
|
|
|
services.nfs.server.createMountPoints = true;
|
2010-06-08 16:02:22 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
|
''
|
2012-10-24 16:22:53 +00:00
|
|
|
|
$server->waitForUnit("nfsd");
|
|
|
|
|
$server->waitForUnit("network.target");
|
2010-06-08 16:02:22 +00:00
|
|
|
|
|
2012-03-16 20:10:14 +00:00
|
|
|
|
startAll;
|
2010-06-08 16:02:22 +00:00
|
|
|
|
|
2012-10-24 16:22:53 +00:00
|
|
|
|
$client1->waitForUnit("data.mount");
|
2010-06-09 13:18:49 +00:00
|
|
|
|
$client1->succeed("echo bla > /data/foo");
|
2010-06-08 16:02:22 +00:00
|
|
|
|
$server->succeed("test -e /data/foo");
|
|
|
|
|
|
2012-10-24 16:22:53 +00:00
|
|
|
|
$client2->waitForUnit("data.mount");
|
2010-06-09 13:18:49 +00:00
|
|
|
|
$client2->succeed("echo bla > /data/bar");
|
|
|
|
|
$server->succeed("test -e /data/bar");
|
|
|
|
|
|
2012-03-16 20:10:14 +00:00
|
|
|
|
# Test whether restarting ‘nfsd’ works correctly.
|
2012-10-24 16:10:58 +00:00
|
|
|
|
$server->succeed("systemctl restart nfsd");
|
2012-03-16 20:10:14 +00:00
|
|
|
|
$client2->succeed("echo bla >> /data/bar"); # will take 90 seconds due to the NFS grace period
|
2011-10-13 14:08:00 +00:00
|
|
|
|
|
2012-03-16 20:10:14 +00:00
|
|
|
|
# Test whether we can get a lock.
|
2010-06-09 15:11:46 +00:00
|
|
|
|
$client2->succeed("time flock -n -s /data/lock true");
|
2011-09-14 18:20:50 +00:00
|
|
|
|
|
2010-06-09 13:18:49 +00: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 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
# Test whether client 2 obtains the lock if we reset client 1.
|
2010-06-09 15:11:46 +00:00
|
|
|
|
$client2->succeed("flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &");
|
2010-06-09 13:46:18 +00:00
|
|
|
|
$client1->crash;
|
|
|
|
|
$client1->start;
|
|
|
|
|
$client2->waitForFile("locked");
|
2010-06-09 15:11:46 +00:00
|
|
|
|
|
|
|
|
|
# Test whether locks survive a reboot of the server.
|
2012-10-24 16:22:53 +00:00
|
|
|
|
$client1->waitForUnit("data.mount");
|
2010-06-09 15:11:46 +00:00
|
|
|
|
$server->shutdown;
|
|
|
|
|
$server->start;
|
|
|
|
|
$client1->succeed("touch /data/xyzzy");
|
|
|
|
|
$client1->fail("time flock -n -s /data/lock true");
|
2010-06-09 22:29:06 +00:00
|
|
|
|
|
2012-03-16 20:10:14 +00:00
|
|
|
|
# Test whether unmounting during shutdown happens quickly.
|
2010-06-09 22:29:06 +00:00
|
|
|
|
my $t1 = time;
|
|
|
|
|
$client1->shutdown;
|
|
|
|
|
my $duration = time - $t1;
|
|
|
|
|
die "shutdown took too long ($duration seconds)" if $duration > 30;
|
2010-06-08 16:02:22 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
}
|