]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rados/test_rados_tool.sh
5325743f23d596703c6d722e5b9d8525ddcd8bb8
[ceph.git] / ceph / qa / workunits / rados / test_rados_tool.sh
1 #!/usr/bin/env bash
2
3 set -x
4
5 die() {
6 echo "$@"
7 exit 1
8 }
9
10 usage() {
11 cat <<EOF
12 test_rados_tool.sh: tests rados_tool
13 -c: RADOS configuration file to use [optional]
14 -k: keep temp files
15 -h: this help message
16 -p: set temporary pool to use [optional]
17 EOF
18 }
19
20 do_run() {
21 if [ "$1" == "--tee" ]; then
22 shift
23 tee_out="$1"
24 shift
25 "$@" | tee $tee_out
26 else
27 "$@"
28 fi
29 }
30
31 run_expect_fail() {
32 echo "RUN_EXPECT_FAIL: " "$@"
33 do_run "$@"
34 [ $? -eq 0 ] && die "expected failure, but got success! cmd: $@"
35 }
36
37 run_expect_succ() {
38 echo "RUN_EXPECT_SUCC: " "$@"
39 do_run "$@"
40 [ $? -ne 0 ] && die "expected success, but got failure! cmd: $@"
41 }
42
43 run_expect_nosignal() {
44 echo "RUN_EXPECT_NOSIGNAL: " "$@"
45 do_run "$@"
46 [ $? -ge 128 ] && die "expected success or fail, but got signal! cmd: $@"
47 }
48
49 run() {
50 echo "RUN: " $@
51 do_run "$@"
52 }
53
54 if [ -n "$CEPH_BIN" ] ; then
55 # CMake env
56 RADOS_TOOL="$CEPH_BIN/rados"
57 CEPH_TOOL="$CEPH_BIN/ceph"
58 else
59 # executables should be installed by the QA env
60 RADOS_TOOL=$(which rados)
61 CEPH_TOOL=$(which ceph)
62 fi
63
64 KEEP_TEMP_FILES=0
65 POOL=trs_pool
66 POOL_CP_TARGET=trs_pool.2
67 POOL_EC=trs_pool_ec
68
69 [ -x "$RADOS_TOOL" ] || die "couldn't find $RADOS_TOOL binary to test"
70 [ -x "$CEPH_TOOL" ] || die "couldn't find $CEPH_TOOL binary to test"
71
72 while getopts "c:hkp:" flag; do
73 case $flag in
74 c) RADOS_TOOL="$RADOS_TOOL -c $OPTARG";;
75 k) KEEP_TEMP_FILES=1;;
76 h) usage; exit 0;;
77 p) POOL=$OPTARG;;
78 *) echo; usage; exit 1;;
79 esac
80 done
81
82 TDIR=`mktemp -d -t test_rados_tool.XXXXXXXXXX` || die "mktemp failed"
83 [ $KEEP_TEMP_FILES -eq 0 ] && trap "rm -rf ${TDIR}; exit" INT TERM EXIT
84
85 # ensure rados doesn't segfault without --pool
86 run_expect_nosignal "$RADOS_TOOL" --snap "asdf" ls
87 run_expect_nosignal "$RADOS_TOOL" --snapid "0" ls
88 run_expect_nosignal "$RADOS_TOOL" --object_locator "asdf" ls
89 run_expect_nosignal "$RADOS_TOOL" --namespace "asdf" ls
90
91 run_expect_succ "$CEPH_TOOL" osd pool create "$POOL" 8
92 run_expect_succ "$CEPH_TOOL" osd erasure-code-profile set myprofile k=2 m=1 stripe_unit=2K crush-failure-domain=osd --force
93 run_expect_succ "$CEPH_TOOL" osd pool create "$POOL_EC" 100 100 erasure myprofile
94
95
96 # expb happens to be the empty export for legacy reasons
97 run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expb"
98
99 # expa has objects foo, foo2 and bar
100 run_expect_succ "$RADOS_TOOL" -p "$POOL" put foo /etc/fstab
101 run_expect_succ "$RADOS_TOOL" -p "$POOL" put foo2 /etc/fstab
102 run_expect_succ "$RADOS_TOOL" -p "$POOL" put bar /etc/fstab
103 run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expa"
104
105 # expc has foo and foo2 with some attributes and omaps set
106 run_expect_succ "$RADOS_TOOL" -p "$POOL" rm bar
107 run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothbrush" "toothbrush"
108 run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothpaste" "crest"
109 run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapval foo "rados.floss" "myfloss"
110 run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo2 "rados.toothbrush" "green"
111 run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapheader foo2 "foo2.header"
112 run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expc"
113
114 # make sure that --create works
115 run "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
116 run_expect_succ "$RADOS_TOOL" -p "$POOL" --create import "$TDIR/expa"
117
118 # make sure that lack of --create fails
119 run_expect_succ "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
120 run_expect_fail "$RADOS_TOOL" -p "$POOL" import "$TDIR/expa"
121
122 run_expect_succ "$RADOS_TOOL" -p "$POOL" --create import "$TDIR/expa"
123
124 # inaccessible import src should fail
125 run_expect_fail "$RADOS_TOOL" -p "$POOL" import "$TDIR/dir_nonexistent"
126
127 # export an empty pool to test purge
128 run_expect_succ "$RADOS_TOOL" purge "$POOL" --yes-i-really-really-mean-it
129 run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/empty"
130 cmp -s "$TDIR/expb" "$TDIR/empty" \
131 || die "failed to export the same stuff we imported!"
132 rm -f "$TDIR/empty"
133
134 # import some stuff with extended attributes on it
135 run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
136 VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
137 [ ${VAL} = "toothbrush" ] || die "Invalid attribute after import"
138
139 # the second time, the xattrs should match, so there should be nothing to do.
140 run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
141 VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
142 [ "${VAL}" = "toothbrush" ] || die "Invalid attribute after second import"
143
144 # Now try with --no-overwrite option after changing an attribute
145 run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothbrush" "dentist"
146 run_expect_succ "$RADOS_TOOL" -p "$POOL" import --no-overwrite "$TDIR/expc"
147 VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
148 [ "${VAL}" = "dentist" ] || die "Invalid attribute after second import"
149
150 # now force it to copy everything
151 run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
152 VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
153 [ "${VAL}" = "toothbrush" ] || die "Invalid attribute after second import"
154
155 # test copy pool
156 run "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
157 run "$CEPH_TOOL" osd pool rm "$POOL_CP_TARGET" "$POOL_CP_TARGET" --yes-i-really-really-mean-it
158 run_expect_succ "$CEPH_TOOL" osd pool create "$POOL" 8
159 run_expect_succ "$CEPH_TOOL" osd pool create "$POOL_CP_TARGET" 8
160
161 # create src files
162 mkdir -p "$TDIR/dir_cp_src"
163 for i in `seq 1 5`; do
164 fname="$TDIR/dir_cp_src/f.$i"
165 objname="f.$i"
166 dd if=/dev/urandom of="$fname" bs=$((1024*1024)) count=$i
167 run_expect_succ "$RADOS_TOOL" -p "$POOL" put $objname "$fname"
168
169 # a few random attrs
170 for j in `seq 1 4`; do
171 rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
172 run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr $objname attr.$j "$rand_str"
173 run_expect_succ --tee "$fname.attr.$j" "$RADOS_TOOL" -p "$POOL" getxattr $objname attr.$j
174 done
175
176 rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
177 run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapheader $objname "$rand_str"
178 run_expect_succ --tee "$fname.omap.header" "$RADOS_TOOL" -p "$POOL" getomapheader $objname
179
180 # a few random omap keys
181 for j in `seq 1 4`; do
182 rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
183 run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapval $objname key.$j "$rand_str"
184 done
185 run_expect_succ --tee "$fname.omap.vals" "$RADOS_TOOL" -p "$POOL" listomapvals $objname
186 done
187
188 run_expect_succ "$RADOS_TOOL" cppool "$POOL" "$POOL_CP_TARGET"
189
190 mkdir -p "$TDIR/dir_cp_dst"
191 for i in `seq 1 5`; do
192 fname="$TDIR/dir_cp_dst/f.$i"
193 objname="f.$i"
194 run_expect_succ "$RADOS_TOOL" -p "$POOL_CP_TARGET" get $objname "$fname"
195
196 # a few random attrs
197 for j in `seq 1 4`; do
198 run_expect_succ --tee "$fname.attr.$j" "$RADOS_TOOL" -p "$POOL_CP_TARGET" getxattr $objname attr.$j
199 done
200
201 run_expect_succ --tee "$fname.omap.header" "$RADOS_TOOL" -p "$POOL_CP_TARGET" getomapheader $objname
202 run_expect_succ --tee "$fname.omap.vals" "$RADOS_TOOL" -p "$POOL_CP_TARGET" listomapvals $objname
203 done
204
205 diff -q -r "$TDIR/dir_cp_src" "$TDIR/dir_cp_dst" \
206 || die "copy pool validation failed!"
207
208 for opt in \
209 block-size \
210 concurrent-ios \
211 min-object-size \
212 max-object-size \
213 min-op-len \
214 max-op-len \
215 max-ops \
216 max-backlog \
217 target-throughput \
218 read-percent \
219 num-objects \
220 run-length \
221 ; do
222 run_expect_succ "$RADOS_TOOL" --$opt 4 df
223 run_expect_fail "$RADOS_TOOL" --$opt 4k df
224 done
225
226 run_expect_succ "$RADOS_TOOL" lock list f.1 --lock-duration 4 --pool "$POOL"
227 echo # previous command doesn't output an end of line: issue #9735
228 run_expect_fail "$RADOS_TOOL" lock list f.1 --lock-duration 4k --pool "$POOL"
229
230 run_expect_succ "$RADOS_TOOL" mksnap snap1 --pool "$POOL"
231 snapid=$("$RADOS_TOOL" lssnap --pool "$POOL" | grep snap1 | cut -f1)
232 [ $? -ne 0 ] && die "expected success, but got failure! cmd: \"$RADOS_TOOL\" lssnap --pool \"$POOL\" | grep snap1 | cut -f1"
233 run_expect_succ "$RADOS_TOOL" ls --pool "$POOL" --snapid="$snapid"
234 run_expect_fail "$RADOS_TOOL" ls --pool "$POOL" --snapid="$snapid"k
235
236 run_expect_succ "$RADOS_TOOL" truncate f.1 0 --pool "$POOL"
237 run_expect_fail "$RADOS_TOOL" truncate f.1 0k --pool "$POOL"
238
239 run "$CEPH_TOOL" osd pool rm delete_me_mkpool_test delete_me_mkpool_test --yes-i-really-really-mean-it
240 run_expect_succ "$CEPH_TOOL" osd pool create delete_me_mkpool_test 1
241
242 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 write
243 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 1k write
244 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 write --format json --output "$TDIR/bench.json"
245 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 1 write --output "$TDIR/bench.json"
246 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --format json --no-cleanup
247 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 rand --format json
248 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 rand -f json
249 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 seq --format json
250 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 seq -f json
251 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-omap
252 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-object
253 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr
254 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-object
255 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-omap
256 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-omap --write-object
257 run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-omap --write-object
258 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-omap
259 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-object
260 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr
261 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-object
262 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-omap
263 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-omap --write-object
264 run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-omap --write-object
265
266 for i in $("$RADOS_TOOL" --pool "$POOL" ls | grep "benchmark_data"); do
267 "$RADOS_TOOL" --pool "$POOL" truncate $i 0
268 done
269
270 run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 rand
271 run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 seq
272
273 set -e
274
275 OBJ=test_rados_obj
276
277 expect_false()
278 {
279 if "$@"; then return 1; else return 0; fi
280 }
281
282 cleanup() {
283 $RADOS_TOOL -p $POOL rm $OBJ > /dev/null 2>&1 || true
284 $RADOS_TOOL -p $POOL_EC rm $OBJ > /dev/null 2>&1 || true
285 }
286
287 test_omap() {
288 cleanup
289 for i in $(seq 1 1 10)
290 do
291 if [ $(($i % 2)) -eq 0 ]; then
292 $RADOS_TOOL -p $POOL setomapval $OBJ $i $i
293 else
294 echo -n "$i" | $RADOS_TOOL -p $POOL setomapval $OBJ $i
295 fi
296 $RADOS_TOOL -p $POOL getomapval $OBJ $i | grep -q "|$i|\$"
297 done
298 $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 10
299 for i in $(seq 1 1 5)
300 do
301 $RADOS_TOOL -p $POOL rmomapkey $OBJ $i
302 done
303 $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 5
304 $RADOS_TOOL -p $POOL clearomap $OBJ
305 $RADOS_TOOL -p $POOL listomapvals $OBJ | wc -l | grep 0
306 cleanup
307
308 for i in $(seq 1 1 10)
309 do
310 dd if=/dev/urandom bs=128 count=1 > $TDIR/omap_key
311 if [ $(($i % 2)) -eq 0 ]; then
312 $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key setomapval $OBJ $i
313 else
314 echo -n "$i" | $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key setomapval $OBJ
315 fi
316 $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key getomapval $OBJ | grep -q "|$i|\$"
317 $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key rmomapkey $OBJ
318 $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 0
319 done
320 cleanup
321 }
322
323 test_xattr() {
324 cleanup
325 $RADOS_TOOL -p $POOL put $OBJ /etc/passwd
326 V1=`mktemp fooattrXXXXXXX`
327 V2=`mktemp fooattrXXXXXXX`
328 echo -n fooval > $V1
329 expect_false $RADOS_TOOL -p $POOL setxattr $OBJ 2>/dev/null
330 expect_false $RADOS_TOOL -p $POOL setxattr $OBJ foo fooval extraarg 2>/dev/null
331 $RADOS_TOOL -p $POOL setxattr $OBJ foo fooval
332 $RADOS_TOOL -p $POOL getxattr $OBJ foo > $V2
333 cmp $V1 $V2
334 cat $V1 | $RADOS_TOOL -p $POOL setxattr $OBJ bar
335 $RADOS_TOOL -p $POOL getxattr $OBJ bar > $V2
336 cmp $V1 $V2
337 $RADOS_TOOL -p $POOL listxattr $OBJ > $V1
338 grep -q foo $V1
339 grep -q bar $V1
340 [ `cat $V1 | wc -l` -eq 2 ]
341 rm $V1 $V2
342 cleanup
343 }
344 test_rmobj() {
345 p=`uuidgen`
346 $CEPH_TOOL osd pool create $p 1
347 $CEPH_TOOL osd pool set-quota $p max_objects 1
348 V1=`mktemp fooattrXXXXXXX`
349 $RADOS_TOOL put $OBJ $V1 -p $p
350 while ! $CEPH_TOOL osd dump | grep 'full_quota max_objects'
351 do
352 sleep 2
353 done
354 $RADOS_TOOL -p $p rm $OBJ --force-full
355 $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
356 rm $V1
357 }
358
359 test_ls() {
360 echo "Testing rados ls command"
361 p=`uuidgen`
362 $CEPH_TOOL osd pool create $p 1
363 NS=10
364 OBJS=20
365 # Include default namespace (0) in the total
366 TOTAL=$(expr $OBJS \* $(expr $NS + 1))
367
368 for nsnum in `seq 0 $NS`
369 do
370 for onum in `seq 1 $OBJS`
371 do
372 if [ "$nsnum" = "0" ];
373 then
374 "$RADOS_TOOL" -p $p put obj${onum} /etc/fstab 2> /dev/null
375 else
376 "$RADOS_TOOL" -p $p -N "NS${nsnum}" put obj${onum} /etc/fstab 2> /dev/null
377 fi
378 done
379 done
380 CHECK=$("$RADOS_TOOL" -p $p ls 2> /dev/null | wc -l)
381 if [ "$OBJS" -ne "$CHECK" ];
382 then
383 die "Created $OBJS objects in default namespace but saw $CHECK"
384 fi
385 TESTNS=NS${NS}
386 CHECK=$("$RADOS_TOOL" -p $p -N $TESTNS ls 2> /dev/null | wc -l)
387 if [ "$OBJS" -ne "$CHECK" ];
388 then
389 die "Created $OBJS objects in $TESTNS namespace but saw $CHECK"
390 fi
391 CHECK=$("$RADOS_TOOL" -p $p --all ls 2> /dev/null | wc -l)
392 if [ "$TOTAL" -ne "$CHECK" ];
393 then
394 die "Created $TOTAL objects but saw $CHECK"
395 fi
396
397 $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
398 }
399
400 test_cleanup() {
401 echo "Testing rados cleanup command"
402 p=`uuidgen`
403 $CEPH_TOOL osd pool create $p 1
404 NS=5
405 OBJS=4
406 # Include default namespace (0) in the total
407 TOTAL=$(expr $OBJS \* $(expr $NS + 1))
408
409 for nsnum in `seq 0 $NS`
410 do
411 for onum in `seq 1 $OBJS`
412 do
413 if [ "$nsnum" = "0" ];
414 then
415 "$RADOS_TOOL" -p $p put obj${onum} /etc/fstab 2> /dev/null
416 else
417 "$RADOS_TOOL" -p $p -N "NS${nsnum}" put obj${onum} /etc/fstab 2> /dev/null
418 fi
419 done
420 done
421
422 $RADOS_TOOL -p $p --all ls > $TDIR/before.ls.out 2> /dev/null
423
424 $RADOS_TOOL -p $p bench 3 write --no-cleanup 2> /dev/null
425 $RADOS_TOOL -p $p -N NS1 bench 3 write --no-cleanup 2> /dev/null
426 $RADOS_TOOL -p $p -N NS2 bench 3 write --no-cleanup 2> /dev/null
427 $RADOS_TOOL -p $p -N NS3 bench 3 write --no-cleanup 2> /dev/null
428 # Leave dangling objects without a benchmark_last_metadata in NS4
429 expect_false timeout 3 $RADOS_TOOL -p $p -N NS4 bench 30 write --no-cleanup 2> /dev/null
430 $RADOS_TOOL -p $p -N NS5 bench 3 write --no-cleanup 2> /dev/null
431
432 $RADOS_TOOL -p $p -N NS3 cleanup 2> /dev/null
433 #echo "Check NS3 after specific cleanup"
434 CHECK=$($RADOS_TOOL -p $p -N NS3 ls | wc -l)
435 if [ "$OBJS" -ne "$CHECK" ] ;
436 then
437 die "Expected $OBJS objects in NS3 but saw $CHECK"
438 fi
439
440 #echo "Try to cleanup all"
441 $RADOS_TOOL -p $p --all cleanup
442 #echo "Check all namespaces"
443 $RADOS_TOOL -p $p --all ls > $TDIR/after.ls.out 2> /dev/null
444 CHECK=$(cat $TDIR/after.ls.out | wc -l)
445 if [ "$TOTAL" -ne "$CHECK" ];
446 then
447 die "Expected $TOTAL objects but saw $CHECK"
448 fi
449 if ! diff $TDIR/before.ls.out $TDIR/after.ls.out
450 then
451 die "Different objects found after cleanup"
452 fi
453
454 set +e
455 run_expect_fail $RADOS_TOOL -p $p cleanup --prefix illegal_prefix
456 run_expect_succ $RADOS_TOOL -p $p cleanup --prefix benchmark_data_otherhost
457 set -e
458
459 $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
460 }
461
462 function test_append()
463 {
464 cleanup
465
466 # create object
467 touch ./rados_append_null
468 $RADOS_TOOL -p $POOL append $OBJ ./rados_append_null
469 $RADOS_TOOL -p $POOL get $OBJ ./rados_append_0_out
470 cmp ./rados_append_null ./rados_append_0_out
471
472 # append 4k, total size 4k
473 dd if=/dev/zero of=./rados_append_4k bs=4k count=1
474 $RADOS_TOOL -p $POOL append $OBJ ./rados_append_4k
475 $RADOS_TOOL -p $POOL get $OBJ ./rados_append_4k_out
476 cmp ./rados_append_4k ./rados_append_4k_out
477
478 # append 4k, total size 8k
479 $RADOS_TOOL -p $POOL append $OBJ ./rados_append_4k
480 $RADOS_TOOL -p $POOL get $OBJ ./rados_append_4k_out
481 read_size=`ls -l ./rados_append_4k_out | awk -F ' ' '{print $5}'`
482 if [ 8192 -ne $read_size ];
483 then
484 die "Append failed expecting 8192 read $read_size"
485 fi
486
487 # append 10M, total size 10493952
488 dd if=/dev/zero of=./rados_append_10m bs=10M count=1
489 $RADOS_TOOL -p $POOL append $OBJ ./rados_append_10m
490 $RADOS_TOOL -p $POOL get $OBJ ./rados_append_10m_out
491 read_size=`ls -l ./rados_append_10m_out | awk -F ' ' '{print $5}'`
492 if [ 10493952 -ne $read_size ];
493 then
494 die "Append failed expecting 10493952 read $read_size"
495 fi
496
497 # cleanup
498 cleanup
499
500 # create object
501 $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_null
502 $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_0_out
503 cmp rados_append_null rados_append_0_out
504
505 # append 4k, total size 4k
506 $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_4k
507 $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_4k_out
508 cmp rados_append_4k rados_append_4k_out
509
510 # append 4k, total size 8k
511 $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_4k
512 $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_4k_out
513 read_size=`ls -l ./rados_append_4k_out | awk -F ' ' '{print $5}'`
514 if [ 8192 -ne $read_size ];
515 then
516 die "Append failed expecting 8192 read $read_size"
517 fi
518
519 # append 10M, total size 10493952
520 $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_10m
521 $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_10m_out
522 read_size=`ls -l ./rados_append_10m_out | awk -F ' ' '{print $5}'`
523 if [ 10493952 -ne $read_size ];
524 then
525 die "Append failed expecting 10493952 read $read_size"
526 fi
527
528 cleanup
529 rm -rf ./rados_append_null ./rados_append_0_out
530 rm -rf ./rados_append_4k ./rados_append_4k_out ./rados_append_10m ./rados_append_10m_out
531 }
532
533 function test_put()
534 {
535 # rados put test:
536 cleanup
537
538 # create file in local fs
539 dd if=/dev/urandom of=rados_object_10k bs=1K count=10
540
541 # test put command
542 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k
543 $RADOS_TOOL -p $POOL get $OBJ ./rados_object_10k_out
544 cmp ./rados_object_10k ./rados_object_10k_out
545 cleanup
546
547 # test put command with offset 0
548 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k --offset 0
549 $RADOS_TOOL -p $POOL get $OBJ ./rados_object_offset_0_out
550 cmp ./rados_object_10k ./rados_object_offset_0_out
551 cleanup
552
553 # test put command with offset 1000
554 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k --offset 1000
555 $RADOS_TOOL -p $POOL get $OBJ ./rados_object_offset_1000_out
556 cmp ./rados_object_10k ./rados_object_offset_1000_out 0 1000
557 cleanup
558
559 rm -rf ./rados_object_10k ./rados_object_10k_out ./rados_object_offset_0_out ./rados_object_offset_1000_out
560 }
561
562 function test_stat()
563 {
564 bluestore=$("$CEPH_TOOL" osd metadata | grep '"osd_objectstore": "bluestore"' | cut -f1)
565 # create file in local fs
566 dd if=/dev/urandom of=rados_object_128k bs=64K count=2
567
568 # rados df test (replicated_pool):
569 $RADOS_TOOL purge $POOL --yes-i-really-really-mean-it
570 $CEPH_TOOL osd pool rm $POOL $POOL --yes-i-really-really-mean-it
571 $CEPH_TOOL osd pool create $POOL 8
572 $CEPH_TOOL osd pool set $POOL size 3
573
574 # put object with 1 MB gap in front
575 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=1048576
576 MATCH_CNT=0
577 if [ "" == "$bluestore" ];
578 then
579 STORED=1.1
580 STORED_UNIT="MiB"
581 else
582 STORED=384
583 STORED_UNIT="KiB"
584 fi
585 for i in {1..60}
586 do
587 IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
588 [[ -z $IN ]] && sleep 1 && continue
589 IFS=' ' read -ra VALS <<< "$IN"
590
591 # verification is a bit tricky due to stats report's eventual model
592 # VALS[1] - STORED
593 # VALS[2] - STORED units
594 # VALS[3] - OBJECTS
595 # VALS[5] - COPIES
596 # VALS[12] - WR_OPS
597 # VALS[13] - WR
598 # VALS[14] - WR uints
599 # implies replication factor 3
600 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "1" ] && [ ${VALS[13]} == 128 ] && [ ${VALS[14]} == "KiB" ]
601 then
602 # enforce multiple match to make sure stats aren't changing any more
603 MATCH_CNT=$((MATCH_CNT+1))
604 [[ $MATCH_CNT == 3 ]] && break
605 sleep 1
606 continue
607 fi
608 MATCH_CNT=0
609 sleep 1
610 continue
611 done
612 [[ -z $IN ]] && die "Failed to retrieve any pool stats within 60 seconds"
613 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "1" ] || [ ${VALS[13]} != 128 ] || [ ${VALS[14]} != "KiB" ]
614 then
615 die "Failed to retrieve proper pool stats within 60 seconds"
616 fi
617
618 # overwrite data at 1MB offset
619 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=1048576
620 MATCH_CNT=0
621 if [ "" == "$bluestore" ];
622 then
623 STORED=1.1
624 STORED_UNIT="MiB"
625 else
626 STORED=384
627 STORED_UNIT="KiB"
628 fi
629 for i in {1..60}
630 do
631 IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
632 IFS=' ' read -ra VALS <<< "$IN"
633
634 # verification is a bit tricky due to stats report's eventual model
635 # VALS[1] - STORED
636 # VALS[2] - STORED units
637 # VALS[3] - OBJECTS
638 # VALS[5] - COPIES
639 # VALS[12] - WR_OPS
640 # VALS[13] - WR
641 # VALS[14] - WR uints
642 # implies replication factor 3
643 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "2" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
644 then
645 # enforce multiple match to make sure stats aren't changing any more
646 MATCH_CNT=$((MATCH_CNT+1))
647 [[ $MATCH_CNT == 3 ]] && break
648 sleep 1
649 continue
650 fi
651 MATCH_CNT=0
652 sleep 1
653 continue
654 done
655 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "2" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
656 then
657 die "Failed to retrieve proper pool stats within 60 seconds"
658 fi
659
660 # write data at 64K offset
661 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=65536
662 MATCH_CNT=0
663 if [ "" == "$bluestore" ];
664 then
665 STORED=1.1
666 STORED_UNIT="MiB"
667 else
668 STORED=768
669 STORED_UNIT="KiB"
670 fi
671 for i in {1..60}
672 do
673 IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
674 IFS=' ' read -ra VALS <<< "$IN"
675
676 # verification is a bit tricky due to stats report's eventual model
677 # VALS[1] - STORED
678 # VALS[2] - STORED units
679 # VALS[3] - OBJECTS
680 # VALS[5] - COPIES
681 # VALS[12] - WR_OPS
682 # VALS[13] - WR
683 # VALS[14] - WR uints
684 # implies replication factor 3
685 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "3" ] && [ ${VALS[13]} == 384 ] && [ ${VALS[14]} == "KiB" ]
686 then
687 # enforce multiple match to make sure stats aren't changing any more
688 MATCH_CNT=$((MATCH_CNT+1))
689 [[ $MATCH_CNT == 3 ]] && break
690 sleep 1
691 continue
692 fi
693 MATCH_CNT=0
694 sleep 1
695 continue
696 done
697 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "3" ] || [ ${VALS[13]} != 384 ] || [ ${VALS[14]} != "KiB" ]
698 then
699 die "Failed to retrieve proper pool stats within 60 seconds"
700 fi
701
702 # overwrite object totally
703 $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k
704 MATCH_CNT=0
705 if [ "" == "$bluestore" ];
706 then
707 STORED=128
708 STORED_UNIT="KiB"
709 else
710 STORED=384
711 STORED_UNIT="KiB"
712 fi
713 for i in {1..60}
714 do
715 IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
716 IFS=' ' read -ra VALS <<< "$IN"
717
718 # verification is a bit tricky due to stats report's eventual model
719 # VALS[1] - STORED
720 # VALS[2] - STORED units
721 # VALS[3] - OBJECTS
722 # VALS[5] - COPIES
723 # VALS[12] - WR_OPS
724 # VALS[13] - WR
725 # VALS[14] - WR uints
726 # implies replication factor 3
727 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "4" ] && [ ${VALS[13]} == 512 ] && [ ${VALS[14]} == "KiB" ]
728 then
729 # enforce multiple match to make sure stats aren't changing any more
730 MATCH_CNT=$((MATCH_CNT+1))
731 [[ $MATCH_CNT == 3 ]] && break
732 sleep 1
733 continue
734 fi
735 MATCH_CNT=0
736 sleep 1
737 continue
738 done
739 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "4" ] || [ ${VALS[13]} != 512 ] || [ ${VALS[14]} != "KiB" ]
740 then
741 die "Failed to retrieve proper pool stats within 60 seconds"
742 fi
743
744 cleanup
745
746 # after cleanup?
747 MATCH_CNT=0
748 for i in {1..60}
749 do
750 IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
751 IFS=' ' read -ra VALS <<< "$IN"
752
753 # verification is a bit tricky due to stats report's eventual model
754 # VALS[1] - STORED
755 # VALS[2] - STORED units
756 # VALS[3] - OBJECTS
757 # VALS[5] - COPIES
758 # VALS[12] - WR_OPS
759 # VALS[13] - WR
760 # VALS[14] - WR uints
761 # implies replication factor 3
762 if [ ${VALS[1]} == 0 ] && [ ${VALS[2]} == "B" ] && [ ${VALS[3]} == "0" ] && [ ${VALS[5]} == "0" ] && [ ${VALS[12]} == "5" ] && [ ${VALS[13]} == 512 ] && [ ${VALS[14]} == "KiB" ]
763 then
764 # enforce multiple match to make sure stats aren't changing any more
765 MATCH_CNT=$((MATCH_CNT+1))
766 [[ $MATCH_CNT == 3 ]] && break
767 sleep 1
768 continue
769 fi
770 MATCH_CNT=0
771 sleep 1
772 continue
773 done
774 if [ ${VALS[1]} != 0 ] || [ ${VALS[2]} != "B" ] || [ ${VALS[3]} != "0" ] || [ ${VALS[5]} != "0" ] || [ ${VALS[12]} != "5" ] || [ ${VALS[13]} != 512 ] || [ ${VALS[14]} != "KiB" ]
775 then
776 die "Failed to retrieve proper pool stats within 60 seconds"
777 fi
778
779 ############ rados df test (EC pool): ##############
780 $RADOS_TOOL purge $POOL_EC --yes-i-really-really-mean-it
781 $CEPH_TOOL osd pool rm $POOL_EC $POOL_EC --yes-i-really-really-mean-it
782 $CEPH_TOOL osd erasure-code-profile set myprofile k=2 m=1 stripe_unit=2K crush-failure-domain=osd --force
783 $CEPH_TOOL osd pool create $POOL_EC 8 8 erasure
784
785 # put object
786 $RADOS_TOOL -p $POOL_EC put $OBJ ./rados_object_128k
787 MATCH_CNT=0
788 if [ "" == "$bluestore" ];
789 then
790 STORED=128
791 STORED_UNIT="KiB"
792 else
793 STORED=192
794 STORED_UNIT="KiB"
795 fi
796 for i in {1..60}
797 do
798 IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
799 [[ -z $IN ]] && sleep 1 && continue
800 IFS=' ' read -ra VALS <<< "$IN"
801
802 # verification is a bit tricky due to stats report's eventual model
803 # VALS[1] - STORED
804 # VALS[2] - STORED units
805 # VALS[3] - OBJECTS
806 # VALS[5] - COPIES
807 # VALS[12] - WR_OPS
808 # VALS[13] - WR
809 # VALS[14] - WR uints
810 # implies replication factor 2+1
811 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "1" ] && [ ${VALS[13]} == 128 ] && [ ${VALS[14]} == "KiB" ]
812 then
813 # enforce multiple match to make sure stats aren't changing any more
814 MATCH_CNT=$((MATCH_CNT+1))
815 [[ $MATCH_CNT == 3 ]] && break
816 sleep 1
817 continue
818 fi
819 MATCH_CNT=0
820 sleep 1
821 continue
822 done
823 [[ -z $IN ]] && die "Failed to retrieve any pool stats within 60 seconds"
824 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "1" ] || [ ${VALS[13]} != 128 ] || [ ${VALS[14]} != "KiB" ]
825 then
826 die "Failed to retrieve proper pool stats within 60 seconds"
827 fi
828
829 # overwrite object
830 $RADOS_TOOL -p $POOL_EC put $OBJ ./rados_object_128k
831 MATCH_CNT=0
832 if [ "" == "$bluestore" ];
833 then
834 STORED=128
835 STORED_UNIT="KiB"
836 else
837 STORED=192
838 STORED_UNIT="KiB"
839 fi
840 for i in {1..60}
841 do
842 IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
843 IFS=' ' read -ra VALS <<< "$IN"
844
845 # verification is a bit tricky due to stats report's eventual model
846 # VALS[1] - STORED
847 # VALS[2] - STORED units
848 # VALS[3] - OBJECTS
849 # VALS[5] - COPIES
850 # VALS[12] - WR_OPS
851 # VALS[13] - WR
852 # VALS[14] - WR uints
853 # implies replication factor 2+1
854 if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "2" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
855 then
856 # enforce multiple match to make sure stats aren't changing any more
857 MATCH_CNT=$((MATCH_CNT+1))
858 [[ $MATCH_CNT == 3 ]] && break
859 sleep 1
860 continue
861 fi
862 MATCH_CNT=0
863 sleep 1
864 continue
865 done
866 if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "2" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
867 then
868 die "Failed to retrieve proper pool stats within 60 seconds"
869 fi
870
871 cleanup
872
873 # after cleanup?
874 MATCH_CNT=0
875 for i in {1..60}
876 do
877 IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
878 IFS=' ' read -ra VALS <<< "$IN"
879
880 # verification is a bit tricky due to stats report's eventual model
881 # VALS[1] - STORED
882 # VALS[2] - STORED units
883 # VALS[3] - OBJECTS
884 # VALS[5] - COPIES
885 # VALS[12] - WR_OPS
886 # VALS[13] - WR
887 # VALS[14] - WR uints
888 # implies replication factor 2+1
889 if [ ${VALS[1]} == 0 ] && [ ${VALS[2]} == "B" ] && [ ${VALS[3]} == "0" ] && [ ${VALS[5]} == "0" ] && [ ${VALS[12]} == "3" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
890 then
891 # enforce multiple match to make sure stats aren't changing any more
892 MATCH_CNT=$((MATCH_CNT+1))
893 [[ $MATCH_CNT == 3 ]] && break
894 sleep 1
895 continue
896 fi
897 MATCH_CNT=0
898 sleep 1
899 continue
900 done
901 if [ ${VALS[1]} != 0 ] || [ ${VALS[2]} != "B" ] || [ ${VALS[3]} != "0" ] || [ ${VALS[5]} != "0" ] || [ ${VALS[12]} != "3" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
902 then
903 die "Failed to retrieve proper pool stats within 60 seconds"
904 fi
905
906 rm -rf ./rados_object_128k
907 }
908
909 test_xattr
910 test_omap
911 test_rmobj
912 test_ls
913 test_cleanup
914 test_append
915 test_put
916 test_stat
917
918 # clean up environment, delete pool
919 $CEPH_TOOL osd pool delete $POOL $POOL --yes-i-really-really-mean-it
920 $CEPH_TOOL osd pool delete $POOL_EC $POOL_EC --yes-i-really-really-mean-it
921 $CEPH_TOOL osd pool delete $POOL_CP_TARGET $POOL_CP_TARGET --yes-i-really-really-mean-it
922
923 echo "SUCCESS!"
924 exit 0