Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / rbd / test_lock_fence.sh
1 #!/bin/bash  -x
2 # can't use -e because of background process
3
4 IMAGE=rbdrw-image
5 LOCKID=rbdrw
6 RELPATH=$(dirname $0)/../../../src/test/librbd
7 RBDRW=$RELPATH/rbdrw.py
8
9 rbd create $IMAGE --size 10 --image-format 2 --image-shared || exit 1
10
11 # rbdrw loops doing I/O to $IMAGE after locking with lockid $LOCKID
12 python $RBDRW $IMAGE $LOCKID &
13 iochild=$!
14
15 # give client time to lock and start reading/writing
16 LOCKS='{}'
17 while [ "$LOCKS" == "{}" ]
18 do
19     LOCKS=$(rbd lock list $IMAGE --format json)
20     sleep 1
21 done
22
23 clientaddr=$(rbd lock list $IMAGE | tail -1 | awk '{print $NF;}')
24 clientid=$(rbd lock list $IMAGE | tail -1 | awk '{print $1;}')
25 echo "clientaddr: $clientaddr"
26 echo "clientid: $clientid"
27
28 ceph osd blacklist add $clientaddr || exit 1
29
30 wait $iochild
31 rbdrw_exitcode=$?
32 if [ $rbdrw_exitcode != 108 ]
33 then
34         echo "wrong exitcode from rbdrw: $rbdrw_exitcode"
35         exit 1
36 else
37         echo "rbdrw stopped with ESHUTDOWN"
38 fi
39
40 set -e
41 ceph osd blacklist rm $clientaddr
42 rbd lock remove $IMAGE $LOCKID "$clientid"
43 # rbdrw will have exited with an existing watch, so, until #3527 is fixed,
44 # hang out until the watch expires
45 sleep 30
46 rbd rm $IMAGE
47 echo OK