summaryrefslogtreecommitdiffstats
path: root/src/ceph/qa/standalone/crush/crush-choose-args.sh
blob: 6e03a999c64d7475854b1a082e8ec6f6410acec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Copyright (C) 2017 Red Hat <contact@redhat.com>
#
# Author: Loic Dachary <loic@dachary.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library Public License for more details.
#

source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

function run() {
    local dir=$1
    shift

    export CEPH_MON="127.0.0.1:7131" # git grep '\<7131\>' : there must be only one
    export CEPH_ARGS
    CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
    CEPH_ARGS+="--mon-host=$CEPH_MON "
    CEPH_ARGS+="--crush-location=root=default,host=HOST "
    CEPH_ARGS+="--osd-crush-initial-weight=3 "
    #
    # Disable device auto class feature for now.
    # The device class is non-deterministic and will
    # crash the crushmap comparison below.
    #
    CEPH_ARGS+="--osd-class-update-on-start=false "

    local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
    for func in $funcs ; do
        setup $dir || return 1
        $func $dir || return 1
        teardown $dir || return 1
    done
}

function TEST_choose_args_update() {
    #
    # adding a weighted OSD updates the weight up to the top
    #
    local dir=$1

    run_mon $dir a || return 1
    run_osd $dir 0 || return 1

    ceph osd set-require-min-compat-client luminous
    ceph osd getcrushmap > $dir/map || return 1
    crushtool -d $dir/map -o $dir/map.txt || return 1
    sed -i -e '/end crush map/d' $dir/map.txt
    cat >> $dir/map.txt <<EOF
# choose_args
choose_args 0 {
  {
    bucket_id -1
    weight_set [
      [ 3.000 ]
      [ 3.000 ]
    ]
    ids [ -10 ]
  }
  {
    bucket_id -2
    weight_set [
      [ 2.000 ]
      [ 2.000 ]
    ]
    ids [ -20 ]
  }
}

# end crush map
EOF
    crushtool -c $dir/map.txt -o $dir/map-new || return 1
    ceph osd setcrushmap -i $dir/map-new || return 1

    run_osd $dir 1 || return 1
    ceph osd getcrushmap > $dir/map-one-more || return 1
    crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
    cat $dir/map-one-more.txt
    diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-3.txt || return 1

    destroy_osd $dir 1 || return 1
    ceph osd getcrushmap > $dir/map-one-less || return 1
    crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
    diff -u $dir/map-one-less.txt $dir/map.txt || return 1
}

function TEST_no_update_weight_set() {
    #
    # adding a zero weight OSD does not update the weight set at all
    #
    local dir=$1

    ORIG_CEPH_ARGS="$CEPH_ARGS"
    CEPH_ARGS+="--osd-crush-update-weight-set=false "

    run_mon $dir a || return 1
    run_osd $dir 0 || return 1

    ceph osd set-require-min-compat-client luminous
    ceph osd crush tree
    ceph osd getcrushmap > $dir/map || return 1
    crushtool -d $dir/map -o $dir/map.txt || return 1
    sed -i -e '/end crush map/d' $dir/map.txt
    cat >> $dir/map.txt <<EOF
# choose_args
choose_args 0 {
  {
    bucket_id -1
    weight_set [
      [ 2.000 ]
      [ 1.000 ]
    ]
    ids [ -10 ]
  }
  {
    bucket_id -2
    weight_set [
      [ 2.000 ]
      [ 1.000 ]
    ]
    ids [ -20 ]
  }
}

# end crush map
EOF
    crushtool -c $dir/map.txt -o $dir/map-new || return 1
    ceph osd setcrushmap -i $dir/map-new || return 1
    ceph osd crush tree


    run_osd $dir 1 || return 1
    ceph osd crush tree
    ceph osd getcrushmap > $dir/map-one-more || return 1
    crushtool -d $dir/map-one-more -o $dir/map-one-more.txt || return 1
    cat $dir/map-one-more.txt
    diff -u $dir/map-one-more.txt $CEPH_ROOT/src/test/crush/crush-choose-args-expected-one-more-0.txt || return 1

    destroy_osd $dir 1 || return 1
    ceph osd crush tree
    ceph osd getcrushmap > $dir/map-one-less || return 1
    crushtool -d $dir/map-one-less -o $dir/map-one-less.txt || return 1
    diff -u $dir/map-one-less.txt $dir/map.txt || return 1

    CEPH_ARGS="$ORIG_CEPH_ARGS"
}

main crush-choose-args "$@"

# Local Variables:
# 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"
# End: