]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: listen on random port in tests which start ceph-mon 26376/head
authorKefu Chai <kchai@redhat.com>
Sun, 27 Jan 2019 06:27:57 +0000 (14:27 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 12 Feb 2019 16:12:49 +0000 (00:12 +0800)
See-also: http://tracker.ceph.com/issues/36737
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 94a84b6f5adad75b3cbf956447ee5d9caf1018d2)

qa/standalone/ceph-helpers.sh
src/test/osd/safe-to-destroy.sh
src/test/smoke.sh

index fc3f724e85bb88d5bcab78430a184f5913066c2b..ffc71c215051da490398c937b50f4fc6761ab775 100755 (executable)
@@ -384,6 +384,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()"
+}
+
 #######################################################################
 
 ##
index f03a235f7dda3de4eab917bf1f559e947121c00d..670e5ad7509386faa0718e6d5a0803ae753d099a 100755 (executable)
@@ -8,7 +8,7 @@ function run() {
     local dir=$1
     shift
 
-    export CEPH_MON="127.0.0.1:7227" # git grep '\<7227\>' : there must be only one
+    export CEPH_MON="127.0.0.1:$(get_unused_port)"
     export CEPH_ARGS
     CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
     CEPH_ARGS+="--mon-host=$CEPH_MON "
index 1c79416cbd91c4bd4f235a83787a84c2c7360e87..941e3d1b147318ecf5bce83c67061f614959c9b7 100755 (executable)
@@ -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 "
@@ -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