blob: 6650bdb499a3cc0dfc1cbc60391912f083b9d3bd (
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#!/usr/bin/env bash
#
# Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
# Copyright (C) 2014 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.
#
set -xe
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
DIR=mkfs
export CEPH_CONF=/dev/null
unset CEPH_ARGS
MON_ID=a
MON_DIR=$DIR/$MON_ID
CEPH_MON=127.0.0.1:7110 # git grep '\<7110\>' : there must be only one
TIMEOUT=360
EXTRAOPTS=""
function setup() {
teardown
mkdir $DIR
}
function teardown() {
kill_daemons
rm -fr $DIR
}
function mon_mkfs() {
local fsid=$(uuidgen)
ceph-mon \
--id $MON_ID \
--fsid $fsid \
$EXTRAOPTS \
--mkfs \
--mon-data=$MON_DIR \
--mon-initial-members=$MON_ID \
--mon-host=$CEPH_MON \
"$@"
}
function mon_run() {
ceph-mon \
--id $MON_ID \
--chdir= \
--mon-osd-full-ratio=.99 \
--mon-data-avail-crit=1 \
$EXTRAOPTS \
--mon-data=$MON_DIR \
--log-file=$MON_DIR/log \
--mon-cluster-log-file=$MON_DIR/log \
--run-dir=$MON_DIR \
--pid-file=$MON_DIR/pidfile \
--public-addr $CEPH_MON \
"$@"
}
function kill_daemons() {
for pidfile in $(find $DIR -name pidfile) ; do
pid=$(cat $pidfile)
for try in 0 1 1 1 2 3 ; do
kill $pid || break
sleep $try
done
done
}
function auth_none() {
mon_mkfs --auth-supported=none
ceph-mon \
--id $MON_ID \
--mon-osd-full-ratio=.99 \
--mon-data-avail-crit=1 \
$EXTRAOPTS \
--mon-data=$MON_DIR \
--extract-monmap $MON_DIR/monmap
[ -f $MON_DIR/monmap ] || return 1
[ ! -f $MON_DIR/keyring ] || return 1
mon_run --auth-supported=none
timeout $TIMEOUT ceph --mon-host $CEPH_MON mon stat || return 1
}
function auth_cephx_keyring() {
cat > $DIR/keyring <<EOF
[mon.]
key = AQDUS79S0AF9FRAA2cgRLFscVce0gROn/s9WMg==
caps mon = "allow *"
EOF
mon_mkfs --keyring=$DIR/keyring
[ -f $MON_DIR/keyring ] || return 1
mon_run
timeout $TIMEOUT ceph \
--name mon. \
--keyring $MON_DIR/keyring \
--mon-host $CEPH_MON mon stat || return 1
}
function auth_cephx_key() {
if [ -f /etc/ceph/keyring ] ; then
echo "Please move /etc/ceph/keyring away for testing!"
return 1
fi
local key=$(ceph-authtool --gen-print-key)
if mon_mkfs --key='corrupted key' ; then
return 1
else
rm -fr $MON_DIR/store.db
rm -fr $MON_DIR/kv_backend
fi
mon_mkfs --key=$key
[ -f $MON_DIR/keyring ] || return 1
grep $key $MON_DIR/keyring
mon_run
timeout $TIMEOUT ceph \
--name mon. \
--keyring $MON_DIR/keyring \
--mon-host $CEPH_MON mon stat || return 1
}
function makedir() {
local toodeep=$MON_DIR/toodeep
# fail if recursive directory creation is needed
ceph-mon \
--id $MON_ID \
--mon-osd-full-ratio=.99 \
--mon-data-avail-crit=1 \
$EXTRAOPTS \
--mkfs \
--mon-data=$toodeep 2>&1 | tee $DIR/makedir.log
grep 'toodeep.*No such file' $DIR/makedir.log > /dev/null
rm $DIR/makedir.log
# an empty directory does not mean the mon exists
mkdir $MON_DIR
mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log
! grep "$MON_DIR already exists" $DIR/makedir.log || return 1
}
function idempotent() {
mon_mkfs --auth-supported=none
mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log
grep "'$MON_DIR' already exists" $DIR/makedir.log > /dev/null || return 1
}
function run() {
local actions
actions+="makedir "
actions+="idempotent "
actions+="auth_cephx_key "
actions+="auth_cephx_keyring "
actions+="auth_none "
for action in $actions ; do
setup
$action || return 1
teardown
done
}
run
# Local Variables:
# compile-command: "cd ../.. ; make TESTS=test/mon/mkfs.sh check"
# End:
|