]> git.proxmox.com Git - ceph.git/blame - ceph/qa/standalone/mon/mon-bind.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / qa / standalone / mon / mon-bind.sh
CommitLineData
11fdf7f2 1#!/usr/bin/env bash
224ce89b
WB
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#
c07f9fc5 15source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
224ce89b
WB
16
17SOCAT_PIDS=()
18
19function port_forward() {
20 local source_port=$1
21 local target_port=$2
22
23 socat TCP-LISTEN:${source_port},fork,reuseaddr TCP:localhost:${target_port} &
24 SOCAT_PIDS+=( $! )
25}
26
27function cleanup() {
28 for p in "${SOCAT_PIDS[@]}"; do
29 kill $p
30 done
31 SOCAT_PIDS=()
32}
33
34trap cleanup SIGTERM SIGKILL SIGQUIT SIGINT
35
36function run() {
37 local dir=$1
38 shift
39
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
47 export CEPH_ARGS
48 CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
49
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; }
54 teardown $dir
55 done
56}
57
58function TEST_mon_client_connect_fails() {
59 local dir=$1
60
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} "
c07f9fc5 65 run_mon $dir a --mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
224ce89b
WB
66
67 # now attempt to ping it that should fail.
68 timeout 3 ceph ping mon.a || return 0
69 return 1
70}
71
72function TEST_mon_client_connect() {
73 local dir=$1
74
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} "
c07f9fc5 79 run_mon $dir a --mon-host=${MON_IP}:${MONA_PUBLIC} --public-bind-addr=${MON_IP}:${MONA_BIND} || return 1
224ce89b
WB
80
81 # now forward the public port to the bind port.
82 port_forward ${MONA_PUBLIC} ${MONA_BIND}
83
84 # attempt to connect. we expect that to work
85 ceph ping mon.a || return 1
86}
87
88function TEST_mon_quorum() {
89 local dir=$1
90
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} "
c07f9fc5
FG
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
224ce89b
WB
98
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}
103
104 # expect monmap to contain 3 monitors (a, b, and c)
9f95a23c 105 jqinput="$(ceph quorum_status --format=json 2>/dev/null)"
224ce89b
WB
106 jq_success "$jqinput" '.monmap.mons | length == 3' || return 1
107
108 # quorum should form
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
113}
114
115function TEST_put_get() {
116 local dir=$1
117
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} "
c07f9fc5
FG
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
224ce89b
WB
125
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}
130
131 # quorum should form
132 wait_for_quorum 300 3 || return 1
133
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
138
b5b8bbf5 139 create_pool hello 8 || return 1
224ce89b
WB
140
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
145}
146
147main mon-bind "$@"