Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / test_crush_bucket.sh
1 #!/bin/bash
2
3
4 #Generic test_crush_bucket  test
5 #
6
7 # Includes
8 source $(dirname $0)/detect-build-env-vars.sh
9 source ../qa/standalone/ceph-helpers.sh
10 function run() {
11     local dir=$1
12     shift
13
14     export CEPH_MON="127.0.0.1:17119" # git grep '\<17119\>' : there must be only one
15     export CEPH_ARGS
16     CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
17     CEPH_ARGS+="--mon-host=$CEPH_MON "
18
19     local funcs=${@:-$(set | ${SED} -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
20     for func in $funcs ; do
21         $func $dir || return 1
22     done
23 }
24
25 function TEST_crush_bucket() {
26     local dir=$1
27     setup $dir || return 1
28     run_mon $dir a || return 1
29     run_osd $dir 0 || return 1
30     run_osd $dir 1 || return 1
31     run_osd $dir 2 || return 1
32
33
34     ceph osd getcrushmap -o "$dir/map1" || return 1
35     crushtool -d "$dir/map1" -o "$dir/map1.txt"|| return 1
36     local var=`ceph osd crush dump|grep -w id|grep '-'|grep -Eo '[0-9]+'|sort|uniq|${SED} -n '$p'`
37     local id=`expr  $var + 1`
38     local item=`${SED} -n '/^root/,/}/p' $dir/map1.txt|grep  'item'|head -1`
39     local weight=`${SED} -n '/^root/,/}/p' $dir/map1.txt|grep  'item'|head -1|awk '{print $4}'`
40     local bucket="host test {\n id -$id\n # weight $weight\n alg straw \n hash 0  # rjenkins1 \n $item\n}\n"
41     ${SED} -i "/# buckets/a\ $bucket" "$dir/map1.txt"
42     crushtool  -c "$dir/map1.txt" -o "$dir/map1.bin" 2>"$dir/rev"
43     local result=$(cat "$dir/rev")
44     if [ "$result" != "" ];
45     then
46       return 1
47     fi
48
49 }
50
51 main testcrushbucket
52