]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/crush/crush-choose-args.sh
c0aefb23834fce9c27ea8c29074c5cf4bececa9e
[ceph.git] / ceph / src / test / 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 $(dirname $0)/../detect-build-env-vars.sh
19 source $CEPH_ROOT/qa/workunits/ceph-helpers.sh
20
21 function run() {
22 local dir=$1
23 shift
24
25 export CEPH_MON="127.0.0.1:7131" # git grep '\<7131\>' : there must be only one
26 export CEPH_ARGS
27 CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
28 CEPH_ARGS+="--mon-host=$CEPH_MON "
29 CEPH_ARGS+="--crush-location=root=default,host=HOST "
30 CEPH_ARGS+="--osd-crush-initial-weight=3 "
31
32 local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
33 for func in $funcs ; do
34 setup $dir || return 1
35 $func $dir || return 1
36 teardown $dir || return 1
37 done
38 }
39
40 function TEST_choose_args_update() {
41 #
42 # adding a weighted OSD updates the weight up to the top
43 #
44 local dir=$1
45
46 run_mon $dir a || return 1
47 run_osd $dir 0 || return 1
48
49 ceph osd getcrushmap > $dir/map || return 1
50 crushtool -d $dir/map -o $dir/map.txt || return 1
51 sed -i -e '/end crush map/d' $dir/map.txt
52 cat >> $dir/map.txt <<EOF
53 # choose_args
54 choose_args 0 {
55 {
56 bucket_id -1
57 weight_set [
58 [ 3.000 ]
59 [ 3.000 ]
60 ]
61 ids [ -10 ]
62 }
63 {
64 bucket_id -2
65 weight_set [
66 [ 2.000 ]
67 [ 2.000 ]
68 ]
69 ids [ -20 ]
70 }
71 }
72
73 # end crush map
74 EOF
75 crushtool -c $dir/map.txt -o $dir/map-new || return 1
76 ceph osd setcrushmap -i $dir/map-new || return 1
77
78 run_osd $dir 1 || return 1
79 ceph osd getcrushmap > $dir/map-one-more || return 1
80 crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
81 cat $dir/map-one-more.txt
82 diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-3.txt || return 1
83
84 destroy_osd $dir 1 || return 1
85 ceph osd getcrushmap > $dir/map-one-less || return 1
86 crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
87 diff -u $dir/map-one-less.txt $dir/map.txt || return 1
88 }
89
90 function TEST_no_update_weight_set() {
91 #
92 # adding a zero weight OSD does not update the weight set at all
93 #
94 local dir=$1
95
96 ORIG_CEPH_ARGS="$CEPH_ARGS"
97 CEPH_ARGS+="--osd-crush-update-weight-set=false "
98
99 run_mon $dir a || return 1
100 run_osd $dir 0 || return 1
101
102 ceph osd getcrushmap > $dir/map || return 1
103 crushtool -d $dir/map -o $dir/map.txt || return 1
104 sed -i -e '/end crush map/d' $dir/map.txt
105 cat >> $dir/map.txt <<EOF
106 # choose_args
107 choose_args 0 {
108 {
109 bucket_id -1
110 weight_set [
111 [ 6.000 ]
112 [ 7.000 ]
113 ]
114 ids [ -10 ]
115 }
116 {
117 bucket_id -2
118 weight_set [
119 [ 2.000 ]
120 [ 2.000 ]
121 ]
122 ids [ -20 ]
123 }
124 }
125
126 # end crush map
127 EOF
128 crushtool -c $dir/map.txt -o $dir/map-new || return 1
129 ceph osd setcrushmap -i $dir/map-new || return 1
130
131
132 run_osd $dir 1 || return 1
133 ceph osd getcrushmap > $dir/map-one-more || return 1
134 crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
135 cat $dir/map-one-more.txt
136 diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-0.txt || return 1
137
138 destroy_osd $dir 1 || return 1
139 ceph osd getcrushmap > $dir/map-one-less || return 1
140 crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
141 diff -u $dir/map-one-less.txt $dir/map.txt || return 1
142
143 CEPH_ARGS="$ORIG_CEPH_ARGS"
144 }
145
146 main crush-choose-args "$@"
147
148 # Local Variables:
149 # 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"
150 # End: