summaryrefslogtreecommitdiffstats
path: root/qa/workunits/rados/test_rados_tool.sh
blob: 9d025eee8aee8348979025d23004cc601c4dbbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
#!/usr/bin/env bash

set -x

die() {
    echo "$@"
    exit 1
}

usage() {
    cat <<EOF
test_rados_tool.sh: tests rados_tool
-c:        RADOS configuration file to use [optional]
-k:        keep temp files
-h:        this help message
-p:        set temporary pool to use [optional]
EOF
}

do_run() {
    if [ "$1" == "--tee" ]; then
      shift
      tee_out="$1"
      shift
      "$@" | tee $tee_out
    else
      "$@"
    fi
}

run_expect_fail() {
    echo "RUN_EXPECT_FAIL: " "$@"
    do_run "$@"
    [ $? -eq 0 ] && die "expected failure, but got success! cmd: $@"
}

run_expect_succ() {
    echo "RUN_EXPECT_SUCC: " "$@"
    do_run "$@"
    [ $? -ne 0 ] && die "expected success, but got failure! cmd: $@"
}

run_expect_nosignal() {
    echo "RUN_EXPECT_NOSIGNAL: " "$@"
    do_run "$@"
    [ $? -ge 128 ] && die "expected success or fail, but got signal! cmd: $@"
}

run() {
    echo "RUN: " $@
    do_run "$@"
}

if [ -n "$CEPH_BIN" ] ; then
   # CMake env
   RADOS_TOOL="$CEPH_BIN/rados"
   CEPH_TOOL="$CEPH_BIN/ceph"
else
   # executables should be installed by the QA env 
   RADOS_TOOL=$(which rados)
   CEPH_TOOL=$(which ceph)
fi

KEEP_TEMP_FILES=0
POOL=trs_pool
POOL_CP_TARGET=trs_pool.2
POOL_EC=trs_pool_ec

[ -x "$RADOS_TOOL" ] || die "couldn't find $RADOS_TOOL binary to test"
[ -x "$CEPH_TOOL" ] || die "couldn't find $CEPH_TOOL binary to test"

while getopts  "c:hkp:" flag; do
    case $flag in
        c)  RADOS_TOOL="$RADOS_TOOL -c $OPTARG";;
        k)  KEEP_TEMP_FILES=1;;
        h)  usage; exit 0;;
        p)  POOL=$OPTARG;;
        *)  echo; usage; exit 1;;
    esac
done

TDIR=`mktemp -d -t test_rados_tool.XXXXXXXXXX` || die "mktemp failed"
[ $KEEP_TEMP_FILES -eq 0 ] && trap "rm -rf ${TDIR}; exit" INT TERM EXIT

# ensure rados doesn't segfault without --pool
run_expect_nosignal "$RADOS_TOOL" --snap "asdf" ls
run_expect_nosignal "$RADOS_TOOL" --snapid "0" ls
run_expect_nosignal "$RADOS_TOOL" --object-locator "asdf" ls
run_expect_nosignal "$RADOS_TOOL" --namespace "asdf" ls

run_expect_succ "$CEPH_TOOL" osd pool create "$POOL" 8
run_expect_succ "$CEPH_TOOL" osd erasure-code-profile set myprofile k=2 m=1 stripe_unit=2K crush-failure-domain=osd --force
run_expect_succ "$CEPH_TOOL" osd pool create "$POOL_EC" 100 100 erasure myprofile


# expb happens to be the empty export for legacy reasons
run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expb"

# expa has objects foo, foo2 and bar
run_expect_succ "$RADOS_TOOL" -p "$POOL" put foo /etc/fstab
run_expect_succ "$RADOS_TOOL" -p "$POOL" put foo2 /etc/fstab
run_expect_succ "$RADOS_TOOL" -p "$POOL" put bar /etc/fstab
run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expa"

# expc has foo and foo2 with some attributes and omaps set
run_expect_succ "$RADOS_TOOL" -p "$POOL" rm bar
run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothbrush" "toothbrush"
run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothpaste" "crest"
run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapval foo "rados.floss" "myfloss"
run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo2 "rados.toothbrush" "green"
run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapheader foo2 "foo2.header"
run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/expc"

# make sure that --create works
run "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
run_expect_succ "$RADOS_TOOL" -p "$POOL" --create import "$TDIR/expa"

# make sure that lack of --create fails
run_expect_succ "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
run_expect_fail "$RADOS_TOOL" -p "$POOL" import "$TDIR/expa"

run_expect_succ "$RADOS_TOOL" -p "$POOL" --create import "$TDIR/expa"

# inaccessible import src should fail
run_expect_fail "$RADOS_TOOL" -p "$POOL" import "$TDIR/dir_nonexistent"

# export an empty pool to test purge
run_expect_succ "$RADOS_TOOL" purge "$POOL" --yes-i-really-really-mean-it
run_expect_succ "$RADOS_TOOL" -p "$POOL" export "$TDIR/empty"
cmp -s "$TDIR/expb" "$TDIR/empty" \
    || die "failed to export the same stuff we imported!"
rm -f "$TDIR/empty"

# import some stuff with extended attributes on it
run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
[ ${VAL} = "toothbrush" ] || die "Invalid attribute after import"

# the second time, the xattrs should match, so there should be nothing to do.
run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
[ "${VAL}" = "toothbrush" ] || die "Invalid attribute after second import"

# Now try with --no-overwrite option after changing an attribute
run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr foo "rados.toothbrush" "dentist"
run_expect_succ "$RADOS_TOOL" -p "$POOL" import --no-overwrite "$TDIR/expc"
VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
[ "${VAL}" = "dentist" ] || die "Invalid attribute after second import"

# now force it to copy everything
run_expect_succ "$RADOS_TOOL" -p "$POOL" import "$TDIR/expc"
VAL=`"$RADOS_TOOL" -p "$POOL" getxattr foo "rados.toothbrush"`
[ "${VAL}" = "toothbrush" ] || die "Invalid attribute after second import"

# test copy pool
run "$CEPH_TOOL" osd pool rm "$POOL" "$POOL" --yes-i-really-really-mean-it
run "$CEPH_TOOL" osd pool rm "$POOL_CP_TARGET" "$POOL_CP_TARGET" --yes-i-really-really-mean-it
run_expect_succ "$CEPH_TOOL" osd pool create "$POOL" 8
run_expect_succ "$CEPH_TOOL" osd pool create "$POOL_CP_TARGET" 8

# create src files
mkdir -p "$TDIR/dir_cp_src"
for i in `seq 1 5`; do
  fname="$TDIR/dir_cp_src/f.$i"
  objname="f.$i"
  dd if=/dev/urandom of="$fname" bs=$((1024*1024)) count=$i
  run_expect_succ "$RADOS_TOOL" -p "$POOL" put $objname "$fname"

# a few random attrs
  for j in `seq 1 4`; do
    rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
    run_expect_succ "$RADOS_TOOL" -p "$POOL" setxattr $objname attr.$j "$rand_str"
    run_expect_succ --tee "$fname.attr.$j" "$RADOS_TOOL" -p "$POOL" getxattr $objname attr.$j
  done

  rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
  run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapheader $objname "$rand_str"
  run_expect_succ --tee "$fname.omap.header" "$RADOS_TOOL" -p "$POOL" getomapheader $objname

# a few random omap keys
  for j in `seq 1 4`; do
    rand_str=`dd if=/dev/urandom bs=4 count=1 | hexdump -x`
    run_expect_succ "$RADOS_TOOL" -p "$POOL" setomapval $objname key.$j "$rand_str"
  done
  run_expect_succ --tee "$fname.omap.vals" "$RADOS_TOOL" -p "$POOL" listomapvals $objname
done

run_expect_succ "$RADOS_TOOL" cppool "$POOL" "$POOL_CP_TARGET"

mkdir -p "$TDIR/dir_cp_dst"
for i in `seq 1 5`; do
  fname="$TDIR/dir_cp_dst/f.$i"
  objname="f.$i"
  run_expect_succ "$RADOS_TOOL" -p "$POOL_CP_TARGET" get $objname "$fname"

# a few random attrs
  for j in `seq 1 4`; do
    run_expect_succ --tee "$fname.attr.$j" "$RADOS_TOOL" -p "$POOL_CP_TARGET" getxattr $objname attr.$j
  done

  run_expect_succ --tee "$fname.omap.header" "$RADOS_TOOL" -p "$POOL_CP_TARGET" getomapheader $objname
  run_expect_succ --tee "$fname.omap.vals" "$RADOS_TOOL" -p "$POOL_CP_TARGET" listomapvals $objname
done

diff -q -r "$TDIR/dir_cp_src" "$TDIR/dir_cp_dst" \
    || die "copy pool validation failed!"

for opt in \
    block-size \
    concurrent-ios \
    min-object-size \
    max-object-size \
    min-op-len \
    max-op-len \
    max-ops \
    max-backlog \
    target-throughput \
    read-percent \
    num-objects \
    run-length \
    ; do
    run_expect_succ "$RADOS_TOOL" --$opt 4 df
    run_expect_fail "$RADOS_TOOL" --$opt 4k df
done

run_expect_succ "$RADOS_TOOL" lock list f.1 --lock-duration 4 --pool "$POOL"
echo # previous command doesn't output an end of line: issue #9735
run_expect_fail "$RADOS_TOOL" lock list f.1 --lock-duration 4k --pool "$POOL"

run_expect_succ "$RADOS_TOOL" mksnap snap1 --pool "$POOL"
snapid=$("$RADOS_TOOL" lssnap --pool "$POOL" | grep snap1 | cut -f1)
[ $? -ne 0 ] && die "expected success, but got failure! cmd: \"$RADOS_TOOL\" lssnap --pool \"$POOL\" | grep snap1 | cut -f1"
run_expect_succ "$RADOS_TOOL" ls --pool "$POOL" --snapid="$snapid"
run_expect_fail "$RADOS_TOOL" ls --pool "$POOL" --snapid="$snapid"k

run_expect_succ "$RADOS_TOOL" truncate f.1 0 --pool "$POOL"
run_expect_fail "$RADOS_TOOL" truncate f.1 0k --pool "$POOL"

run "$CEPH_TOOL" osd pool rm delete_me_mkpool_test delete_me_mkpool_test --yes-i-really-really-mean-it
run_expect_succ "$CEPH_TOOL" osd pool create delete_me_mkpool_test 1

run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 write
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 1k write
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 write --format json --output "$TDIR/bench.json"
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 1 write --output "$TDIR/bench.json"
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --format json --no-cleanup
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 rand --format json
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 rand -f json
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 seq --format json
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 1 seq -f json
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-omap
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-object
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-object
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-omap
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-omap --write-object
run_expect_succ "$RADOS_TOOL" --pool "$POOL" bench 5 write --write-xattr --write-omap --write-object
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-omap
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-object
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-object
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-omap
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-omap --write-object
run_expect_fail "$RADOS_TOOL" --pool "$POOL" bench 5 read --write-xattr --write-omap --write-object

for i in $("$RADOS_TOOL" --pool "$POOL" ls | grep "benchmark_data"); do
    "$RADOS_TOOL" --pool "$POOL" truncate $i 0
done

run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 rand
run_expect_nosignal "$RADOS_TOOL" --pool "$POOL" bench 1 seq

set -e

OBJ=test_rados_obj

expect_false()
{
	if "$@"; then return 1; else return 0; fi
}

cleanup() {
    $RADOS_TOOL -p $POOL rm $OBJ > /dev/null 2>&1 || true
    $RADOS_TOOL -p $POOL_EC rm $OBJ > /dev/null 2>&1 || true
}

test_omap() {
    cleanup
    for i in $(seq 1 1 10)
    do
	if [ $(($i % 2)) -eq 0 ]; then
            $RADOS_TOOL -p $POOL setomapval $OBJ $i $i
	else
            echo -n "$i" | $RADOS_TOOL -p $POOL setomapval $OBJ $i
	fi
        $RADOS_TOOL -p $POOL getomapval $OBJ $i | grep -q "|$i|\$"
    done
    $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 10
    for i in $(seq 1 1 5)
    do
        $RADOS_TOOL -p $POOL rmomapkey $OBJ $i
    done
    $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 5
    $RADOS_TOOL -p $POOL clearomap $OBJ
    $RADOS_TOOL -p $POOL listomapvals $OBJ | wc -l | grep 0
    cleanup

    for i in $(seq 1 1 10)
    do
        dd if=/dev/urandom bs=128 count=1 > $TDIR/omap_key
        if [ $(($i % 2)) -eq 0 ]; then
            $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key setomapval $OBJ $i
        else
            echo -n "$i" | $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key setomapval $OBJ
        fi
        $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key getomapval $OBJ | grep -q "|$i|\$"
        $RADOS_TOOL -p $POOL --omap-key-file $TDIR/omap_key rmomapkey $OBJ
        $RADOS_TOOL -p $POOL listomapvals $OBJ | grep -c value | grep 0
    done
    cleanup
}

test_xattr() {
    cleanup
    $RADOS_TOOL -p $POOL put $OBJ /etc/passwd
    V1=`mktemp fooattrXXXXXXX`
    V2=`mktemp fooattrXXXXXXX`
    echo -n fooval > $V1
    expect_false $RADOS_TOOL -p $POOL setxattr $OBJ 2>/dev/null
    expect_false $RADOS_TOOL -p $POOL setxattr $OBJ foo fooval extraarg 2>/dev/null
    $RADOS_TOOL -p $POOL setxattr $OBJ foo fooval
    $RADOS_TOOL -p $POOL getxattr $OBJ foo > $V2
    cmp $V1 $V2
    cat $V1 | $RADOS_TOOL -p $POOL setxattr $OBJ bar
    $RADOS_TOOL -p $POOL getxattr $OBJ bar > $V2
    cmp $V1 $V2
    $RADOS_TOOL -p $POOL listxattr $OBJ > $V1
    grep -q foo $V1
    grep -q bar $V1
    [ `cat $V1 | wc -l` -eq 2 ]
    rm $V1 $V2
    cleanup
}
test_rmobj() {
    p=`uuidgen`
    $CEPH_TOOL osd pool create $p 1
    $CEPH_TOOL osd pool set-quota $p max_objects 1
    V1=`mktemp fooattrXXXXXXX`
    $RADOS_TOOL put $OBJ $V1 -p $p
    while ! $CEPH_TOOL osd dump | grep 'full_quota max_objects'
    do
	sleep 2
    done
    $RADOS_TOOL -p $p rm $OBJ --force-full
    $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
    rm $V1
}

test_ls() {
    echo "Testing rados ls command"
    p=`uuidgen`
    $CEPH_TOOL osd pool create $p 1
    NS=10
    OBJS=20
    # Include default namespace (0) in the total
    TOTAL=$(expr $OBJS \* $(expr $NS + 1))

    for nsnum in `seq 0 $NS`
    do
        for onum in `seq 1 $OBJS`
        do
	    if [ "$nsnum" = "0" ];
	    then
                "$RADOS_TOOL" -p $p put obj${onum} /etc/fstab 2> /dev/null
            else
                "$RADOS_TOOL" -p $p -N "NS${nsnum}" put obj${onum} /etc/fstab 2> /dev/null
	    fi
	done
    done
    CHECK=$("$RADOS_TOOL" -p $p ls 2> /dev/null | wc -l)
    if [ "$OBJS" -ne "$CHECK" ];
    then
        die "Created $OBJS objects in default namespace but saw $CHECK"
    fi
    TESTNS=NS${NS}
    CHECK=$("$RADOS_TOOL" -p $p -N $TESTNS ls 2> /dev/null | wc -l)
    if [ "$OBJS" -ne "$CHECK" ];
    then
        die "Created $OBJS objects in $TESTNS namespace but saw $CHECK"
    fi
    CHECK=$("$RADOS_TOOL" -p $p --all ls 2> /dev/null | wc -l)
    if [ "$TOTAL" -ne "$CHECK" ];
    then
        die "Created $TOTAL objects but saw $CHECK"
    fi

    $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
}

test_cleanup() {
    echo "Testing rados cleanup command"
    p=`uuidgen`
    $CEPH_TOOL osd pool create $p 1
    NS=5
    OBJS=4
    # Include default namespace (0) in the total
    TOTAL=$(expr $OBJS \* $(expr $NS + 1))

    for nsnum in `seq 0 $NS`
    do
        for onum in `seq 1 $OBJS`
        do
	    if [ "$nsnum" = "0" ];
	    then
                "$RADOS_TOOL" -p $p put obj${onum} /etc/fstab 2> /dev/null
            else
                "$RADOS_TOOL" -p $p -N "NS${nsnum}" put obj${onum} /etc/fstab 2> /dev/null
	    fi
	done
    done

    $RADOS_TOOL -p $p --all ls > $TDIR/before.ls.out 2> /dev/null

    $RADOS_TOOL -p $p bench 3 write --no-cleanup 2> /dev/null
    $RADOS_TOOL -p $p -N NS1 bench 3 write --no-cleanup 2> /dev/null
    $RADOS_TOOL -p $p -N NS2 bench 3 write --no-cleanup 2> /dev/null
    $RADOS_TOOL -p $p -N NS3 bench 3 write --no-cleanup 2> /dev/null
    # Leave dangling objects without a benchmark_last_metadata in NS4
    expect_false timeout 3 $RADOS_TOOL -p $p -N NS4 bench 30 write --no-cleanup 2> /dev/null
    $RADOS_TOOL -p $p -N NS5 bench 3 write --no-cleanup 2> /dev/null

    $RADOS_TOOL -p $p -N NS3 cleanup 2> /dev/null
    #echo "Check NS3 after specific cleanup"
    CHECK=$($RADOS_TOOL -p $p -N NS3 ls | wc -l)
    if [ "$OBJS" -ne "$CHECK" ] ;
    then
        die "Expected $OBJS objects in NS3 but saw $CHECK"
    fi

    #echo "Try to cleanup all"
    $RADOS_TOOL -p $p --all cleanup
    #echo "Check all namespaces"
    $RADOS_TOOL -p $p --all ls > $TDIR/after.ls.out 2> /dev/null
    CHECK=$(cat $TDIR/after.ls.out | wc -l)
    if [ "$TOTAL" -ne "$CHECK" ];
    then
        die "Expected $TOTAL objects but saw $CHECK"
    fi
    if ! diff $TDIR/before.ls.out $TDIR/after.ls.out
    then
        die "Different objects found after cleanup"
    fi

    set +e
    run_expect_fail $RADOS_TOOL -p $p cleanup --prefix illegal_prefix
    run_expect_succ $RADOS_TOOL -p $p cleanup --prefix benchmark_data_otherhost
    set -e

    $CEPH_TOOL osd pool rm $p $p --yes-i-really-really-mean-it
}

function test_append()
{
  cleanup

  # create object
  touch ./rados_append_null
  $RADOS_TOOL -p $POOL append $OBJ ./rados_append_null
  $RADOS_TOOL -p $POOL get $OBJ ./rados_append_0_out
  cmp ./rados_append_null ./rados_append_0_out

  # append 4k, total size 4k
  dd if=/dev/zero of=./rados_append_4k bs=4k count=1
  $RADOS_TOOL -p $POOL append $OBJ ./rados_append_4k
  $RADOS_TOOL -p $POOL get $OBJ ./rados_append_4k_out
  cmp ./rados_append_4k ./rados_append_4k_out

  # append 4k, total size 8k
  $RADOS_TOOL -p $POOL append $OBJ ./rados_append_4k
  $RADOS_TOOL -p $POOL get $OBJ ./rados_append_4k_out
  read_size=`ls -l ./rados_append_4k_out | awk -F ' '  '{print $5}'`
  if [ 8192 -ne $read_size ];
  then
    die "Append failed expecting 8192 read $read_size"
  fi

  # append 10M, total size 10493952
  dd if=/dev/zero of=./rados_append_10m bs=10M count=1
  $RADOS_TOOL -p $POOL append $OBJ ./rados_append_10m
  $RADOS_TOOL -p $POOL get $OBJ ./rados_append_10m_out
  read_size=`ls -l ./rados_append_10m_out | awk -F ' '  '{print $5}'`
  if [ 10493952 -ne $read_size ];
  then
    die "Append failed expecting 10493952 read $read_size"
  fi

  # cleanup
  cleanup

  # create object
  $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_null
  $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_0_out
  cmp rados_append_null rados_append_0_out

  # append 4k, total size 4k
  $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_4k
  $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_4k_out
  cmp rados_append_4k rados_append_4k_out

  # append 4k, total size 8k
  $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_4k
  $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_4k_out
  read_size=`ls -l ./rados_append_4k_out | awk -F ' '  '{print $5}'`
  if [ 8192 -ne $read_size ];
  then
    die "Append failed expecting 8192 read $read_size"
  fi

  # append 10M, total size 10493952
  $RADOS_TOOL -p $POOL_EC append $OBJ ./rados_append_10m
  $RADOS_TOOL -p $POOL_EC get $OBJ ./rados_append_10m_out
  read_size=`ls -l ./rados_append_10m_out | awk -F ' '  '{print $5}'`
  if [ 10493952 -ne $read_size ];
  then
    die "Append failed expecting 10493952 read $read_size"
  fi

  cleanup
  rm -rf ./rados_append_null ./rados_append_0_out
  rm -rf ./rados_append_4k ./rados_append_4k_out ./rados_append_10m ./rados_append_10m_out
}

function test_put()
{
  # rados put test:
  cleanup

  # create file in local fs
  dd if=/dev/urandom of=rados_object_10k bs=1K count=10

  # test put command
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k
  $RADOS_TOOL -p $POOL get $OBJ ./rados_object_10k_out
  cmp ./rados_object_10k ./rados_object_10k_out
  cleanup

  # test put command with offset 0
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k --offset 0
  $RADOS_TOOL -p $POOL get $OBJ ./rados_object_offset_0_out
  cmp ./rados_object_10k ./rados_object_offset_0_out
  cleanup

  # test put command with offset 1000
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_10k --offset 1000
  $RADOS_TOOL -p $POOL get $OBJ ./rados_object_offset_1000_out
  cmp ./rados_object_10k ./rados_object_offset_1000_out 0 1000
  cleanup

  rm -rf ./rados_object_10k ./rados_object_10k_out ./rados_object_offset_0_out ./rados_object_offset_1000_out
}

function test_stat()
{
  bluestore=$("$CEPH_TOOL" osd metadata | grep '"osd_objectstore": "bluestore"' | cut -f1)
  # create file in local fs
  dd if=/dev/urandom of=rados_object_128k bs=64K count=2

  # rados df test (replicated_pool):
  $RADOS_TOOL purge $POOL --yes-i-really-really-mean-it
  $CEPH_TOOL osd pool rm $POOL $POOL --yes-i-really-really-mean-it
  $CEPH_TOOL osd pool create $POOL 8
  $CEPH_TOOL osd pool set $POOL size 3

  # put object with 1 MB gap in front
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=1048576
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=1.1
    STORED_UNIT="MiB"
  else
    STORED=384
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
    [[ -z $IN ]] && sleep 1 && continue
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 3
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "1" ] && [ ${VALS[13]} == 128 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  [[ -z $IN ]] && die "Failed to retrieve any pool stats within 60 seconds"
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "1" ] || [ ${VALS[13]} != 128 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  # overwrite data at 1MB offset
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=1048576
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=1.1
    STORED_UNIT="MiB"
  else
    STORED=384
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 3
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "2" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "2" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  # write data at 64K offset
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k --offset=65536
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=1.1
    STORED_UNIT="MiB"
  else
    STORED=768
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 3
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "3" ] && [ ${VALS[13]} == 384 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "3" ] || [ ${VALS[13]} != 384 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  # overwrite object totally
  $RADOS_TOOL -p $POOL put $OBJ ./rados_object_128k
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=128
    STORED_UNIT="KiB"
  else
    STORED=384
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 3
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "4" ] && [ ${VALS[13]} == 512 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "4" ] || [ ${VALS[13]} != 512 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  cleanup

  # after cleanup?
  MATCH_CNT=0
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL df | grep $POOL ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 3
    if [ ${VALS[1]} == 0 ] && [ ${VALS[2]} == "B" ] && [ ${VALS[3]} == "0" ] && [ ${VALS[5]} == "0" ] && [ ${VALS[12]} == "5" ] && [ ${VALS[13]} == 512 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != 0 ] || [ ${VALS[2]} != "B" ] || [ ${VALS[3]} != "0" ] || [ ${VALS[5]} != "0" ] || [ ${VALS[12]} != "5" ] || [ ${VALS[13]} != 512 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  ############ rados df test (EC pool): ##############
  $RADOS_TOOL purge $POOL_EC --yes-i-really-really-mean-it
  $CEPH_TOOL osd pool rm $POOL_EC $POOL_EC --yes-i-really-really-mean-it
  $CEPH_TOOL osd erasure-code-profile set myprofile k=2 m=1 stripe_unit=2K crush-failure-domain=osd --force
  $CEPH_TOOL osd pool create $POOL_EC 8 8 erasure

  # put object
  $RADOS_TOOL -p $POOL_EC put $OBJ ./rados_object_128k
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=128
    STORED_UNIT="KiB"
  else
    STORED=192
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
    [[ -z $IN ]] && sleep 1 && continue
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 2+1
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "1" ] && [ ${VALS[13]} == 128 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  [[ -z $IN ]] && die "Failed to retrieve any pool stats within 60 seconds"
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "1" ] || [ ${VALS[13]} != 128 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  # overwrite object
  $RADOS_TOOL -p $POOL_EC put $OBJ ./rados_object_128k
  MATCH_CNT=0
  if [ "" == "$bluestore" ];
  then
    STORED=128
    STORED_UNIT="KiB"
  else
    STORED=192
    STORED_UNIT="KiB"
  fi
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 2+1
    if [ ${VALS[1]} == $STORED ] && [ ${VALS[2]} == $STORED_UNIT ] && [ ${VALS[3]} == "1" ] && [ ${VALS[5]} == "3" ] && [ ${VALS[12]} == "2" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != $STORED ] || [ ${VALS[2]} != $STORED_UNIT ] || [ ${VALS[3]} != "1" ] || [ ${VALS[5]} != "3" ] || [ ${VALS[12]} != "2" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  cleanup

  # after cleanup?
  MATCH_CNT=0
  for i in {1..60}
  do
    IN=$($RADOS_TOOL -p $POOL_EC df | grep $POOL_EC ; [[ ! -z $? ]] && echo "")
    IFS=' ' read -ra VALS <<< "$IN"

    # verification is a bit tricky due to stats report's eventual model
    # VALS[1] - STORED
    # VALS[2] - STORED units
    # VALS[3] - OBJECTS
    # VALS[5] - COPIES
    # VALS[12] - WR_OPS
    # VALS[13] - WR
    # VALS[14] - WR uints
    # implies replication factor 2+1
    if [ ${VALS[1]} == 0 ] && [ ${VALS[2]} == "B" ] && [ ${VALS[3]} == "0" ] && [ ${VALS[5]} == "0" ] && [ ${VALS[12]} == "3" ] && [ ${VALS[13]} == 256 ] && [ ${VALS[14]} == "KiB" ]
    then
      # enforce multiple match to make sure stats aren't changing any more
      MATCH_CNT=$((MATCH_CNT+1))
      [[ $MATCH_CNT == 3 ]] && break
      sleep 1
      continue
    fi
    MATCH_CNT=0
    sleep 1
    continue
  done
  if [ ${VALS[1]} != 0 ] || [ ${VALS[2]} != "B" ] || [ ${VALS[3]} != "0" ] || [ ${VALS[5]} != "0" ] || [ ${VALS[12]} != "3" ] || [ ${VALS[13]} != 256 ] || [ ${VALS[14]} != "KiB" ]
  then
    die "Failed to retrieve proper pool stats within 60 seconds"
  fi

  rm -rf ./rados_object_128k
}

test_xattr
test_omap
test_rmobj
test_ls
test_cleanup
test_append
test_put
test_stat

# clean up environment, delete pool
$CEPH_TOOL osd pool delete $POOL $POOL --yes-i-really-really-mean-it
$CEPH_TOOL osd pool delete $POOL_EC $POOL_EC --yes-i-really-really-mean-it
$CEPH_TOOL osd pool delete $POOL_CP_TARGET $POOL_CP_TARGET --yes-i-really-really-mean-it

echo "SUCCESS!"
exit 0