]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/mon/mon-bind.sh
update sources to v12.1.1
[ceph.git] / ceph / src / test / mon / mon-bind.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Quantum Corp.
4 #
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)
8 # any later version.
9 #
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.
14 #
15 source $(dirname $0)/../detect-build-env-vars.sh
16 source $CEPH_ROOT/qa/workunits/ceph-helpers.sh
17
18 SOCAT_PIDS=()
19
20 function port_forward() {
21 local source_port=$1
22 local target_port=$2
23
24 socat TCP-LISTEN:${source_port},fork,reuseaddr TCP:localhost:${target_port} &
25 SOCAT_PIDS+=( $! )
26 }
27
28 function cleanup() {
29 for p in "${SOCAT_PIDS[@]}"; do
30 kill $p
31 done
32 SOCAT_PIDS=()
33 }
34
35 trap cleanup SIGTERM SIGKILL SIGQUIT SIGINT
36
37 function run() {
38 local dir=$1
39 shift
40
41 export MON_IP=127.0.0.1
42 export MONA_PUBLIC=7132 # git grep '\<7132\>' ; there must be only one
43 export MONB_PUBLIC=7133 # git grep '\<7133\>' ; there must be only one
44 export MONC_PUBLIC=7134 # git grep '\<7134\>' ; there must be only one
45 export MONA_BIND=7135 # git grep '\<7135\>' ; there must be only one
46 export MONB_BIND=7136 # git grep '\<7136\>' ; there must be only one
47 export MONC_BIND=7137 # git grep '\<7137\>' ; there must be only one
48 export CEPH_ARGS
49 CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
50
51 local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
52 for func in $funcs ; do
53 setup $dir || return 1
54 $func $dir && cleanup || { cleanup; return 1; }
55 teardown $dir
56 done
57 }
58
59 function TEST_mon_client_connect_fails() {
60 local dir=$1
61
62 # start the mon with a public-bind-addr that is different
63 # from the public-addr.
64 CEPH_ARGS+="--mon-initial-members=a "
65 CEPH_ARGS+="--mon-host=${MON_IP}:${MONA_PUBLIC} "
66 run_mon_no_pool $dir a --mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
67
68 # now attempt to ping it that should fail.
69 timeout 3 ceph ping mon.a || return 0
70 return 1
71 }
72
73 function TEST_mon_client_connect() {
74 local dir=$1
75
76 # start the mon with a public-bind-addr that is different
77 # from the public-addr.
78 CEPH_ARGS+="--mon-initial-members=a "
79 CEPH_ARGS+="--mon-host=${MON_IP}:${MONA_PUBLIC} "
80 run_mon_no_pool $dir a --mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
81
82 # now forward the public port to the bind port.
83 port_forward ${MONA_PUBLIC} ${MONA_BIND}
84
85 # attempt to connect. we expect that to work
86 ceph ping mon.a || return 1
87 }
88
89 function TEST_mon_quorum() {
90 local dir=$1
91
92 # start the mon with a public-bind-addr that is different
93 # from the public-addr.
94 CEPH_ARGS+="--mon-initial-members=a,b,c "
95 CEPH_ARGS+="--mon-host=${MON_IP}:${MONA_PUBLIC},${MON_IP}:${MONB_PUBLIC},${MON_IP}:${MONC_PUBLIC} "
96 run_mon_no_pool $dir a --public-addr=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
97 run_mon_no_pool $dir b --public-addr=${MON_IP}:${MONB_PUBLIC} --public-bind-addr=${MON_IP}:${MONB_BIND} || return 1
98 run_mon_no_pool $dir c --public-addr=${MON_IP}:${MONC_PUBLIC} --public-bind-addr=${MON_IP}:${MONC_BIND} || return 1
99
100 # now forward the public port to the bind port.
101 port_forward ${MONA_PUBLIC} ${MONA_BIND}
102 port_forward ${MONB_PUBLIC} ${MONB_BIND}
103 port_forward ${MONC_PUBLIC} ${MONC_BIND}
104
105 # expect monmap to contain 3 monitors (a, b, and c)
106 jqinput="$(ceph mon_status --format=json 2>/dev/null)"
107 jq_success "$jqinput" '.monmap.mons | length == 3' || return 1
108
109 # quorum should form
110 wait_for_quorum 300 3 || return 1
111 # expect quorum to have all three monitors
112 jqfilter='.quorum | length == 3'
113 jq_success "$jqinput" "$jqfilter" || return 1
114 }
115
116 function TEST_put_get() {
117 local dir=$1
118
119 # start the mon with a public-bind-addr that is different
120 # from the public-addr.
121 CEPH_ARGS+="--mon-initial-members=a,b,c "
122 CEPH_ARGS+="--mon-host=${MON_IP}:${MONA_PUBLIC},${MON_IP}:${MONB_PUBLIC},${MON_IP}:${MONC_PUBLIC} "
123 run_mon_no_pool $dir a --public-addr=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
124 run_mon_no_pool $dir b --public-addr=${MON_IP}:${MONB_PUBLIC} --public-bind-addr=${MON_IP}:${MONB_BIND} || return 1
125 run_mon_no_pool $dir c --public-addr=${MON_IP}:${MONC_PUBLIC} --public-bind-addr=${MON_IP}:${MONC_BIND} || return 1
126
127 # now forward the public port to the bind port.
128 port_forward ${MONA_PUBLIC} ${MONA_BIND}
129 port_forward ${MONB_PUBLIC} ${MONB_BIND}
130 port_forward ${MONC_PUBLIC} ${MONC_BIND}
131
132 # quorum should form
133 wait_for_quorum 300 3 || return 1
134
135 run_mgr $dir x || return 1
136 run_osd $dir 0 || return 1
137 run_osd $dir 1 || return 1
138 run_osd $dir 2 || return 1
139
140 ceph osd pool create hello 8 || return 1
141
142 echo "hello world" > $dir/hello
143 rados --pool hello put foo $dir/hello || return 1
144 rados --pool hello get foo $dir/hello2 || return 1
145 diff $dir/hello $dir/hello2 || return 1
146 }
147
148 main mon-bind "$@"