Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / standalone / crush / crush-choose-args.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Red Hat <contact@redhat.com>
4 #
5 # Author: Loic Dachary <loic@dachary.org>
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
18 source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
19
20 function run() {
21     local dir=$1
22     shift
23
24     export CEPH_MON="127.0.0.1:7131" # git grep '\<7131\>' : there must be only one
25     export CEPH_ARGS
26     CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
27     CEPH_ARGS+="--mon-host=$CEPH_MON "
28     CEPH_ARGS+="--crush-location=root=default,host=HOST "
29     CEPH_ARGS+="--osd-crush-initial-weight=3 "
30     #
31     # Disable device auto class feature for now.
32     # The device class is non-deterministic and will
33     # crash the crushmap comparison below.
34     #
35     CEPH_ARGS+="--osd-class-update-on-start=false "
36
37     local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
38     for func in $funcs ; do
39         setup $dir || return 1
40         $func $dir || return 1
41         teardown $dir || return 1
42     done
43 }
44
45 function TEST_choose_args_update() {
46     #
47     # adding a weighted OSD updates the weight up to the top
48     #
49     local dir=$1
50
51     run_mon $dir a || return 1
52     run_osd $dir 0 || return 1
53
54     ceph osd set-require-min-compat-client luminous
55     ceph osd getcrushmap > $dir/map || return 1
56     crushtool -d $dir/map -o $dir/map.txt || return 1
57     sed -i -e '/end crush map/d' $dir/map.txt
58     cat >> $dir/map.txt <<EOF
59 # choose_args
60 choose_args 0 {
61   {
62     bucket_id -1
63     weight_set [
64       [ 3.000 ]
65       [ 3.000 ]
66     ]
67     ids [ -10 ]
68   }
69   {
70     bucket_id -2
71     weight_set [
72       [ 2.000 ]
73       [ 2.000 ]
74     ]
75     ids [ -20 ]
76   }
77 }
78
79 # end crush map
80 EOF
81     crushtool -c $dir/map.txt -o $dir/map-new || return 1
82     ceph osd setcrushmap -i $dir/map-new || return 1
83
84     run_osd $dir 1 || return 1
85     ceph osd getcrushmap > $dir/map-one-more || return 1
86     crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
87     cat $dir/map-one-more.txt
88     diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-3.txt || return 1
89
90     destroy_osd $dir 1 || return 1
91     ceph osd getcrushmap > $dir/map-one-less || return 1
92     crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
93     diff -u $dir/map-one-less.txt $dir/map.txt || return 1
94 }
95
96 function TEST_no_update_weight_set() {
97     #
98     # adding a zero weight OSD does not update the weight set at all
99     #
100     local dir=$1
101
102     ORIG_CEPH_ARGS="$CEPH_ARGS"
103     CEPH_ARGS+="--osd-crush-update-weight-set=false "
104
105     run_mon $dir a || return 1
106     run_osd $dir 0 || return 1
107
108     ceph osd set-require-min-compat-client luminous
109     ceph osd crush tree
110     ceph osd getcrushmap > $dir/map || return 1
111     crushtool -d $dir/map -o $dir/map.txt || return 1
112     sed -i -e '/end crush map/d' $dir/map.txt
113     cat >> $dir/map.txt <<EOF
114 # choose_args
115 choose_args 0 {
116   {
117     bucket_id -1
118     weight_set [
119       [ 2.000 ]
120       [ 1.000 ]
121     ]
122     ids [ -10 ]
123   }
124   {
125     bucket_id -2
126     weight_set [
127       [ 2.000 ]
128       [ 1.000 ]
129     ]
130     ids [ -20 ]
131   }
132 }
133
134 # end crush map
135 EOF
136     crushtool -c $dir/map.txt -o $dir/map-new || return 1
137     ceph osd setcrushmap -i $dir/map-new || return 1
138     ceph osd crush tree
139
140
141     run_osd $dir 1 || return 1
142     ceph osd crush tree
143     ceph osd getcrushmap > $dir/map-one-more || return 1
144     crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
145     cat $dir/map-one-more.txt
146     diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-0.txt || return 1
147
148     destroy_osd $dir 1 || return 1
149     ceph osd crush tree
150     ceph osd getcrushmap > $dir/map-one-less || return 1
151     crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
152     diff -u $dir/map-one-less.txt $dir/map.txt || return 1
153
154     CEPH_ARGS="$ORIG_CEPH_ARGS"
155 }
156
157 main crush-choose-args "$@"
158
159 # Local Variables:
160 # compile-command: "cd ../../../build ; ln -sf ../src/ceph-disk/ceph_disk/main.py bin/ceph-disk && make -j4 && ../src/test/crush/crush-choose-args.sh"
161 # End: