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