Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / rbd / read-flags.sh
1 #!/bin/bash -ex
2
3 # create a snapshot, then export it and check that setting read flags works
4 # by looking at --debug-ms output
5
6 function clean_up {
7     rm -f test.log || true
8     rbd snap remove test@snap || true
9     rbd rm test || true
10 }
11
12 function test_read_flags {
13     local IMAGE=$1
14     local SET_BALANCED=$2
15     local SET_LOCALIZED=$3
16     local EXPECT_BALANCED=$4
17     local EXPECT_LOCALIZED=$5
18
19     local EXTRA_ARGS="--log-file test.log --debug-ms 1 --no-log-to-stderr"
20     if [ "$SET_BALANCED" = 'y' ]; then
21         EXTRA_ARGS="$EXTRA_ARGS --rbd-balance-snap-reads"
22     elif [ "$SET_LOCALIZED" = 'y' ]; then
23         EXTRA_ARGS="$EXTRA_ARGS --rbd-localize-snap-reads"
24     fi
25
26     rbd export $IMAGE - $EXTRA_ARGS > /dev/null
27     if [ "$EXPECT_BALANCED" = 'y' ]; then
28         grep -q balance_reads test.log
29     else
30         grep -L balance_reads test.log | grep -q test.log
31     fi
32     if [ "$EXPECT_LOCALIZED" = 'y' ]; then
33         grep -q localize_reads test.log
34     else
35         grep -L localize_reads test.log | grep -q test.log
36     fi
37     rm -f test.log
38
39 }
40
41 clean_up
42
43 trap clean_up INT TERM EXIT
44
45 rbd create --image-feature layering -s 10 test
46 rbd snap create test@snap
47
48 # export from non snapshot with or without settings should not have flags
49 test_read_flags test n n n n
50 test_read_flags test y y n n
51
52 # export from snapshot should have read flags in log if they are set
53 test_read_flags test@snap n n n n
54 test_read_flags test@snap y n y n
55 test_read_flags test@snap n y n y
56
57 # balanced_reads happens to take priority over localize_reads
58 test_read_flags test@snap y y y n
59
60 echo OK