git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/drbd: init
commit7f4e071274424c3e37847fc26bd7e4343ce9522c authorRyan Mulligan <ryan@ryantm.com> dateTue 30 Nov 2021, 21:42 (5 years ago) parentaa37441
2 files changed+88
nixos/tests/all-tests.nix+1 nixos/tests/drbd.nix+87
nixos/tests/all-tests.nix+1
@@ -111,6 +111,7 @@ in
111111 dokuwiki = handleTest ./dokuwiki.nix {};
112112 domination = handleTest ./domination.nix {};
113113 dovecot = handleTest ./dovecot.nix {};
114+ drbd = handleTest ./drbd.nix {};
114115 ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {};
115116 ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {};
116117 ecryptfs = handleTest ./ecryptfs.nix {};
nixos/tests/drbd.nixnew file+87
@@ -0,0 +1,87 @@
1+import ./make-test-python.nix (
2+ { pkgs, lib, ... }:
3+ let
4+ drbdPort = 7789;
5+
6+ drbdConfig =
7+ { nodes, ... }:
8+ {
9+ virtualisation.emptyDiskImages = [ 1 ];
10+ networking.firewall.allowedTCPPorts = [ drbdPort ];
11+
12+ services.drbd = {
13+ enable = true;
14+ config = ''
15+ global {
16+ usage-count yes;
17+ }
18+
19+ common {
20+ net {
21+ protocol C;
22+ ping-int 1;
23+ }
24+ }
25+
26+ resource r0 {
27+ volume 0 {
28+ device /dev/drbd0;
29+ disk /dev/vdb;
30+ meta-disk internal;
31+ }
32+
33+ on drbd1 {
34+ address ${nodes.drbd1.config.networking.primaryIPAddress}:${toString drbdPort};
35+ }
36+
37+ on drbd2 {
38+ address ${nodes.drbd2.config.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 ];
49+ };
50+
51+ nodes.drbd1 = drbdConfig;
52+ nodes.drbd2 = drbdConfig;
53+
54+ testScript = { nodes }: ''
55+ drbd1.start()
56+ drbd2.start()
57+
58+ drbd1.wait_for_unit("network.target")
59+ drbd2.wait_for_unit("network.target")
60+
61+ drbd1.succeed(
62+ "drbdadm create-md r0",
63+ "drbdadm up r0",
64+ "drbdadm primary r0 --force",
65+ )
66+
67+ drbd2.succeed("drbdadm create-md r0", "drbdadm up r0")
68+
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)
78+
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+ }
87+)