[sheepdog] [PATCH 1/2] test: add two helpers to start/kill sheep

Liu Yuan namei.unix at gmail.com
Mon Aug 20 05:57:54 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 tests/001       |   12 ++++++------
 tests/002       |    8 ++++----
 tests/003       |    8 ++++----
 tests/004       |   12 ++++++------
 tests/005       |   10 +++++-----
 tests/006       |    4 ++--
 tests/007       |   10 +++++-----
 tests/008       |    6 +++---
 tests/009       |    6 +++---
 tests/010       |    6 +++---
 tests/011       |    2 +-
 tests/012       |    4 ++--
 tests/013       |    2 +-
 tests/014       |    2 +-
 tests/015       |    2 +-
 tests/016       |    2 +-
 tests/017       |    2 +-
 tests/018       |    2 +-
 tests/019       |    2 +-
 tests/020       |    2 +-
 tests/021       |    2 +-
 tests/022       |    2 +-
 tests/023       |    4 ++--
 tests/024       |    4 ++--
 tests/026       |    8 +++-----
 tests/common.rc |   10 ++++++++++
 26 files changed, 71 insertions(+), 63 deletions(-)

diff --git a/tests/001 b/tests/001
index 1a5749e..438c6e7 100755
--- a/tests/001
+++ b/tests/001
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -22,21 +22,21 @@ done
 $COLLIE cluster format
 
 # kill the master node
-pkill -f "sheep $STORE/0"
+_kill_sheep 0
 sleep 1
 
 # start another sheep
-$SHEEP $STORE/2 -z 2 -p 7002 -c $DRIVER
+_start_sheep 2
 sleep 1
 
 # kill all sheeps
 for i in 1 2; do
-    pkill -f "sheep $STORE/$i"
+    _kill_sheep $i
     sleep 1
 done
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -45,7 +45,7 @@ $COLLIE cluster info -p 7002 | _filter_cluster_info
 
 # add the other nodes
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
diff --git a/tests/002 b/tests/002
index 4fe52dd..6a97bb8 100755
--- a/tests/002
+++ b/tests/002
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -23,13 +23,13 @@ $COLLIE cluster format
 
 # kill all sheeps
 for i in 0 1 2; do
-    pkill -f "sheep $STORE/$i"
+    _kill_sheep $i
     sleep 1
 done
 
 # master transfer will happen once
 for i in 1 0 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -38,7 +38,7 @@ $COLLIE cluster info -p 7002 | _filter_cluster_info
 
 # add the other nodes
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
diff --git a/tests/003 b/tests/003
index a1b9027..5e0116f 100755
--- a/tests/003
+++ b/tests/003
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -23,13 +23,13 @@ $COLLIE cluster format
 
 # kill all sheeps
 for i in 0 1 2; do
-    pkill -f "sheep $STORE/$i"
+    _kill_sheep $i
     sleep 1
 done
 
 # master transfer will happen twice
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -38,7 +38,7 @@ $COLLIE cluster info -p 7002 | _filter_cluster_info
 
 # add the other nodes
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
diff --git a/tests/004 b/tests/004
index 0e1ee47..f5d13f4 100755
--- a/tests/004
+++ b/tests/004
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -23,21 +23,21 @@ $COLLIE cluster format -c 2
 
 for i in 2 3 4; do
     # add one node after killing existing one node
-    pkill -f "sheep $STORE/$((i - 2))"
+    _kill_sheep $((i - 2))
     sleep 1
 
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
 # kill all existing nodes
 for i in 3 4; do
-    pkill -f "sheep $STORE/$i"
+    _kill_sheep $i
     sleep 1
 done
 
 for i in 0 1 2 3 4; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -46,7 +46,7 @@ $COLLIE cluster info -p 7004 | _filter_cluster_info
 
 # add the other nodes
 for i in 0 1 2 3; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
diff --git a/tests/005 b/tests/005
index c448a0a..bc925e4 100755
--- a/tests/005
+++ b/tests/005
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -23,9 +23,9 @@ $COLLIE cluster format -c 1
 sleep 1
 
 for i in 2 3 4; do
-    pkill -f "sheep $STORE/$((i - 2))"
+    _kill_sheep $((i - 2))
     sleep 1
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -33,7 +33,7 @@ $COLLIE cluster shutdown -p 7004
 sleep 1
 
 for i in 0 1 2 3 4; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
@@ -44,7 +44,7 @@ done
 
 # add the other nodes
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
     sleep 1
 done
 
diff --git a/tests/006 b/tests/006
index 5b6ee51..d1170f6 100755
--- a/tests/006
+++ b/tests/006
@@ -13,7 +13,7 @@ status=1        # failure is the default!
 
 _cleanup
 
-$SHEEP $STORE/0 -z 0 -p 7000 -c $DRIVER
+_start_sheep 0
 sleep 1
 
 # start Sheepdog with one node
@@ -22,7 +22,7 @@ sleep 1
 
 # launch sheeps simultaneously
 for i in `seq 1 9`; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 _wait_for_sheep "10"
diff --git a/tests/007 b/tests/007
index 808c1e5..4ac722f 100755
--- a/tests/007
+++ b/tests/007
@@ -15,20 +15,20 @@ _cleanup
 
 
 # create a node who has wrong epoch
-$SHEEP $STORE/1 -p 7001 -z 1 -c $DRIVER
+_start_sheep 1
 sleep 1
 $COLLIE cluster format -p 7001 -c 1
 $COLLIE cluster shutdown -p 7001
 sleep 1
 
 # start Sheepdog with one node
-$SHEEP $STORE/0 -p 7000 -z 0 -c $DRIVER
+_start_sheep 0
 sleep 1
 $COLLIE cluster format -p 7000 -c 1
 
 for i in `seq 0 5`; do
-    $SHEEP $STORE/1 -p 7001 -z 1 -c $DRIVER  # should fail
-    $SHEEP $STORE/2 -p 7002 -z 2 -c $DRIVER  # should succeed
+    _start_sheep 1  # should fail
+    _start_sheep 2  # should succeed
     sleep 1
 
     if [ "`$COLLIE node list -p 7002 -r | wc -l`" -ne 2 ]; then
@@ -38,7 +38,7 @@ for i in `seq 0 5`; do
 	exit 1
     fi
 
-    pkill -f "$SHEEP $STORE/2"
+    _kill_sheep 2
     sleep 1
 done
 
diff --git a/tests/008 b/tests/008
index 711fbd5..25407be 100755
--- a/tests/008
+++ b/tests/008
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 7`; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 _wait_for_sheep "8"
@@ -34,12 +34,12 @@ sleep 3
 
 echo begin kill
 for i in `seq 1 5`; do
-    pkill -f "$SHEEP $STORE/$i -z $i -p 700$i"
+    _kill_sheep $i
     sleep 3
 done
 
 for i in `seq 1 5`; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 echo wait for object recovery to finish
diff --git a/tests/009 b/tests/009
index 5aa821e..e0f2add 100755
--- a/tests/009
+++ b/tests/009
@@ -15,7 +15,7 @@ _cleanup
 
 # start three sheep daemons
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
@@ -25,13 +25,13 @@ $COLLIE cluster format -c 2
 $COLLIE vdi create test 80M -P
 
 # stop the 3rd node
-pkill -f "$SHEEP $STORE/2"
+_kill_sheep 2
 
 # write data to the vdi
 cat /dev/urandom | $COLLIE vdi write test
 
 # restart the 3rd node
-$SHEEP $STORE/2 -z 2 -p 7002 -c $DRIVER
+_start_sheep 2
 
 # wait for object recovery to finish
 sleep 10
diff --git a/tests/010 b/tests/010
index 093ac0c..7496e2d 100755
--- a/tests/010
+++ b/tests/010
@@ -13,8 +13,8 @@ status=1        # failure is the default!
 
 _cleanup
 
-$SHEEP $STORE/0 -z 0 -p 7000 -c $DRIVER
-$SHEEP $STORE/1 -z 1 -p 7001 -c $DRIVER
+_start_sheep 0
+_start_sheep 1
 
 sleep 2
 
@@ -28,7 +28,7 @@ for i in `seq 0 19`; do
     $COLLIE vdi write test $((i * 4 * 1024 * 1024)) 512 < /dev/zero
 done
 
-$SHEEP $STORE/2 -z 2 -p 7002 -c $DRIVER
+_start_sheep 2
 
 # overwrite the objects
 for i in `seq 0 19`; do
diff --git a/tests/011 b/tests/011
index 4059624..a4950a7 100755
--- a/tests/011
+++ b/tests/011
@@ -33,7 +33,7 @@ for i in 0 1 2; do
     mkfs.xfs -f $STORE/$i.img > $seq.full
     mkdir $STORE/$i
     mount -o loop $STORE/$i.img $STORE/$i
-    $SHEEP $STORE/$i/ -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
diff --git a/tests/012 b/tests/012
index f558241..48be894 100755
--- a/tests/012
+++ b/tests/012
@@ -14,11 +14,11 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i/ -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 # add gateway node
-$SHEEP $STORE/4/ -z 4 -p 7004 -c $DRIVER -g
+_start_sheep 4 "-g"
 
 sleep 1
 
diff --git a/tests/013 b/tests/013
index b55ccae..d98c158 100755
--- a/tests/013
+++ b/tests/013
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -p 700$i -z $i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
diff --git a/tests/014 b/tests/014
index 03b4e6d..05d64fa 100755
--- a/tests/014
+++ b/tests/014
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
diff --git a/tests/015 b/tests/015
index 5ef362a..3fdebb2 100755
--- a/tests/015
+++ b/tests/015
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 2; do
-    $SHEEP $STORE/$i -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
diff --git a/tests/016 b/tests/016
index df773fe..72678aa 100755
--- a/tests/016
+++ b/tests/016
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -s 4096 -p 700$i -z $i -c $DRIVER
+    _start_sheep $i "-s 4096"
 done
 
 sleep 1;
diff --git a/tests/017 b/tests/017
index 73bb07a..4d111c1 100755
--- a/tests/017
+++ b/tests/017
@@ -14,7 +14,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in 0 1 2; do
-    $SHEEP $STORE/$i -p 700$i -z $i -c $DRIVER
+    _start_sheep $i
 done
 
 sleep 1
diff --git a/tests/018 b/tests/018
index 00d6ee5..238f892 100755
--- a/tests/018
+++ b/tests/018
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 2`; do
-    $SHEEP $STORE/$i -w 100,writeback -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-w 100,writeback"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/019 b/tests/019
index e6556ec..e220400 100755
--- a/tests/019
+++ b/tests/019
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 2`; do
-    $SHEEP $STORE/$i -w 100 -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-w 100"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/020 b/tests/020
index 242dab8..64439b8 100755
--- a/tests/020
+++ b/tests/020
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 2`; do
-    $SHEEP $STORE/$i -d -w 20 -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-w 20"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/021 b/tests/021
index 0476b47..f7c86c3 100755
--- a/tests/021
+++ b/tests/021
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 2`; do
-    $SHEEP $STORE/$i -d -g -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-g"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/022 b/tests/022
index 33d0707..d7b4bfe 100755
--- a/tests/022
+++ b/tests/022
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 2`; do
-    $SHEEP $STORE/$i -d -g -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-g"
 done
 
 _wait_for_sheep "3"
diff --git a/tests/023 b/tests/023
index d9a2200..cd4c889 100755
--- a/tests/023
+++ b/tests/023
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 0`; do
-    $SHEEP $STORE/$i -d -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 _wait_for_sheep "1"
@@ -24,7 +24,7 @@ _wait_for_sheep "1"
 $COLLIE cluster format -c 1
 
 for i in `seq 1 9`; do
-    $SHEEP $STORE/$i -d -g -z $i -p 700$i -c $DRIVER
+    _start_sheep $i "-g"
 done
 
 _wait_for_sheep "10"
diff --git a/tests/024 b/tests/024
index c8b7dd6..6738b4b 100755
--- a/tests/024
+++ b/tests/024
@@ -20,7 +20,7 @@ VDI_SIZE="300M"
 
 echo "starting first sheep"
 for i in `seq 0 0`; do
-    $SHEEP $STORE/$i -d -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 _wait_for_sheep "1"
 
@@ -38,7 +38,7 @@ qemu-io -c "read 0 1m" sheepdog:${VDI_NAME} | _filter_qemu_io
 
 echo "starting second sheep"
 for i in `seq 1 1`; do
-    $SHEEP $STORE/$i -d -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 _wait_for_sheep "2"
 
diff --git a/tests/026 b/tests/026
index 2392eda..5409826 100755
--- a/tests/026
+++ b/tests/026
@@ -16,7 +16,7 @@ status=1        # failure is the default!
 _cleanup
 
 for i in `seq 0 7`; do
-    $SHEEP $STORE/$i -d -z $i -p 700$i -c $DRIVER
+    _start_sheep $i
 done
 
 _wait_for_sheep "8"
@@ -32,11 +32,9 @@ done
 
 # kill nodes and join them back
 sleep 1
-for i in `seq 1 5`; do pkill -f "sheep $STORE/$i";done
+for i in `seq 1 5`; do _kill_sheep $i;done
 sleep 10
-for i in `seq 1 5`; do
-    $SHEEP $STORE/$i -d -w 20 -z $i -p 700$i -c $DRIVER
-done
+for i in `seq 1 5`; do _start_sheep $i;done
 
 _wait_for_collie
 
diff --git a/tests/common.rc b/tests/common.rc
index b1546b2..64182c6 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -159,5 +159,15 @@ _wait_for_sheep()
     done
 }
 
+_start_sheep()
+{
+    $SHEEP $STORE/$1 -z $1 -p $((7000+$1)) -c $DRIVER -y 127.0.0.1 -d $2
+}
+
+_kill_sheep()
+{
+    pkill -f "$SHEEP $STORE/$1"
+}
+
 # make sure this script returns success
 /bin/true
-- 
1.7.10.2




More information about the sheepdog mailing list