]> git.proxmox.com Git - ceph.git/blob - ceph/qa/standalone/mgr/balancer.sh
import ceph 14.2.5
[ceph.git] / ceph / qa / standalone / mgr / balancer.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2019 Red Hat <contact@redhat.com>
4 #
5 # Author: David Zafman <dzafman@redhat.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:7102" # git grep '\<7102\>' : 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 $func $dir || return 1
31 done
32 }
33
34 TEST_POOL1=test1
35 TEST_POOL2=test2
36
37 function TEST_balancer() {
38 local dir=$1
39
40 setup $dir || return 1
41 run_mon $dir a || return 1
42 run_mgr $dir x || return 1
43 run_osd $dir 0 || return 1
44 run_osd $dir 1 || return 1
45 run_osd $dir 2 || return 1
46 create_pool $TEST_POOL1 8
47 create_pool $TEST_POOL2 8
48
49 wait_for_clean || return 1
50
51 ceph pg dump pgs
52 ceph osd set-require-min-compat-client luminous
53 ceph balancer status || return 1
54 eval MODE=$(ceph balancer status | jq '.mode')
55 test $MODE = "none" || return 1
56 ACTIVE=$(ceph balancer status | jq '.active')
57 test $ACTIVE = "false" || return 1
58
59 ceph balancer ls || return 1
60 PLANS=$(ceph balancer ls)
61 test "$PLANS" = "[]" || return 1
62 ceph balancer eval || return 1
63 EVAL="$(ceph balancer eval)"
64 test "$EVAL" = "current cluster score 0.000000 (lower is better)"
65 ceph balancer eval-verbose || return 1
66
67 ceph balancer pool add $TEST_POOL1 || return 1
68 ceph balancer pool add $TEST_POOL2 || return 1
69 ceph balancer pool ls || return 1
70 eval POOL=$(ceph balancer pool ls | jq '.[0]')
71 test "$POOL" = "$TEST_POOL1" || return 1
72 eval POOL=$(ceph balancer pool ls | jq '.[1]')
73 test "$POOL" = "$TEST_POOL2" || return 1
74 ceph balancer pool rm $TEST_POOL1 || return 1
75 ceph balancer pool rm $TEST_POOL2 || return 1
76 ceph balancer pool ls || return 1
77 ceph balancer pool add $TEST_POOL1 || return 1
78
79 ceph balancer mode crush-compat || return 1
80 ceph balancer status || return 1
81 eval MODE=$(ceph balancer status | jq '.mode')
82 test $MODE = "crush-compat" || return 1
83 ! ceph balancer optimize plan_crush $TEST_POOL1 || return 1
84 ceph balancer status || return 1
85 eval RESULT=$(ceph balancer status | jq '.optimize_result')
86 test "$RESULT" = "Distribution is already perfect" || return 1
87
88 ceph balancer on || return 1
89 ACTIVE=$(ceph balancer status | jq '.active')
90 test $ACTIVE = "true" || return 1
91 sleep 2
92 ceph balancer status || return 1
93 ceph balancer off || return 1
94 ACTIVE=$(ceph balancer status | jq '.active')
95 test $ACTIVE = "false" || return 1
96 sleep 2
97
98 ceph balancer reset || return 1
99
100 ceph balancer mode upmap || return 1
101 ceph balancer status || return 1
102 eval MODE=$(ceph balancer status | jq '.mode')
103 test $MODE = "upmap" || return 1
104 ! ceph balancer optimize plan_upmap $TEST_POOL || return 1
105 ceph balancer status || return 1
106 eval RESULT=$(ceph balancer status | jq '.optimize_result')
107 test "$RESULT" = "Unable to find further optimization, or pool(s)' pg_num is decreasing, or distribution is already perfect" || return 1
108
109 ceph balancer on || return 1
110 ACTIVE=$(ceph balancer status | jq '.active')
111 test $ACTIVE = "true" || return 1
112 sleep 2
113 ceph balancer status || return 1
114 ceph balancer off || return 1
115 ACTIVE=$(ceph balancer status | jq '.active')
116 test $ACTIVE = "false" || return 1
117
118 teardown $dir || return 1
119 }
120
121 main balancer "$@"
122
123 # Local Variables:
124 # compile-command: "make -j4 && ../qa/run-standalone.sh balancer.sh"
125 # End: