3 # Copyright (C) 2017 Quantum Corp.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Library Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Library Public License for more details.
15 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
19 function port_forward
() {
23 socat TCP-LISTEN
:${source_port},fork
,reuseaddr TCP
:localhost
:${target_port} &
28 for p
in "${SOCAT_PIDS[@]}"; do
34 trap cleanup SIGTERM SIGKILL SIGQUIT SIGINT
40 export MON_IP
=127.0.0.1
41 export MONA_PUBLIC
=7132 # git grep '\<7132\>' ; there must be only one
42 export MONB_PUBLIC
=7133 # git grep '\<7133\>' ; there must be only one
43 export MONC_PUBLIC
=7134 # git grep '\<7134\>' ; there must be only one
44 export MONA_BIND
=7135 # git grep '\<7135\>' ; there must be only one
45 export MONB_BIND
=7136 # git grep '\<7136\>' ; there must be only one
46 export MONC_BIND
=7137 # git grep '\<7137\>' ; there must be only one
48 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
50 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
51 for func
in $funcs ; do
52 setup
$dir ||
return 1
53 $func $dir && cleanup ||
{ cleanup
; return 1; }
58 function TEST_mon_client_connect_fails
() {
61 # start the mon with a public-bind-addr that is different
62 # from the public-addr.
63 CEPH_ARGS
+="--mon-initial-members=a "
64 CEPH_ARGS
+="--mon-host=${MON_IP}:${MONA_PUBLIC} "
65 run_mon
$dir a
--mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} ||
return 1
67 # now attempt to ping it that should fail.
68 timeout
3 ceph
ping mon.a ||
return 0
72 function TEST_mon_client_connect
() {
75 # start the mon with a public-bind-addr that is different
76 # from the public-addr.
77 CEPH_ARGS
+="--mon-initial-members=a "
78 CEPH_ARGS
+="--mon-host=${MON_IP}:${MONA_PUBLIC} "
79 run_mon
$dir a
--mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} ||
return 1
81 # now forward the public port to the bind port.
82 port_forward
${MONA_PUBLIC} ${MONA_BIND}
84 # attempt to connect. we expect that to work
85 ceph
ping mon.a ||
return 1
88 function TEST_mon_quorum
() {
91 # start the mon with a public-bind-addr that is different
92 # from the public-addr.
93 CEPH_ARGS
+="--mon-initial-members=a,b,c "
94 CEPH_ARGS
+="--mon-host=${MON_IP}:${MONA_PUBLIC},${MON_IP}:${MONB_PUBLIC},${MON_IP}:${MONC_PUBLIC} "
95 run_mon
$dir a
--public-addr=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} ||
return 1
96 run_mon
$dir b
--public-addr=${MON_IP}:${MONB_PUBLIC} --public-bind-addr=${MON_IP}:${MONB_BIND} ||
return 1
97 run_mon
$dir c
--public-addr=${MON_IP}:${MONC_PUBLIC} --public-bind-addr=${MON_IP}:${MONC_BIND} ||
return 1
99 # now forward the public port to the bind port.
100 port_forward
${MONA_PUBLIC} ${MONA_BIND}
101 port_forward
${MONB_PUBLIC} ${MONB_BIND}
102 port_forward
${MONC_PUBLIC} ${MONC_BIND}
104 # expect monmap to contain 3 monitors (a, b, and c)
105 jqinput
="$(ceph mon_status --format=json 2>/dev/null)"
106 jq_success
"$jqinput" '.monmap.mons | length == 3' ||
return 1
109 wait_for_quorum
300 3 ||
return 1
110 # expect quorum to have all three monitors
111 jqfilter
='.quorum | length == 3'
112 jq_success
"$jqinput" "$jqfilter" ||
return 1
115 function TEST_put_get
() {
118 # start the mon with a public-bind-addr that is different
119 # from the public-addr.
120 CEPH_ARGS
+="--mon-initial-members=a,b,c "
121 CEPH_ARGS
+="--mon-host=${MON_IP}:${MONA_PUBLIC},${MON_IP}:${MONB_PUBLIC},${MON_IP}:${MONC_PUBLIC} "
122 run_mon
$dir a
--public-addr=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} ||
return 1
123 run_mon
$dir b
--public-addr=${MON_IP}:${MONB_PUBLIC} --public-bind-addr=${MON_IP}:${MONB_BIND} ||
return 1
124 run_mon
$dir c
--public-addr=${MON_IP}:${MONC_PUBLIC} --public-bind-addr=${MON_IP}:${MONC_BIND} ||
return 1
126 # now forward the public port to the bind port.
127 port_forward
${MONA_PUBLIC} ${MONA_BIND}
128 port_forward
${MONB_PUBLIC} ${MONB_BIND}
129 port_forward
${MONC_PUBLIC} ${MONC_BIND}
132 wait_for_quorum
300 3 ||
return 1
134 run_mgr
$dir x ||
return 1
135 run_osd
$dir 0 ||
return 1
136 run_osd
$dir 1 ||
return 1
137 run_osd
$dir 2 ||
return 1
139 ceph osd pool create hello
8 ||
return 1
141 echo "hello world" > $dir/hello
142 rados
--pool hello put foo
$dir/hello ||
return 1
143 rados
--pool hello get foo
$dir/hello2 ||
return 1
144 diff $dir/hello
$dir/hello2 ||
return 1