notes: 2.3.0 -> 2.3.1 (#352950)
[NixPkgs.git] / nixos / tests / drbd.nix
blobdefbad6933932967ebbf5986ac463dc0672ba025
1 import ./make-test-python.nix (
2   { pkgs, lib, ... }:
3   let
4     drbdPort = 7789;
6     drbdConfig =
7       { nodes, ... }:
8       {
9         virtualisation.emptyDiskImages = [ 1 ];
10         networking.firewall.allowedTCPPorts = [ drbdPort ];
12         services.drbd = {
13           enable = true;
14           config = ''
15             global {
16               usage-count yes;
17             }
19             common {
20               net {
21                 protocol C;
22                 ping-int 1;
23               }
24             }
26             resource r0 {
27               volume 0 {
28                 device    /dev/drbd0;
29                 disk      /dev/vdb;
30                 meta-disk internal;
31               }
33               on drbd1 {
34                 address ${nodes.drbd1.networking.primaryIPAddress}:${toString drbdPort};
35               }
37               on drbd2 {
38                 address ${nodes.drbd2.networking.primaryIPAddress}:${toString drbdPort};
39               }
40             }
41           '';
42         };
43       };
44   in
45   {
46     name = "drbd";
47     meta = with pkgs.lib.maintainers; {
48       maintainers = [ ryantm astro birkb ];
49     };
51     nodes.drbd1 = drbdConfig;
52     nodes.drbd2 = drbdConfig;
54     testScript = { nodes }: ''
55       drbd1.start()
56       drbd2.start()
58       drbd1.wait_for_unit("network.target")
59       drbd2.wait_for_unit("network.target")
61       drbd1.succeed(
62           "drbdadm create-md r0",
63           "drbdadm up r0",
64           "drbdadm primary r0 --force",
65       )
67       drbd2.succeed("drbdadm create-md r0", "drbdadm up r0")
69       drbd1.succeed(
70           "mkfs.ext4 /dev/drbd0",
71           "mkdir -p /mnt/drbd",
72           "mount /dev/drbd0 /mnt/drbd",
73           "touch /mnt/drbd/hello",
74           "umount /mnt/drbd",
75           "drbdadm secondary r0",
76       )
77       drbd1.sleep(1)
79       drbd2.succeed(
80           "drbdadm primary r0",
81           "mkdir -p /mnt/drbd",
82           "mount /dev/drbd0 /mnt/drbd",
83           "ls /mnt/drbd/hello",
84       )
85     '';
86   }