]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rados/test_crushdiff.sh
import quincy beta 17.1.0
[ceph.git] / ceph / qa / workunits / rados / test_crushdiff.sh
1 #!/usr/bin/env bash
2
3 set -ex
4
5 REP_POOL=
6 EC_POOL=
7 TEMPDIR=
8
9 OSD_NUM=$(ceph osd ls | wc -l)
10 test ${OSD_NUM} -gt 0
11
12 setup() {
13 local pool
14
15 TEMPDIR=`mktemp -d`
16
17 pool=test-crushdiff-rep-$$
18 ceph osd pool create ${pool} 32
19 REP_POOL=${pool}
20 rados -p ${REP_POOL} bench 5 write --no-cleanup
21
22 if [ ${OSD_NUM} -gt 3 ]; then
23 pool=test-crushdiff-ec-$$
24 ceph osd pool create ${pool} 32 32 erasure
25 EC_POOL=${pool}
26 rados -p ${EC_POOL} bench 5 write --no-cleanup
27 fi
28 }
29
30 cleanup() {
31 set +e
32
33 test -n "${EC_POOL}" &&
34 ceph osd pool delete "${EC_POOL}" "${EC_POOL}" \
35 --yes-i-really-really-mean-it
36 EC_POOL=
37
38 test -n "${REP_POOL}" &&
39 ceph osd pool delete "${REP_POOL}" "${REP_POOL}" \
40 --yes-i-really-really-mean-it
41 REP_POOL=
42
43 test -n "${TEMPDIR}" && rm -Rf ${TEMPDIR}
44 TEMPDIR=
45 }
46
47 trap "cleanup" INT TERM EXIT
48
49 setup
50
51 # test without crushmap modification
52
53 crushdiff export ${TEMPDIR}/cm.txt --verbose
54 crushdiff compare ${TEMPDIR}/cm.txt --verbose
55 crushdiff import ${TEMPDIR}/cm.txt --verbose
56
57 # test using a compiled crushmap
58
59 crushdiff export ${TEMPDIR}/cm --compiled --verbose
60 crushdiff compare ${TEMPDIR}/cm --compiled --verbose
61 crushdiff import ${TEMPDIR}/cm --compiled --verbose
62
63 # test using "offline" osdmap and pg-dump
64
65 ceph osd getmap -o ${TEMPDIR}/osdmap
66 ceph pg dump --format json > ${TEMPDIR}/pg-dump
67
68 crushdiff export ${TEMPDIR}/cm.txt --osdmap ${TEMPDIR}/osdmap --verbose
69 crushdiff compare ${TEMPDIR}/cm.txt --osdmap ${TEMPDIR}/osdmap \
70 --pg-dump ${TEMPDIR}/pg-dump --verbose | tee ${TEMPDIR}/compare.txt
71
72 # test the diff is zero when the crushmap is not modified
73
74 grep '^0/[0-9]* (0\.00%) pgs affected' ${TEMPDIR}/compare.txt
75 grep '^0/[0-9]* (0\.00%) objects affected' ${TEMPDIR}/compare.txt
76 grep '^0/[0-9]* (0\.00%) pg shards to move' ${TEMPDIR}/compare.txt
77 grep '^0/[0-9]* (0\.00%) pg object shards to move' ${TEMPDIR}/compare.txt
78 grep '^0\.00/.* (0\.00%) bytes to move' ${TEMPDIR}/compare.txt
79 crushdiff import ${TEMPDIR}/cm.txt --osdmap ${TEMPDIR}/osdmap --verbose
80
81 if [ ${OSD_NUM} -gt 3 ]; then
82
83 # test the diff is non-zero when the crushmap is modified
84
85 cat ${TEMPDIR}/cm.txt >&2
86
87 weight=$(awk '/item osd\.0 weight ([0-9.]+)/ {print $4 * 3}' \
88 ${TEMPDIR}/cm.txt)
89 test -n "${weight}"
90 sed -i -Ee 's/^(.*item osd\.0 weight )[0-9.]+/\1'${weight}'/' \
91 ${TEMPDIR}/cm.txt
92 crushdiff compare ${TEMPDIR}/cm.txt --osdmap ${TEMPDIR}/osdmap \
93 --pg-dump ${TEMPDIR}/pg-dump --verbose | tee ${TEMPDIR}/compare.txt
94 grep '^[1-9][0-9]*/[0-9]* (.*%) pgs affected' ${TEMPDIR}/compare.txt
95 grep '^[1-9][0-9]*/[0-9]* (.*%) objects affected' ${TEMPDIR}/compare.txt
96 grep '^[1-9][0-9]*/[0-9]* (.*%) pg shards to move' ${TEMPDIR}/compare.txt
97 grep '^[1-9][0-9]*/[0-9]* (.*%) pg object shards to move' \
98 ${TEMPDIR}/compare.txt
99 grep '^.*/.* (.*%) bytes to move' ${TEMPDIR}/compare.txt
100 crushdiff import ${TEMPDIR}/cm.txt --osdmap ${TEMPDIR}/osdmap --verbose
101 fi
102
103 echo OK