]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "testcase_cxx.h" | |
5 | ||
6 | #include <errno.h> | |
7 | #include "test_cxx.h" | |
8 | #include "test_shared.h" | |
9 | #include "include/scope_guard.h" | |
10 | ||
11 | using namespace librados; | |
12 | ||
13 | namespace { | |
14 | ||
15 | void init_rand() { | |
16 | static bool seeded = false; | |
17 | if (!seeded) { | |
18 | seeded = true; | |
19 | int seed = getpid(); | |
20 | std::cout << "seed " << seed << std::endl; | |
21 | srand(seed); | |
22 | } | |
23 | } | |
24 | ||
25 | } // anonymous namespace | |
26 | ||
27 | std::string RadosTestPPNS::pool_name; | |
28 | Rados RadosTestPPNS::s_cluster; | |
29 | ||
30 | void RadosTestPPNS::SetUpTestCase() | |
31 | { | |
32 | pool_name = get_temp_pool_name(); | |
33 | ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster)); | |
34 | } | |
35 | ||
36 | void RadosTestPPNS::TearDownTestCase() | |
37 | { | |
38 | ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster)); | |
39 | } | |
40 | ||
41 | void RadosTestPPNS::SetUp() | |
42 | { | |
43 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
44 | bool requires; | |
45 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
46 | ASSERT_FALSE(requires); | |
47 | } | |
48 | ||
49 | void RadosTestPPNS::TearDown() | |
50 | { | |
51 | if (cleanup) | |
52 | cleanup_all_objects(ioctx); | |
53 | ioctx.close(); | |
54 | } | |
55 | ||
56 | void RadosTestPPNS::cleanup_all_objects(librados::IoCtx ioctx) | |
57 | { | |
58 | // remove all objects to avoid polluting other tests | |
59 | ioctx.snap_set_read(librados::SNAP_HEAD); | |
60 | ioctx.set_namespace(all_nspaces); | |
61 | for (NObjectIterator it = ioctx.nobjects_begin(); | |
62 | it != ioctx.nobjects_end(); ++it) { | |
63 | ioctx.locator_set_key(it->get_locator()); | |
64 | ioctx.set_namespace(it->get_nspace()); | |
65 | ASSERT_EQ(0, ioctx.remove(it->get_oid())); | |
66 | } | |
67 | } | |
68 | ||
69 | std::string RadosTestParamPPNS::pool_name; | |
70 | std::string RadosTestParamPPNS::cache_pool_name; | |
71 | Rados RadosTestParamPPNS::s_cluster; | |
72 | ||
73 | void RadosTestParamPPNS::SetUpTestCase() | |
74 | { | |
75 | pool_name = get_temp_pool_name(); | |
76 | ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster)); | |
77 | } | |
78 | ||
79 | void RadosTestParamPPNS::TearDownTestCase() | |
80 | { | |
81 | if (cache_pool_name.length()) { | |
82 | // tear down tiers | |
83 | bufferlist inbl; | |
84 | ASSERT_EQ(0, s_cluster.mon_command( | |
85 | "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name + | |
86 | "\"}", | |
87 | inbl, NULL, NULL)); | |
88 | ASSERT_EQ(0, s_cluster.mon_command( | |
89 | "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name + | |
90 | "\", \"tierpool\": \"" + cache_pool_name + "\"}", | |
91 | inbl, NULL, NULL)); | |
92 | ASSERT_EQ(0, s_cluster.mon_command( | |
93 | "{\"prefix\": \"osd pool delete\", \"pool\": \"" + cache_pool_name + | |
94 | "\", \"pool2\": \"" + cache_pool_name + "\", \"yes_i_really_really_mean_it\": true}", | |
95 | inbl, NULL, NULL)); | |
96 | cache_pool_name = ""; | |
97 | } | |
98 | ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster)); | |
99 | } | |
100 | ||
101 | void RadosTestParamPPNS::SetUp() | |
102 | { | |
103 | if (strcmp(GetParam(), "cache") == 0 && cache_pool_name.empty()) { | |
104 | cache_pool_name = get_temp_pool_name(); | |
105 | bufferlist inbl; | |
106 | ASSERT_EQ(0, cluster.mon_command( | |
107 | "{\"prefix\": \"osd pool create\", \"pool\": \"" + cache_pool_name + | |
108 | "\", \"pg_num\": 4}", | |
109 | inbl, NULL, NULL)); | |
110 | ASSERT_EQ(0, cluster.mon_command( | |
111 | "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name + | |
112 | "\", \"tierpool\": \"" + cache_pool_name + | |
113 | "\", \"force_nonempty\": \"--force-nonempty\" }", | |
114 | inbl, NULL, NULL)); | |
115 | ASSERT_EQ(0, cluster.mon_command( | |
116 | "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name + | |
117 | "\", \"overlaypool\": \"" + cache_pool_name + "\"}", | |
118 | inbl, NULL, NULL)); | |
119 | ASSERT_EQ(0, cluster.mon_command( | |
120 | "{\"prefix\": \"osd tier cache-mode\", \"pool\": \"" + cache_pool_name + | |
121 | "\", \"mode\": \"writeback\"}", | |
122 | inbl, NULL, NULL)); | |
123 | cluster.wait_for_latest_osdmap(); | |
124 | } | |
125 | ||
126 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
127 | bool requires; | |
128 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
129 | ASSERT_FALSE(requires); | |
130 | } | |
131 | ||
132 | void RadosTestParamPPNS::TearDown() | |
133 | { | |
134 | if (cleanup) | |
135 | cleanup_all_objects(ioctx); | |
136 | ioctx.close(); | |
137 | } | |
138 | ||
139 | void RadosTestParamPPNS::cleanup_all_objects(librados::IoCtx ioctx) | |
140 | { | |
141 | // remove all objects to avoid polluting other tests | |
142 | ioctx.snap_set_read(librados::SNAP_HEAD); | |
143 | ioctx.set_namespace(all_nspaces); | |
144 | for (NObjectIterator it = ioctx.nobjects_begin(); | |
145 | it != ioctx.nobjects_end(); ++it) { | |
146 | ioctx.locator_set_key(it->get_locator()); | |
147 | ioctx.set_namespace(it->get_nspace()); | |
148 | ASSERT_EQ(0, ioctx.remove(it->get_oid())); | |
149 | } | |
150 | } | |
151 | ||
152 | std::string RadosTestECPPNS::pool_name; | |
153 | Rados RadosTestECPPNS::s_cluster; | |
154 | ||
155 | void RadosTestECPPNS::SetUpTestCase() | |
156 | { | |
157 | pool_name = get_temp_pool_name(); | |
158 | ASSERT_EQ("", create_one_ec_pool_pp(pool_name, s_cluster)); | |
159 | } | |
160 | ||
161 | void RadosTestECPPNS::TearDownTestCase() | |
162 | { | |
163 | ASSERT_EQ(0, destroy_one_ec_pool_pp(pool_name, s_cluster)); | |
164 | } | |
165 | ||
166 | void RadosTestECPPNS::SetUp() | |
167 | { | |
168 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
169 | bool requires; | |
170 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
171 | ASSERT_TRUE(requires); | |
172 | ASSERT_EQ(0, ioctx.pool_required_alignment2(&alignment)); | |
173 | ASSERT_NE(0U, alignment); | |
174 | } | |
175 | ||
176 | void RadosTestECPPNS::TearDown() | |
177 | { | |
178 | if (cleanup) | |
179 | cleanup_all_objects(ioctx); | |
180 | ioctx.close(); | |
181 | } | |
182 | ||
183 | std::string RadosTestPP::pool_name; | |
184 | Rados RadosTestPP::s_cluster; | |
185 | ||
186 | void RadosTestPP::SetUpTestCase() | |
187 | { | |
188 | init_rand(); | |
189 | ||
190 | pool_name = get_temp_pool_name(); | |
191 | ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster)); | |
192 | } | |
193 | ||
194 | void RadosTestPP::TearDownTestCase() | |
195 | { | |
196 | ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster)); | |
197 | } | |
198 | ||
199 | void RadosTestPP::SetUp() | |
200 | { | |
201 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
202 | nspace = get_temp_pool_name(); | |
203 | ioctx.set_namespace(nspace); | |
204 | bool requires; | |
205 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
206 | ASSERT_FALSE(requires); | |
207 | } | |
208 | ||
209 | void RadosTestPP::TearDown() | |
210 | { | |
211 | if (cleanup) { | |
212 | cleanup_default_namespace(ioctx); | |
213 | cleanup_namespace(ioctx, nspace); | |
214 | } | |
215 | ioctx.close(); | |
216 | } | |
217 | ||
218 | void RadosTestPP::cleanup_default_namespace(librados::IoCtx ioctx) | |
219 | { | |
220 | // remove all objects from the default namespace to avoid polluting | |
221 | // other tests | |
222 | cleanup_namespace(ioctx, ""); | |
223 | } | |
224 | ||
225 | void RadosTestPP::cleanup_namespace(librados::IoCtx ioctx, std::string ns) | |
226 | { | |
227 | ioctx.snap_set_read(librados::SNAP_HEAD); | |
228 | ioctx.set_namespace(ns); | |
9f95a23c | 229 | int tries = 20; |
11fdf7f2 TL |
230 | while (--tries) { |
231 | int got_enoent = 0; | |
232 | for (NObjectIterator it = ioctx.nobjects_begin(); | |
233 | it != ioctx.nobjects_end(); ++it) { | |
234 | ioctx.locator_set_key(it->get_locator()); | |
235 | ObjectWriteOperation op; | |
236 | op.remove(); | |
237 | librados::AioCompletion *completion = s_cluster.aio_create_completion(); | |
238 | auto sg = make_scope_guard([&] { completion->release(); }); | |
239 | ASSERT_EQ(0, ioctx.aio_operate(it->get_oid(), completion, &op, | |
240 | librados::OPERATION_IGNORE_CACHE)); | |
9f95a23c | 241 | completion->wait_for_complete(); |
11fdf7f2 TL |
242 | if (completion->get_return_value() == -ENOENT) { |
243 | ++got_enoent; | |
9f95a23c TL |
244 | std::cout << " got ENOENT removing " << it->get_oid() |
245 | << " in ns " << ns << std::endl; | |
11fdf7f2 TL |
246 | } else { |
247 | ASSERT_EQ(0, completion->get_return_value()); | |
248 | } | |
249 | } | |
250 | if (!got_enoent) { | |
251 | break; | |
252 | } | |
253 | std::cout << " got ENOENT on " << got_enoent | |
254 | << " objects, waiting a bit for snap" | |
255 | << " trimming before retrying " << tries << " more times..." | |
256 | << std::endl; | |
257 | sleep(1); | |
258 | } | |
259 | if (tries == 0) { | |
9f95a23c TL |
260 | std::cout << "failed to clean up; probably need to scrub purged_snaps." |
261 | << std::endl; | |
11fdf7f2 TL |
262 | } |
263 | } | |
264 | ||
265 | std::string RadosTestParamPP::pool_name; | |
266 | std::string RadosTestParamPP::cache_pool_name; | |
267 | Rados RadosTestParamPP::s_cluster; | |
268 | ||
269 | void RadosTestParamPP::SetUpTestCase() | |
270 | { | |
271 | pool_name = get_temp_pool_name(); | |
272 | ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster)); | |
273 | } | |
274 | ||
275 | void RadosTestParamPP::TearDownTestCase() | |
276 | { | |
277 | if (cache_pool_name.length()) { | |
278 | // tear down tiers | |
279 | bufferlist inbl; | |
280 | ASSERT_EQ(0, s_cluster.mon_command( | |
281 | "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name + | |
282 | "\"}", | |
283 | inbl, NULL, NULL)); | |
284 | ASSERT_EQ(0, s_cluster.mon_command( | |
285 | "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name + | |
286 | "\", \"tierpool\": \"" + cache_pool_name + "\"}", | |
287 | inbl, NULL, NULL)); | |
288 | ASSERT_EQ(0, s_cluster.mon_command( | |
289 | "{\"prefix\": \"osd pool delete\", \"pool\": \"" + cache_pool_name + | |
290 | "\", \"pool2\": \"" + cache_pool_name + "\", \"yes_i_really_really_mean_it\": true}", | |
291 | inbl, NULL, NULL)); | |
292 | cache_pool_name = ""; | |
293 | } | |
294 | ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster)); | |
295 | } | |
296 | ||
297 | void RadosTestParamPP::SetUp() | |
298 | { | |
299 | if (strcmp(GetParam(), "cache") == 0 && cache_pool_name.empty()) { | |
300 | cache_pool_name = get_temp_pool_name(); | |
301 | bufferlist inbl; | |
302 | ASSERT_EQ(0, cluster.mon_command( | |
303 | "{\"prefix\": \"osd pool create\", \"pool\": \"" + cache_pool_name + | |
304 | "\", \"pg_num\": 4}", | |
305 | inbl, NULL, NULL)); | |
306 | ASSERT_EQ(0, cluster.mon_command( | |
307 | "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name + | |
308 | "\", \"tierpool\": \"" + cache_pool_name + | |
309 | "\", \"force_nonempty\": \"--force-nonempty\" }", | |
310 | inbl, NULL, NULL)); | |
311 | ASSERT_EQ(0, cluster.mon_command( | |
312 | "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name + | |
313 | "\", \"overlaypool\": \"" + cache_pool_name + "\"}", | |
314 | inbl, NULL, NULL)); | |
315 | ASSERT_EQ(0, cluster.mon_command( | |
316 | "{\"prefix\": \"osd tier cache-mode\", \"pool\": \"" + cache_pool_name + | |
317 | "\", \"mode\": \"writeback\"}", | |
318 | inbl, NULL, NULL)); | |
319 | cluster.wait_for_latest_osdmap(); | |
320 | } | |
321 | ||
322 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
323 | nspace = get_temp_pool_name(); | |
324 | ioctx.set_namespace(nspace); | |
325 | bool requires; | |
326 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
327 | ASSERT_FALSE(requires); | |
328 | } | |
329 | ||
330 | void RadosTestParamPP::TearDown() | |
331 | { | |
332 | if (cleanup) { | |
333 | cleanup_default_namespace(ioctx); | |
334 | cleanup_namespace(ioctx, nspace); | |
335 | } | |
336 | ioctx.close(); | |
337 | } | |
338 | ||
339 | void RadosTestParamPP::cleanup_default_namespace(librados::IoCtx ioctx) | |
340 | { | |
341 | // remove all objects from the default namespace to avoid polluting | |
342 | // other tests | |
343 | cleanup_namespace(ioctx, ""); | |
344 | } | |
345 | ||
346 | void RadosTestParamPP::cleanup_namespace(librados::IoCtx ioctx, std::string ns) | |
347 | { | |
348 | ioctx.snap_set_read(librados::SNAP_HEAD); | |
349 | ioctx.set_namespace(ns); | |
350 | for (NObjectIterator it = ioctx.nobjects_begin(); | |
351 | it != ioctx.nobjects_end(); ++it) { | |
352 | ioctx.locator_set_key(it->get_locator()); | |
353 | ASSERT_EQ(0, ioctx.remove(it->get_oid())); | |
354 | } | |
355 | } | |
356 | ||
357 | std::string RadosTestECPP::pool_name; | |
358 | Rados RadosTestECPP::s_cluster; | |
359 | ||
360 | void RadosTestECPP::SetUpTestCase() | |
361 | { | |
362 | pool_name = get_temp_pool_name(); | |
363 | ASSERT_EQ("", create_one_ec_pool_pp(pool_name, s_cluster)); | |
364 | } | |
365 | ||
366 | void RadosTestECPP::TearDownTestCase() | |
367 | { | |
368 | ASSERT_EQ(0, destroy_one_ec_pool_pp(pool_name, s_cluster)); | |
369 | } | |
370 | ||
371 | void RadosTestECPP::SetUp() | |
372 | { | |
373 | ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); | |
374 | nspace = get_temp_pool_name(); | |
375 | ioctx.set_namespace(nspace); | |
376 | bool requires; | |
377 | ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires)); | |
378 | ASSERT_TRUE(requires); | |
379 | ASSERT_EQ(0, ioctx.pool_required_alignment2(&alignment)); | |
380 | ASSERT_NE(0U, alignment); | |
381 | } | |
382 | ||
383 | void RadosTestECPP::TearDown() | |
384 | { | |
385 | if (cleanup) { | |
386 | cleanup_default_namespace(ioctx); | |
387 | cleanup_namespace(ioctx, nspace); | |
388 | } | |
389 | ioctx.close(); | |
390 | } | |
391 |