Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: librbd: admin socket commands to flush and invalidate cache
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
- Loading branch information
Mykola Golub
committed
Nov 3, 2015
1 parent
7c5905d
commit 60e219f
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/bin/bash -ex | ||
|
||
TMPDIR=/tmp/rbd_test_admin_socket$$ | ||
mkdir $TMPDIR | ||
trap "rm -fr $TMPDIR" 0 | ||
|
||
. $(dirname $0)/../ceph-helpers.sh | ||
|
||
function expect_false() | ||
{ | ||
set -x | ||
if "$@"; then return 1; else return 0; fi | ||
} | ||
|
||
function rbd_watch_out_file() | ||
{ | ||
echo ${TMPDIR}/rbd_watch_$1.out | ||
} | ||
|
||
function rbd_watch_pid_file() | ||
{ | ||
echo ${TMPDIR}/rbd_watch_$1.pid | ||
} | ||
|
||
function rbd_watch_fifo() | ||
{ | ||
echo ${TMPDIR}/rbd_watch_$1.fifo | ||
} | ||
|
||
function rbd_watch_asok() | ||
{ | ||
echo ${TMPDIR}/rbd_watch_$1.asok | ||
} | ||
|
||
function rbd_watch_start() | ||
{ | ||
local image=$1 | ||
|
||
mkfifo $(rbd_watch_fifo ${image}) | ||
(cat $(rbd_watch_fifo ${image}) | | ||
rbd watch ${image} > $(rbd_watch_out_file ${image}) 2>&1)& | ||
|
||
# find pid of the started rbd watch process | ||
local pid | ||
for i in `seq 3`; do | ||
pid=$(ps auxww | awk "/[r]bd watch ${image}/ {print \$2}") | ||
test -n "${pid}" && break | ||
done | ||
test -n "${pid}" | ||
echo ${pid} > $(rbd_watch_pid_file ${image}) | ||
|
||
# find watcher admin socket | ||
local asok=$(ceph-conf admin_socket | sed -E "s/[0-9]+/${pid}/") | ||
test -n "${asok}" | ||
for i in `seq 10`; do | ||
test -S "${asok}" && break | ||
sleep 1 | ||
done | ||
test -S "${asok}" | ||
ln -s "${asok}" $(rbd_watch_asok ${image}) | ||
|
||
# configure debug level | ||
ceph --admin-daemon "${asok}" config set debug_rbd 20 | ||
|
||
# check that watcher is registered | ||
rbd status ${image} | expect_false grep "Watchers: none" | ||
} | ||
|
||
function rbd_watch_end() | ||
{ | ||
local image=$1 | ||
local regexp=$2 | ||
local timeout=10 | ||
|
||
if [ -n "$3" ]; then | ||
timeout=$3 | ||
fi | ||
|
||
#ceph --admin-daemon $(rbd_watch_asok ${image}) log dump | ||
|
||
if [ -n "${regexp}" ]; then | ||
for i in `seq ${timeout}`; do | ||
sleep 1 | ||
grep -q "${regexp}" $(rbd_watch_out_file ${image}) && break | ||
done | ||
fi | ||
|
||
# send 'enter' to watch to exit | ||
echo > $(rbd_watch_fifo ${image}) | ||
# just in case it is not terminated | ||
kill $(cat $(rbd_watch_pid_file ${image})) || : | ||
|
||
if [ -n "${regexp}" ] && ! grep "${regexp}" $(rbd_watch_out_file ${image}); then | ||
echo "pattern '${regexp}' not found in watch file. Full watch file content:" >&2 | ||
cat $(rbd_watch_out_file ${image}) >&2 | ||
return 1 | ||
fi | ||
|
||
# cleanup | ||
rm -f $(rbd_watch_fifo ${image}) $(rbd_watch_pid_file ${image}) \ | ||
$(rbd_watch_out_file ${image}) $(rbd_watch_asok ${image}) | ||
} | ||
|
||
wait_for_clean | ||
|
||
image=testimg$$ | ||
ceph_admin="ceph --admin-daemon $(rbd_watch_asok ${image})" | ||
|
||
rbd create --size 128 ${image} | ||
|
||
# test with disabled rbd_cache | ||
rbd image-meta set ${image} conf_rbd_cache false | ||
|
||
rbd_watch_start ${image} | ||
${ceph_admin} help | fgrep "rbd cache flush ${image}" | ||
${ceph_admin} help | fgrep "rbd cache invalidate ${image}" | ||
${ceph_admin} rbd cache flush ${image} | | ||
grep 'cache is not enabled' | ||
${ceph_admin} rbd cache invalidate ${image} | | ||
grep 'cache is not enabled' | ||
rbd_watch_end ${image} | ||
|
||
# test with enabled rbd_cache | ||
rbd image-meta set ${image} conf_rbd_cache true | ||
|
||
rbd_watch_start ${image} | ||
${ceph_admin} rbd cache flush ${image} | ||
rbd_watch_end ${image} 'finished flushing cache' | ||
|
||
rbd_watch_start ${image} | ||
${ceph_admin} rbd cache invalidate ${image} | ||
rbd_watch_end ${image} 'finished invalidating cache' | ||
|
||
rbd rm ${image} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters