Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / hadoop / repl.sh
1 #!/bin/bash
2
3 set -e
4 set -x
5
6 # bail if $TESTDIR is not set as this test will fail in that scenario
7 [ -z $TESTDIR ] && { echo "\$TESTDIR needs to be set, but is not. Exiting."; exit 1; }
8
9 # if HADOOP_PREFIX is not set, use default
10 [ -z $HADOOP_PREFIX ] && { HADOOP_PREFIX=$TESTDIR/hadoop; }
11
12 # create pools with different replication factors
13 for repl in 2 3 7 8 9; do
14   name=hadoop.$repl
15   ceph osd pool create $name 8 8
16   ceph osd pool set $name size $repl
17
18   id=`ceph osd dump | sed -n "s/^pool \([0-9]*\) '$name'.*/\1/p"`
19   ceph mds add_data_pool $id
20 done
21
22 # create a file in each of the pools
23 for repl in 2 3 7 8 9; do
24   name=hadoop.$repl
25   $HADOOP_PREFIX/bin/hadoop fs -rm -f /$name.dat
26   dd if=/dev/zero bs=1048576 count=1 | \
27     $HADOOP_PREFIX/bin/hadoop fs -Dceph.data.pools="$name" \
28     -put - /$name.dat
29 done
30
31 # check that hadoop reports replication matching
32 # that of the pool the file was written into
33 for repl in 2 3 7 8 9; do
34   name=hadoop.$repl
35   repl2=$($HADOOP_PREFIX/bin/hadoop fs -ls /$name.dat | awk '{print $2}')
36   if [ $repl -ne $repl2 ]; then
37     echo "replication factors didn't match!"
38     exit 1
39   fi
40 done
41
42 exit 0