Skip to content

Commit

Permalink
test: listen on random port in tests which start ceph-mon
Browse files Browse the repository at this point in the history
See-also: http://tracker.ceph.com/issues/36737
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 94a84b6)
  • Loading branch information
tchaikov committed Jan 29, 2019
1 parent 1a4ea38 commit c913d4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions qa/standalone/ceph-helpers.sh
Expand Up @@ -389,6 +389,17 @@ function test_kill_daemons() {
teardown $dir || return 1
}

#
# return a random TCP port which is not used yet
#
# please note, there could be racing if we use this function for
# a free port, and then try to bind on this port.
#
function get_unused_port() {
local ip=127.0.0.1
python3 -c "import socket; s=socket.socket(); s.bind(('$ip', 0)); print(s.getsockname()[1]); s.close()"
}

#######################################################################

##
Expand Down
11 changes: 6 additions & 5 deletions src/test/smoke.sh
Expand Up @@ -2,11 +2,13 @@

source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

mon_port=$(get_unused_port)

function run() {
local dir=$1
shift

export CEPH_MON="127.0.0.1:7224" # git grep '\<7224\>' : there must be only one
export CEPH_MON="127.0.0.1:$mon_port"
export CEPH_ARGS
CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
CEPH_ARGS+="--mon-host=$CEPH_MON "
Expand Down Expand Up @@ -34,10 +36,9 @@ function TEST_minimal() {

function TEST_multimon() {
local dir=$1

MONA="127.0.0.1:7224" # git grep '\<7224\>' : there must be only one
MONB="127.0.0.1:7225" # git grep '\<7225\>' : there must be only one
MONC="127.0.0.1:7226" # git grep '\<7226\>' : there must be only one
MONA="127.0.0.1:$((mon_port++))"
MONB="127.0.0.1:$((mon_port++))"
MONC="127.0.0.1:$((mon_port++))"

run_mon $dir a --public-addr $MONA
run_mon $dir b --public-addr $MONB
Expand Down

0 comments on commit c913d4d

Please sign in to comment.