Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / standalone / mon / osd-pool-df.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2017 Tencent <contact@tencent.com>
4 #
5 # Author: Chang Liu <liuchang0812@gmail.com>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Library Public License for more details.
16 #
17 source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
18
19 function run() {
20     local dir=$1
21     shift
22
23     export CEPH_MON="127.0.0.1:7113" # git grep '\<7113\>' : there must be only one
24     export CEPH_ARGS
25     CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
26     CEPH_ARGS+="--mon-host=$CEPH_MON "
27
28     local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
29     for func in $funcs ; do
30         setup $dir || return 1
31         $func $dir || return 1
32         teardown $dir || return 1
33     done
34 }
35
36 function TEST_ceph_df() {
37     local dir=$1
38     setup $dir || return 1
39
40     run_mon $dir a || return 1
41     run_osd $dir 0 || return 1
42     run_osd $dir 1 || return 1
43     run_osd $dir 2 || return 1
44     run_osd $dir 3 || return 1
45     run_osd $dir 4 || return 1
46     run_osd $dir 5 || return 1
47     run_mgr $dir x || return 1
48
49     profile+=" plugin=jerasure"
50     profile+=" technique=reed_sol_van"
51     profile+=" k=4"
52     profile+=" m=2"
53     profile+=" crush-failure-domain=osd"
54
55     ceph osd erasure-code-profile set ec42profile ${profile}
56  
57     local rep_poolname=testcephdf_replicate
58     local ec_poolname=testcephdf_erasurecode
59     create_pool $rep_poolname 6 6 replicated
60     create_pool $ec_poolname 6 6 erasure ec42profile
61
62     local global_avail=`ceph df -f json | jq '.stats.total_avail_bytes'`
63     local rep_avail=`ceph df -f json | jq '.pools | map(select(.name == "$rep_poolname"))[0].stats.max_avail'`
64     local ec_avail=`ceph df -f json | jq '.pools | map(select(.name == "$ec_poolname"))[0].stats.max_avail'`
65
66     echo "${global_avail} >= ${rep_avail}*3" | bc || return 1
67     echo "${global_avail} >= ${ec_avail}*1.5" | bc || return 1
68
69     ceph osd pool delete  $rep_poolname $rep_poolname  --yes-i-really-really-mean-it
70     ceph osd pool delete  $ec_poolname $ec_poolname  --yes-i-really-really-mean-it
71     ceph osd erasure-code-profile rm ec42profile
72     teardown $dir || return 1
73 }
74
75 main osd-pool-df "$@"