python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / nixos / tests / nfs / simple.nix
blob1e319a8eec8106b3b8839516cf2940e9c0c18a2c
1 import ../make-test-python.nix ({ pkgs, version ? 4, ... }:
3 let
5   client =
6     { pkgs, ... }:
7     { virtualisation.fileSystems =
8         { "/data" =
9            { # nfs4 exports the export with fsid=0 as a virtual root directory
10              device = if (version == 4) then "server:/" else "server:/data";
11              fsType = "nfs";
12              options = [ "vers=${toString version}" ];
13            };
14         };
15       networking.firewall.enable = false; # FIXME: only open statd
16     };
21   name = "nfs";
22   meta = with pkgs.lib.maintainers; {
23     maintainers = [ eelco ];
24   };
26   nodes =
27     { client1 = client;
28       client2 = client;
30       server =
31         { ... }:
32         { services.nfs.server.enable = true;
33           services.nfs.server.exports =
34             ''
35               /data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0)
36             '';
37           services.nfs.server.createMountPoints = true;
38           networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed
39         };
40     };
42   testScript =
43     ''
44       import time
46       server.wait_for_unit("nfs-server")
47       server.succeed("systemctl start network-online.target")
48       server.wait_for_unit("network-online.target")
50       start_all()
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"):
74           client2.succeed(
75               "flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &"
76           )
77           client1.crash()
78           client1.start()
79           client2.wait_for_file("locked")
81       with subtest("locks survive server reboot"):
82           client1.wait_for_unit("data.mount")
83           server.shutdown()
84           server.start()
85           client1.succeed("touch /data/xyzzy")
86           client1.fail("time flock -n -s /data/lock true")
88       with subtest("unmounting during shutdown happens quickly"):
89           t1 = time.monotonic()
90           client1.shutdown()
91           duration = time.monotonic() - t1
92           assert duration < 30, f"shutdown took too long ({duration} seconds)"
93     '';