1import ./make-test-python.nix ({pkgs, lib, ...}:
2
3let
4 cfg = {
5 clusterId = "066ae264-2a5d-4729-8001-6ad265f50b03";
6 monA = {
7 name = "a";
8 ip = "192.168.1.1";
9 };
10 osd0 = {
11 name = "0";
12 key = "AQBCEJNa3s8nHRAANvdsr93KqzBznuIWm2gOGg==";
13 uuid = "55ba2294-3e24-478f-bee0-9dca4c231dd9";
14 };
15 osd1 = {
16 name = "1";
17 key = "AQBEEJNac00kExAAXEgy943BGyOpVH1LLlHafQ==";
18 uuid = "5e97a838-85b6-43b0-8950-cb56d554d1e5";
19 };
20 osd2 = {
21 name = "2";
22 key = "AQAdyhZeIaUlARAAGRoidDAmS6Vkp546UFEf5w==";
23 uuid = "ea999274-13d0-4dd5-9af9-ad25a324f72f";
24 };
25 };
26 generateCephConfig = { daemonConfig }: {
27 enable = true;
28 global = {
29 fsid = cfg.clusterId;
30 monHost = cfg.monA.ip;
31 monInitialMembers = cfg.monA.name;
32 };
33 } // daemonConfig;
34
35 generateHost = { pkgs, cephConfig, networkConfig, ... }: {
36 virtualisation = {
37 memorySize = 1024;
38 emptyDiskImages = [ 20480 20480 20480 ];
39 vlans = [ 1 ];
40 };
41
42 networking = networkConfig;
43
44 environment.systemPackages = with pkgs; [
45 bash
46 sudo
47 ceph
48 xfsprogs
49 ];
50
51 boot.kernelModules = [ "xfs" ];
52
53 services.ceph = cephConfig;
54 };
55
56 networkMonA = {
57 dhcpcd.enable = false;
58 interfaces.eth1.ipv4.addresses = pkgs.lib.mkOverride 0 [
59 { address = cfg.monA.ip; prefixLength = 24; }
60 ];
61 };
62 cephConfigMonA = generateCephConfig { daemonConfig = {
63 mon = {
64 enable = true;
65 daemons = [ cfg.monA.name ];
66 };
67 mgr = {
68 enable = true;
69 daemons = [ cfg.monA.name ];
70 };
71 osd = {
72 enable = true;
73 daemons = [ cfg.osd0.name cfg.osd1.name cfg.osd2.name ];
74 };
75 }; };
76
77 # Following deployment is based on the manual deployment described here:
78 # https://docs.ceph.com/docs/master/install/manual-deployment/
79 # For other ways to deploy a ceph cluster, look at the documentation at
80 # https://docs.ceph.com/docs/master/
81 testscript = { ... }: ''
82 start_all()
83
84 monA.wait_for_unit("network.target")
85
86 # Bootstrap ceph-mon daemon
87 monA.succeed(
88 "sudo -u ceph ceph-authtool --create-keyring /tmp/ceph.mon.keyring --gen-key -n mon. --cap mon 'allow *'",
89 "sudo -u ceph ceph-authtool --create-keyring /etc/ceph/ceph.client.admin.keyring --gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow *' --cap mgr 'allow *'",
90 "sudo -u ceph ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.client.admin.keyring",
91 "monmaptool --create --add ${cfg.monA.name} ${cfg.monA.ip} --fsid ${cfg.clusterId} /tmp/monmap",
92 "sudo -u ceph ceph-mon --mkfs -i ${cfg.monA.name} --monmap /tmp/monmap --keyring /tmp/ceph.mon.keyring",
93 "sudo -u ceph touch /var/lib/ceph/mon/ceph-${cfg.monA.name}/done",
94 "systemctl start ceph-mon-${cfg.monA.name}",
95 )
96 monA.wait_for_unit("ceph-mon-${cfg.monA.name}")
97 monA.succeed("ceph mon enable-msgr2")
98 monA.succeed("ceph config set mon auth_allow_insecure_global_id_reclaim false")
99
100 # Can't check ceph status until a mon is up
101 monA.succeed("ceph -s | grep 'mon: 1 daemons'")
102
103 # Start the ceph-mgr daemon, after copying in the keyring
104 monA.succeed(
105 "sudo -u ceph mkdir -p /var/lib/ceph/mgr/ceph-${cfg.monA.name}/",
106 "ceph auth get-or-create mgr.${cfg.monA.name} mon 'allow profile mgr' osd 'allow *' mds 'allow *' > /var/lib/ceph/mgr/ceph-${cfg.monA.name}/keyring",
107 "systemctl start ceph-mgr-${cfg.monA.name}",
108 )
109 monA.wait_for_unit("ceph-mgr-a")
110 monA.wait_until_succeeds("ceph -s | grep 'quorum ${cfg.monA.name}'")
111 monA.wait_until_succeeds("ceph -s | grep 'mgr: ${cfg.monA.name}(active,'")
112
113 # Bootstrap OSDs
114 monA.succeed(
115 "mkdir -p /var/lib/ceph/osd/ceph-${cfg.osd0.name}",
116 "echo bluestore > /var/lib/ceph/osd/ceph-${cfg.osd0.name}/type",
117 "ln -sf /dev/vdb /var/lib/ceph/osd/ceph-${cfg.osd0.name}/block",
118 "mkdir -p /var/lib/ceph/osd/ceph-${cfg.osd1.name}",
119 "echo bluestore > /var/lib/ceph/osd/ceph-${cfg.osd1.name}/type",
120 "ln -sf /dev/vdc /var/lib/ceph/osd/ceph-${cfg.osd1.name}/block",
121 "mkdir -p /var/lib/ceph/osd/ceph-${cfg.osd2.name}",
122 "echo bluestore > /var/lib/ceph/osd/ceph-${cfg.osd2.name}/type",
123 "ln -sf /dev/vdd /var/lib/ceph/osd/ceph-${cfg.osd2.name}/block",
124 "ceph-authtool --create-keyring /var/lib/ceph/osd/ceph-${cfg.osd0.name}/keyring --name osd.${cfg.osd0.name} --add-key ${cfg.osd0.key}",
125 "ceph-authtool --create-keyring /var/lib/ceph/osd/ceph-${cfg.osd1.name}/keyring --name osd.${cfg.osd1.name} --add-key ${cfg.osd1.key}",
126 "ceph-authtool --create-keyring /var/lib/ceph/osd/ceph-${cfg.osd2.name}/keyring --name osd.${cfg.osd2.name} --add-key ${cfg.osd2.key}",
127 'echo \'{"cephx_secret": "${cfg.osd0.key}"}\' | ceph osd new ${cfg.osd0.uuid} -i -',
128 'echo \'{"cephx_secret": "${cfg.osd1.key}"}\' | ceph osd new ${cfg.osd1.uuid} -i -',
129 'echo \'{"cephx_secret": "${cfg.osd2.key}"}\' | ceph osd new ${cfg.osd2.uuid} -i -',
130 )
131
132 # Initialize the OSDs with regular filestore
133 monA.succeed(
134 "ceph-osd -i ${cfg.osd0.name} --mkfs --osd-uuid ${cfg.osd0.uuid}",
135 "ceph-osd -i ${cfg.osd1.name} --mkfs --osd-uuid ${cfg.osd1.uuid}",
136 "ceph-osd -i ${cfg.osd2.name} --mkfs --osd-uuid ${cfg.osd2.uuid}",
137 "chown -R ceph:ceph /var/lib/ceph/osd",
138 "systemctl start ceph-osd-${cfg.osd0.name}",
139 "systemctl start ceph-osd-${cfg.osd1.name}",
140 "systemctl start ceph-osd-${cfg.osd2.name}",
141 )
142 monA.wait_until_succeeds("ceph osd stat | grep -e '3 osds: 3 up[^,]*, 3 in'")
143 monA.wait_until_succeeds("ceph -s | grep 'mgr: ${cfg.monA.name}(active,'")
144 monA.wait_until_succeeds("ceph -s | grep 'HEALTH_OK'")
145
146 monA.succeed(
147 "ceph osd pool create single-node-test 32 32",
148 "ceph osd pool ls | grep 'single-node-test'",
149 "ceph osd pool rename single-node-test single-node-other-test",
150 "ceph osd pool ls | grep 'single-node-other-test'",
151 )
152 monA.wait_until_succeeds("ceph -s | grep '2 pools, 33 pgs'")
153 monA.succeed(
154 "ceph osd getcrushmap -o crush",
155 "crushtool -d crush -o decrushed",
156 "sed 's/step chooseleaf firstn 0 type host/step chooseleaf firstn 0 type osd/' decrushed > modcrush",
157 "crushtool -c modcrush -o recrushed",
158 "ceph osd setcrushmap -i recrushed",
159 "ceph osd pool set single-node-other-test size 2",
160 )
161 monA.wait_until_succeeds("ceph -s | grep 'HEALTH_OK'")
162 monA.wait_until_succeeds("ceph -s | grep '33 active+clean'")
163 monA.fail(
164 "ceph osd pool ls | grep 'multi-node-test'",
165 "ceph osd pool delete single-node-other-test single-node-other-test --yes-i-really-really-mean-it",
166 )
167
168 # Shut down ceph by stopping ceph.target.
169 monA.succeed("systemctl stop ceph.target")
170
171 # Start it up
172 monA.succeed("systemctl start ceph.target")
173 monA.wait_for_unit("ceph-mon-${cfg.monA.name}")
174 monA.wait_for_unit("ceph-mgr-${cfg.monA.name}")
175 monA.wait_for_unit("ceph-osd-${cfg.osd0.name}")
176 monA.wait_for_unit("ceph-osd-${cfg.osd1.name}")
177 monA.wait_for_unit("ceph-osd-${cfg.osd2.name}")
178
179 # Ensure the cluster comes back up again
180 monA.succeed("ceph -s | grep 'mon: 1 daemons'")
181 monA.wait_until_succeeds("ceph -s | grep 'quorum ${cfg.monA.name}'")
182 monA.wait_until_succeeds("ceph osd stat | grep -e '3 osds: 3 up[^,]*, 3 in'")
183 monA.wait_until_succeeds("ceph -s | grep 'mgr: ${cfg.monA.name}(active,'")
184 monA.wait_until_succeeds("ceph -s | grep 'HEALTH_OK'")
185 '';
186in {
187 name = "basic-single-node-ceph-cluster-bluestore";
188 meta = with pkgs.lib.maintainers; {
189 maintainers = [ lukegb ];
190 };
191
192 nodes = {
193 monA = generateHost { pkgs = pkgs; cephConfig = cephConfigMonA; networkConfig = networkMonA; };
194 };
195
196 testScript = testscript;
197})