]> git.proxmox.com Git - ceph.git/blame - ceph/qa/workunits/rbd/test_admin_socket.sh
bump version to 18.2.4-pve3
[ceph.git] / ceph / qa / workunits / rbd / test_admin_socket.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2set -ex
7c673cae
FG
3
4TMPDIR=/tmp/rbd_test_admin_socket$$
5mkdir $TMPDIR
6trap "rm -fr $TMPDIR" 0
7
c07f9fc5 8. $(dirname $0)/../../standalone/ceph-helpers.sh
7c673cae
FG
9
10function expect_false()
11{
12 set -x
13 if "$@"; then return 1; else return 0; fi
14}
15
16function rbd_watch_out_file()
17{
18 echo ${TMPDIR}/rbd_watch_$1.out
19}
20
21function rbd_watch_pid_file()
22{
23 echo ${TMPDIR}/rbd_watch_$1.pid
24}
25
26function rbd_watch_fifo()
27{
28 echo ${TMPDIR}/rbd_watch_$1.fifo
29}
30
31function rbd_watch_asok()
32{
33 echo ${TMPDIR}/rbd_watch_$1.asok
34}
35
36function rbd_get_perfcounter()
37{
38 local image=$1
39 local counter=$2
40 local name
41
42 name=$(ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) \
43 perf schema | $XMLSTARLET el -d3 |
44 grep "/librbd-.*-${image}/${counter}\$")
45 test -n "${name}" || return 1
46
47 ceph --format xml --admin-daemon $(rbd_watch_asok ${image}) perf dump |
48 $XMLSTARLET sel -t -m "${name}" -v .
49}
50
51function rbd_check_perfcounter()
52{
53 local image=$1
54 local counter=$2
55 local expected_val=$3
56 local val=
57
58 val=$(rbd_get_perfcounter ${image} ${counter})
59
60 test "${val}" -eq "${expected_val}"
61}
62
63function rbd_watch_start()
64{
65 local image=$1
d2e6a577 66 local asok=$(rbd_watch_asok ${image})
7c673cae
FG
67
68 mkfifo $(rbd_watch_fifo ${image})
69 (cat $(rbd_watch_fifo ${image}) |
d2e6a577
FG
70 rbd --admin-socket ${asok} watch ${image} \
71 > $(rbd_watch_out_file ${image}) 2>&1)&
7c673cae
FG
72
73 # find pid of the started rbd watch process
74 local pid
75 for i in `seq 10`; do
d2e6a577 76 pid=$(ps auxww | awk "/[r]bd --admin.* watch ${image}/ {print \$2}")
7c673cae
FG
77 test -n "${pid}" && break
78 sleep 0.1
79 done
80 test -n "${pid}"
81 echo ${pid} > $(rbd_watch_pid_file ${image})
82
83 # find watcher admin socket
7c673cae
FG
84 test -n "${asok}"
85 for i in `seq 10`; do
86 test -S "${asok}" && break
87 sleep 0.1
88 done
89 test -S "${asok}"
7c673cae
FG
90
91 # configure debug level
92 ceph --admin-daemon "${asok}" config set debug_rbd 20
93
94 # check that watcher is registered
95 rbd status ${image} | expect_false grep "Watchers: none"
96}
97
98function rbd_watch_end()
99{
100 local image=$1
101 local regexp=$2
102
103 # send 'enter' to watch to exit
104 echo > $(rbd_watch_fifo ${image})
105 # just in case it is not terminated
106 kill $(cat $(rbd_watch_pid_file ${image})) || :
107
108 # output rbd watch out file for easier troubleshooting
109 cat $(rbd_watch_out_file ${image})
110
111 # cleanup
112 rm -f $(rbd_watch_fifo ${image}) $(rbd_watch_pid_file ${image}) \
113 $(rbd_watch_out_file ${image}) $(rbd_watch_asok ${image})
114}
115
7c673cae
FG
116pool="rbd"
117image=testimg$$
118ceph_admin="ceph --admin-daemon $(rbd_watch_asok ${image})"
119
120rbd create --size 128 ${pool}/${image}
121
122# check rbd cache commands are present in help output
123rbd_cache_flush="rbd cache flush ${pool}/${image}"
124rbd_cache_invalidate="rbd cache invalidate ${pool}/${image}"
125
126rbd_watch_start ${image}
127${ceph_admin} help | fgrep "${rbd_cache_flush}"
128${ceph_admin} help | fgrep "${rbd_cache_invalidate}"
129rbd_watch_end ${image}
130
131# test rbd cache commands with disabled and enabled cache
132for conf_rbd_cache in false true; do
133
134 rbd image-meta set ${image} conf_rbd_cache ${conf_rbd_cache}
135
136 rbd_watch_start ${image}
137
138 rbd_check_perfcounter ${image} flush 0
139 ${ceph_admin} ${rbd_cache_flush}
140 # 'flush' counter should increase regardless if cache is enabled
141 rbd_check_perfcounter ${image} flush 1
142
143 rbd_check_perfcounter ${image} invalidate_cache 0
144 ${ceph_admin} ${rbd_cache_invalidate}
145 # 'invalidate_cache' counter should increase regardless if cache is enabled
146 rbd_check_perfcounter ${image} invalidate_cache 1
147
148 rbd_watch_end ${image}
149done
150
151rbd rm ${image}