]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com> | |
4 | # Copyright (C) 2014 Red Hat <contact@redhat.com> | |
5 | # | |
6 | # Author: Loic Dachary <loic@dachary.org> | |
7 | # | |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU Library Public License as published by | |
10 | # the Free Software Foundation; either version 2, or (at your option) | |
11 | # any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU Library Public License for more details. | |
17 | # | |
18 | set -xe | |
19 | PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' | |
20 | ||
21 | source $(dirname $0)/../detect-build-env-vars.sh | |
22 | ||
23 | DIR=mkfs | |
24 | export CEPH_CONF=/dev/null | |
25 | unset CEPH_ARGS | |
26 | MON_ID=a | |
27 | MON_DIR=$DIR/$MON_ID | |
28 | CEPH_MON=127.0.0.1:7110 # git grep '\<7110\>' : there must be only one | |
29 | TIMEOUT=360 | |
30 | ||
31 | function setup() { | |
32 | teardown | |
33 | mkdir $DIR | |
34 | } | |
35 | ||
36 | function teardown() { | |
37 | kill_daemons | |
38 | rm -fr $DIR | |
39 | } | |
40 | ||
41 | function mon_mkfs() { | |
42 | local fsid=$(uuidgen) | |
43 | ||
44 | ceph-mon \ | |
45 | --id $MON_ID \ | |
46 | --fsid $fsid \ | |
47 | --erasure-code-dir=$CEPH_LIB \ | |
48 | --mkfs \ | |
49 | --mon-data=$MON_DIR \ | |
50 | --mon-initial-members=$MON_ID \ | |
51 | --mon-host=$CEPH_MON \ | |
52 | "$@" | |
53 | } | |
54 | ||
55 | function mon_run() { | |
56 | ceph-mon \ | |
57 | --id $MON_ID \ | |
58 | --chdir= \ | |
59 | --mon-osd-full-ratio=.99 \ | |
60 | --mon-data-avail-crit=1 \ | |
61 | --erasure-code-dir=$CEPH_LIB \ | |
62 | --mon-data=$MON_DIR \ | |
63 | --log-file=$MON_DIR/log \ | |
64 | --mon-cluster-log-file=$MON_DIR/log \ | |
65 | --run-dir=$MON_DIR \ | |
66 | --pid-file=$MON_DIR/pidfile \ | |
67 | --public-addr $CEPH_MON \ | |
68 | "$@" | |
69 | } | |
70 | ||
71 | function kill_daemons() { | |
72 | for pidfile in $(find $DIR -name pidfile) ; do | |
73 | pid=$(cat $pidfile) | |
74 | for try in 0 1 1 1 2 3 ; do | |
75 | kill $pid || break | |
76 | sleep $try | |
77 | done | |
78 | done | |
79 | } | |
80 | ||
81 | function auth_none() { | |
82 | mon_mkfs --auth-supported=none | |
83 | ||
84 | ceph-mon \ | |
85 | --id $MON_ID \ | |
86 | --mon-osd-full-ratio=.99 \ | |
87 | --mon-data-avail-crit=1 \ | |
88 | --erasure-code-dir=$CEPH_LIB \ | |
89 | --mon-data=$MON_DIR \ | |
90 | --extract-monmap $MON_DIR/monmap | |
91 | ||
92 | [ -f $MON_DIR/monmap ] || return 1 | |
93 | ||
94 | [ ! -f $MON_DIR/keyring ] || return 1 | |
95 | ||
96 | mon_run --auth-supported=none | |
97 | ||
98 | timeout $TIMEOUT ceph --mon-host $CEPH_MON mon stat || return 1 | |
99 | } | |
100 | ||
101 | function auth_cephx_keyring() { | |
102 | cat > $DIR/keyring <<EOF | |
103 | [mon.] | |
104 | key = AQDUS79S0AF9FRAA2cgRLFscVce0gROn/s9WMg== | |
105 | caps mon = "allow *" | |
106 | EOF | |
107 | ||
108 | mon_mkfs --keyring=$DIR/keyring | |
109 | ||
110 | [ -f $MON_DIR/keyring ] || return 1 | |
111 | ||
112 | mon_run | |
113 | ||
114 | timeout $TIMEOUT ceph \ | |
115 | --name mon. \ | |
116 | --keyring $MON_DIR/keyring \ | |
117 | --mon-host $CEPH_MON mon stat || return 1 | |
118 | } | |
119 | ||
120 | function auth_cephx_key() { | |
121 | if [ -f /etc/ceph/keyring ] ; then | |
122 | echo "Please move /etc/ceph/keyring away for testing!" | |
123 | return 1 | |
124 | fi | |
125 | ||
126 | local key=$(ceph-authtool --gen-print-key) | |
127 | ||
128 | if mon_mkfs --key='corrupted key' ; then | |
129 | return 1 | |
130 | else | |
131 | rm -fr $MON_DIR/store.db | |
132 | rm -fr $MON_DIR/kv_backend | |
133 | fi | |
134 | ||
135 | mon_mkfs --key=$key | |
136 | ||
137 | [ -f $MON_DIR/keyring ] || return 1 | |
138 | grep $key $MON_DIR/keyring | |
139 | ||
140 | mon_run | |
141 | ||
142 | timeout $TIMEOUT ceph \ | |
143 | --name mon. \ | |
144 | --keyring $MON_DIR/keyring \ | |
145 | --mon-host $CEPH_MON mon stat || return 1 | |
146 | } | |
147 | ||
148 | function makedir() { | |
149 | local toodeep=$MON_DIR/toodeep | |
150 | ||
151 | # fail if recursive directory creation is needed | |
152 | ceph-mon \ | |
153 | --id $MON_ID \ | |
154 | --mon-osd-full-ratio=.99 \ | |
155 | --mon-data-avail-crit=1 \ | |
156 | --erasure-code-dir=$CEPH_LIB \ | |
157 | --mkfs \ | |
158 | --mon-data=$toodeep 2>&1 | tee $DIR/makedir.log | |
159 | grep 'toodeep.*No such file' $DIR/makedir.log > /dev/null | |
160 | rm $DIR/makedir.log | |
161 | ||
162 | # an empty directory does not mean the mon exists | |
163 | mkdir $MON_DIR | |
164 | mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log | |
165 | ! grep "$MON_DIR already exists" $DIR/makedir.log || return 1 | |
166 | } | |
167 | ||
168 | function idempotent() { | |
169 | mon_mkfs --auth-supported=none | |
170 | mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log | |
171 | grep "'$MON_DIR' already exists" $DIR/makedir.log > /dev/null || return 1 | |
172 | } | |
173 | ||
174 | function run() { | |
175 | local actions | |
176 | actions+="makedir " | |
177 | actions+="idempotent " | |
178 | actions+="auth_cephx_key " | |
179 | actions+="auth_cephx_keyring " | |
180 | actions+="auth_none " | |
181 | for action in $actions ; do | |
182 | setup | |
183 | $action || return 1 | |
184 | teardown | |
185 | done | |
186 | } | |
187 | ||
188 | run | |
189 | ||
190 | # Local Variables: | |
191 | # compile-command: "cd ../.. ; make TESTS=test/mon/mkfs.sh check" | |
192 | # End: |