3 # Copyright (C) 2017 Red Hat <contact@redhat.com>
5 # Author: Loic Dachary <loic@dachary.org>
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)
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.
18 source $
(dirname $0)/..
/detect-build-env-vars.sh
19 source $CEPH_ROOT/qa
/workunits
/ceph-helpers.sh
25 export CEPH_MON
="127.0.0.1:7130" # git grep '\<7130\>' : there must be only one
27 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
28 CEPH_ARGS
+="--mon-host=$CEPH_MON "
30 # Disable auto-class, so we can inject device class manually below
32 CEPH_ARGS
+="--osd-class-update-on-start=false "
34 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
35 for func
in $funcs ; do
36 setup
$dir ||
return 1
37 $func $dir ||
return 1
38 teardown
$dir ||
return 1
42 function add_something
() {
44 local obj
=${2:-SOMETHING}
47 echo $payload > $dir/ORIGINAL
48 rados
--pool rbd put
$obj $dir/ORIGINAL ||
return 1
51 function get_osds_up
() {
55 local osds
=$
(ceph
--format xml osd map
$poolname $objectname 2>/dev
/null | \
56 $XMLSTARLET sel
-t -m "//up/osd" -v .
-o ' ')
57 # get rid of the trailing space
61 function TEST_classes
() {
64 run_mon
$dir a ||
return 1
65 run_osd
$dir 0 ||
return 1
66 run_osd
$dir 1 ||
return 1
67 run_osd
$dir 2 ||
return 1
69 test "$(get_osds_up rbd SOMETHING)" == "1 2 0" ||
return 1
70 add_something
$dir SOMETHING ||
return 1
73 # osd.0 has class ssd and the rule is modified
74 # to only take ssd devices.
76 ceph osd getcrushmap
> $dir/map ||
return 1
77 crushtool
-d $dir/map
-o $dir/map.txt ||
return 1
79 -e '/device 0 osd.0/s/$/ class ssd/' \
80 -e '/step take default/s/$/ class ssd/' \
81 $dir/map.txt ||
return 1
82 crushtool
-c $dir/map.txt
-o $dir/map-new ||
return 1
83 ceph osd setcrushmap
-i $dir/map-new ||
return 1
86 # There can only be one mapping since there only is
87 # one device with ssd class.
90 for delay
in 2 4 8 16 32 64 128 256 ; do
91 if test "$(get_osds_up rbd SOMETHING_ELSE)" == "0" ; then
96 ceph osd dump
# for debugging purposes
97 ceph pg dump
# for debugging purposes
101 # Writing keeps working because the pool is min_size 1 by
104 add_something
$dir SOMETHING_ELSE ||
return 1
107 # Sanity check that the rule indeed has ssd
108 # generated bucket with a name including ~ssd.
110 ceph osd crush dump |
grep -q '~ssd' ||
return 1
113 function TEST_set_device_class
() {
116 TEST_classes
$dir ||
return 1
118 ceph osd crush set-device-class ssd osd
.0 ||
return 1
119 ceph osd crush class ls-osd ssd |
grep 0 ||
return 1
120 ceph osd crush set-device-class ssd osd
.1 ||
return 1
121 ceph osd crush class ls-osd ssd |
grep 1 ||
return 1
122 ceph osd crush set-device-class ssd
0 1 ||
return 1 # should be idempotent
125 for delay
in 2 4 8 16 32 64 128 256 ; do
126 if test "$(get_osds_up rbd SOMETHING_ELSE)" == "0 1" ; then
132 ceph osd dump
# for debugging purposes
133 ceph pg dump
# for debugging purposes
138 function TEST_mon_classes
() {
141 run_mon
$dir a ||
return 1
142 ceph osd crush class create CLASS ||
return 1
143 ceph osd crush class create CLASS ||
return 1 # idempotent
144 ceph osd crush class
ls |
grep CLASS ||
return 1
145 ceph osd crush class rename CLASS TEMP ||
return 1
146 ceph osd crush class
ls |
grep TEMP ||
return 1
147 ceph osd crush class rename TEMP CLASS ||
return 1
148 ceph osd crush class
ls |
grep CLASS ||
return 1
149 ceph osd crush class
rm CLASS ||
return 1
150 expect_failure
$dir ENOENT ceph osd crush class
rm CLASS ||
return 1
153 main crush-classes
"$@"
156 # compile-command: "cd ../../../build ; ln -sf ../src/ceph-disk/ceph_disk/main.py bin/ceph-disk && make -j4 && ../src/test/crush/crush-classes.sh"