3 # rbd_mirror_helpers.sh - shared rbd-mirror daemon helper functions
5 # The scripts starts two ("local" and "remote") clusters using mstart.sh script,
6 # creates a temporary directory, used for cluster configs, daemon logs, admin
7 # socket, temporary files, and launches rbd-mirror daemon.
9 # There are several env variables useful when troubleshooting a test failure:
11 # RBD_MIRROR_NOCLEANUP - if not empty, don't run the cleanup (stop processes,
12 # destroy the clusters and remove the temp directory)
13 # on exit, so it is possible to check the test state
15 # RBD_MIRROR_TEMDIR - use this path when creating the temporary directory
16 # (should not exist) instead of running mktemp(1).
17 # RBD_MIRROR_ARGS - use this to pass additional arguments to started
19 # RBD_MIRROR_VARGS - use this to pass additional arguments to vstart.sh
20 # when starting clusters.
21 # RBD_MIRROR_INSTANCES - number of daemons to start per cluster
22 # RBD_MIRROR_CONFIG_KEY - if not empty, use config-key for remote cluster
24 # The cleanup can be done as a separate step, running the script with
25 # `cleanup ${RBD_MIRROR_TEMDIR}' arguments.
27 # Note, as other workunits tests, rbd_mirror_journal.sh expects to find ceph binaries
30 # Thus a typical troubleshooting session:
32 # From Ceph src dir (CEPH_SRC_PATH), start the test in NOCLEANUP mode and with
33 # TEMPDIR pointing to a known location:
36 # PATH=$CEPH_SRC_PATH:$PATH
37 # RBD_MIRROR_NOCLEANUP=1 RBD_MIRROR_TEMDIR=/tmp/tmp.rbd_mirror \
38 # ../qa/workunits/rbd/rbd_mirror_journal.sh
40 # After the test failure cd to TEMPDIR and check the current state:
42 # cd /tmp/tmp.rbd_mirror
44 # less rbd-mirror.cluster1_daemon.$pid.log
45 # ceph --cluster cluster1 -s
46 # ceph --cluster cluster1 -s
47 # rbd --cluster cluster2 -p mirror ls
48 # rbd --cluster cluster2 -p mirror journal status --image test
49 # ceph --admin-daemon rbd-mirror.cluster1_daemon.cluster1.$pid.asok help
52 # Also you can execute commands (functions) from the script:
55 # export RBD_MIRROR_TEMDIR=/tmp/tmp.rbd_mirror
56 # ../qa/workunits/rbd/rbd_mirror_journal.sh status
57 # ../qa/workunits/rbd/rbd_mirror_journal.sh stop_mirror cluster1
58 # ../qa/workunits/rbd/rbd_mirror_journal.sh start_mirror cluster2
59 # ../qa/workunits/rbd/rbd_mirror_journal.sh flush cluster2
62 # Eventually, run the cleanup:
65 # RBD_MIRROR_TEMDIR=/tmp/tmp.rbd_mirror \
66 # ../qa/workunits/rbd/rbd_mirror_journal.sh cleanup
69 if type xmlstarlet
> /dev
/null
2>&1; then
71 elif type xml
> /dev
/null
2>&1; then
74 echo "Missing xmlstarlet binary!"
78 RBD_MIRROR_INSTANCES
=${RBD_MIRROR_INSTANCES:-2}
84 PARENT_POOL
=mirror_parent
88 CEPH_ID
=${CEPH_ID:-mirror}
89 RBD_IMAGE_FEATURES
=${RBD_IMAGE_FEATURES:-layering,exclusive-lock,journaling}
90 MIRROR_USER_ID_PREFIX
=${MIRROR_USER_ID_PREFIX:-${CEPH_ID}.}
91 MIRROR_POOL_MODE
=${MIRROR_POOL_MODE:-pool}
92 MIRROR_IMAGE_MODE
=${MIRROR_IMAGE_MODE:-journal}
94 export CEPH_ARGS
="--id ${CEPH_ID}"
96 LAST_MIRROR_INSTANCE
=$
((${RBD_MIRROR_INSTANCES} - 1))
98 CEPH_ROOT
=$
(readlink
-f $
(dirname $0)/..
/..
/..
/src
)
101 if [ -e CMakeCache.txt
]; then
102 CEPH_SRC
=${CEPH_ROOT}
106 # needed for ceph CLI under cmake
107 export LD_LIBRARY_PATH
=${CEPH_ROOT}/lib
:${LD_LIBRARY_PATH}
108 export PYTHONPATH
=${PYTHONPATH}:${CEPH_SRC}/pybind:${CEPH_ROOT}/lib
/cython_modules
/lib
.3
111 # These vars facilitate running this script in an environment with
112 # ceph installed from packages, like teuthology. These are not defined
115 # RBD_MIRROR_USE_EXISTING_CLUSTER - if set, do not start and stop ceph clusters
116 # RBD_MIRROR_USE_RBD_MIRROR - if set, use an existing instance of rbd-mirror
117 # running as ceph client $CEPH_ID. If empty,
118 # this script will start and stop rbd-mirror
124 # Parse a value in format cluster[:instance] and set cluster and instance vars.
125 set_cluster_instance
()
128 local cluster_var_name
=$2
129 local instance_var_name
=$3
134 if [ "${instance}" = "${val}" ]; then
135 # instance was not specified, use default
139 eval ${cluster_var_name}=${cluster}
140 eval ${instance_var_name}=${instance}
145 local local_cluster
=$1
149 set_cluster_instance
"${local_cluster}" local_cluster instance
151 echo $
(ceph-conf
--cluster $local_cluster --name "client.${MIRROR_USER_ID_PREFIX}${instance}" 'admin socket')
159 set_cluster_instance
"${cluster}" cluster instance
161 echo $
(ceph-conf
--cluster $cluster --name "client.${MIRROR_USER_ID_PREFIX}${instance}" 'pid file')
166 echo $
(date '+%F %T') $@ |
tee -a "${TEMPDIR}/rbd-mirror.test.log" >&2
171 local expected
="$1" ; shift
172 local out
=${TEMPDIR}/expect_failure.out
174 if "$@" > ${out} 2>&1 ; then
179 if [ -z "${expected}" ]; then
183 if ! grep -q "${expected}" ${out} ; then
193 echo "$@" |
sed -e 's|[/ ]|_|g'
200 CEPH_ARGS
='' ceph
--cluster "${cluster}" \
201 auth get-or-create client.
${CEPH_ID} \
202 mon
'profile rbd' osd
'profile rbd' mgr
'profile rbd' >> \
203 ${CEPH_ROOT}/run
/${cluster}/keyring
204 for instance
in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
205 CEPH_ARGS
='' ceph
--cluster "${cluster}" \
206 auth get-or-create client.
${MIRROR_USER_ID_PREFIX}${instance} \
207 mon
'profile rbd-mirror' osd
'profile rbd' mgr
'profile rbd' >> \
208 ${CEPH_ROOT}/run
/${cluster}/keyring
216 CEPH_ARGS
='' ${CEPH_SRC}/mstart.sh ${cluster} -n ${RBD_MIRROR_VARGS}
219 rm -f ${TEMPDIR}/${cluster}.conf
220 ln -s $
(readlink
-f run
/${cluster}/ceph.conf
) \
221 ${TEMPDIR}/${cluster}.conf
224 create_users
"${cluster}"
226 for instance
in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
227 cat<<EOF >> ${TEMPDIR}/${cluster}.conf
228 [client.${MIRROR_USER_ID_PREFIX}${instance}]
229 admin socket = ${TEMPDIR}/rbd-mirror.\$cluster-\$name.asok
230 pid file = ${TEMPDIR}/rbd-mirror.\$cluster-\$name.pid
231 log file = ${TEMPDIR}/rbd-mirror.${cluster}_daemon.${instance}.log
238 local cluster
=$1 ; shift
239 local pool
=$1 ; shift
240 local client_cluster
=$1 ; shift
241 local remote_cluster
="${client_cluster##*@}"
245 uuid_var_name
=$1 ; shift
251 for s
in 1 2 4 8 16 32; do
253 peer_uuid
=$
(rbd
--cluster ${cluster} mirror pool peer add \
254 ${pool} ${client_cluster} $@
)
258 if [ $error_code -eq 17 ]; then
259 # raced with a remote heartbeat ping -- remove and retry
261 peer_uuid
=$
(rbd mirror pool info
--cluster ${cluster} --pool ${pool} --format xml | \
262 xmlstarlet sel
-t -v "//peers/peer[site_name='${remote_cluster}']/uuid")
264 CEPH_ARGS
='' rbd
--cluster ${cluster} --pool ${pool} mirror pool peer remove ${peer_uuid}
266 test $error_code -eq 0
267 if [ -n "$uuid_var_name" ]; then
268 eval ${uuid_var_name}=${peer_uuid}
280 local remote_cluster
=$2
286 CEPH_ARGS
='' ceph
--cluster ${cluster} osd pool create
${POOL} 64 64
287 CEPH_ARGS
='' ceph
--cluster ${cluster} osd pool create
${PARENT_POOL} 64 64
289 CEPH_ARGS
='' rbd
--cluster ${cluster} pool init
${POOL}
290 CEPH_ARGS
='' rbd
--cluster ${cluster} pool init
${PARENT_POOL}
292 if [ -n "${RBD_MIRROR_CONFIG_KEY}" ]; then
293 PEER_CLUSTER_SUFFIX
=-DNE
296 CEPH_ARGS
='' rbd
--cluster ${cluster} mirror pool
enable \
297 --site-name ${cluster}${PEER_CLUSTER_SUFFIX} ${POOL} ${MIRROR_POOL_MODE}
298 rbd
--cluster ${cluster} mirror pool
enable ${PARENT_POOL} image
300 rbd
--cluster ${cluster} namespace create ${POOL}/${NS1}
301 rbd
--cluster ${cluster} namespace create ${POOL}/${NS2}
303 rbd
--cluster ${cluster} mirror pool enable ${POOL}/${NS1} ${MIRROR_POOL_MODE}
304 rbd
--cluster ${cluster} mirror pool enable ${POOL}/${NS2} image
306 if [ -z ${RBD_MIRROR_MANUAL_PEERS} ]; then
307 if [ -z ${RBD_MIRROR_CONFIG_KEY} ]; then
308 peer_add
${cluster} ${POOL} ${remote_cluster}
309 peer_add
${cluster} ${PARENT_POOL} ${remote_cluster}
311 mon_map_file
=${TEMPDIR}/${remote_cluster}.monmap
312 CEPH_ARGS
='' ceph
--cluster ${remote_cluster} mon getmap
> ${mon_map_file}
313 mon_addr
=$
(monmaptool
--print ${mon_map_file} |
grep -E 'mon\.' |
314 head -n 1 |
sed -E 's/^[0-9]+: ([^ ]+).+$/\1/' |
sed -E 's/\/[0-9]+//g')
316 admin_key_file
=${TEMPDIR}/${remote_cluster}.client.${CEPH_ID}.key
317 CEPH_ARGS
='' ceph
--cluster ${remote_cluster} auth get-key client.${CEPH_ID} > ${admin_key_file}
319 CEPH_ARGS
='' peer_add
${cluster} ${POOL} \
320 client.
${CEPH_ID}@${remote_cluster}${PEER_CLUSTER_SUFFIX} '' \
321 --remote-mon-host "${mon_addr}" --remote-key-file ${admin_key_file}
323 peer_add
${cluster} ${PARENT_POOL} client.${CEPH_ID}@${remote_cluster}${PEER_CLUSTER_SUFFIX} uuid
324 CEPH_ARGS
='' rbd
--cluster ${cluster} mirror pool peer set ${PARENT_POOL} ${uuid} mon-host ${mon_addr}
325 CEPH_ARGS
='' rbd
--cluster ${cluster} mirror pool peer set ${PARENT_POOL} ${uuid} key-file ${admin_key_file}
332 if [ -n "${RBD_MIRROR_TEMDIR}" ]; then
333 test -d "${RBD_MIRROR_TEMDIR}" ||
334 mkdir
"${RBD_MIRROR_TEMDIR}"
335 TEMPDIR
="${RBD_MIRROR_TEMDIR}"
345 trap 'cleanup $?' INT TERM EXIT
348 if [ -z "${RBD_MIRROR_USE_EXISTING_CLUSTER}" ]; then
349 setup_cluster
"${CLUSTER1}"
350 setup_cluster
"${CLUSTER2}"
353 setup_pools
"${CLUSTER1}" "${CLUSTER2}"
354 setup_pools
"${CLUSTER2}" "${CLUSTER1}"
356 if [ -n "${RBD_MIRROR_MIN_COMPAT_CLIENT}" ]; then
357 CEPH_ARGS
='' ceph
--cluster ${CLUSTER1} osd \
358 set-require-min-compat-client
${RBD_MIRROR_MIN_COMPAT_CLIENT}
359 CEPH_ARGS
='' ceph
--cluster ${CLUSTER2} osd \
360 set-require-min-compat-client
${RBD_MIRROR_MIN_COMPAT_CLIENT}
370 if [ "${error_code}" -ne 0 ]; then
374 if [ -z "${RBD_MIRROR_NOCLEANUP}" ]; then
375 local cluster instance
377 CEPH_ARGS
='' ceph
--cluster ${CLUSTER1} osd pool rm ${POOL} ${POOL} --yes-i-really-really-mean-it
378 CEPH_ARGS
='' ceph
--cluster ${CLUSTER2} osd pool rm ${POOL} ${POOL} --yes-i-really-really-mean-it
379 CEPH_ARGS
='' ceph
--cluster ${CLUSTER1} osd pool rm ${PARENT_POOL} ${PARENT_POOL} --yes-i-really-really-mean-it
380 CEPH_ARGS
='' ceph
--cluster ${CLUSTER2} osd pool rm ${PARENT_POOL} ${PARENT_POOL} --yes-i-really-really-mean-it
382 for cluster
in "${CLUSTER1}" "${CLUSTER2}"; do
383 stop_mirrors
"${cluster}"
386 if [ -z "${RBD_MIRROR_USE_EXISTING_CLUSTER}" ]; then
388 CEPH_ARGS
='' ${CEPH_SRC}/mstop.sh
${CLUSTER1}
389 CEPH_ARGS
='' ${CEPH_SRC}/mstop.sh
${CLUSTER2}
391 test "${RBD_MIRROR_TEMDIR}" = "${TEMPDIR}" || rm -Rf ${TEMPDIR}
394 if [ "${error_code}" -eq 0 ]; then
408 set_cluster_instance "${cluster}" cluster instance
410 test -n "${RBD_MIRROR_USE_RBD_MIRROR}" && return
413 --cluster ${cluster} \
414 --id ${MIRROR_USER_ID_PREFIX}${instance} \
415 --rbd-mirror-delete-retry-interval=5 \
416 --rbd-mirror-image-state-check-interval=5 \
417 --rbd-mirror-journal-poll-age=1 \
418 --rbd-mirror-pool-replayers-refresh-interval=5 \
419 --debug-rbd=30 --debug-journaler=30 \
420 --debug-rbd_mirror=30 \
429 for instance in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
430 start_mirror "${cluster}:${instance}"
439 test -n "${RBD_MIRROR_USE_RBD_MIRROR}" && return
442 pid=$(cat $(daemon_pid_file "${cluster}") 2>/dev/null) || :
446 for s in 1 2 4 8 16 32; do
448 ps auxww | awk -v pid=${pid} '$2 == pid {print; exit 1}' && break
450 ps auxww | awk -v pid=${pid} '$2 == pid {print; exit 1}'
452 rm -f $(daemon_asok_file "${cluster}" "${CLUSTER1}")
453 rm -f $(daemon_asok_file "${cluster}" "${CLUSTER2}")
454 rm -f $(daemon_pid_file "${cluster}")
462 for instance in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
463 stop_mirror "${cluster}:${instance}" "${sig}"
469 local cluster=$1 ; shift
472 set_cluster_instance "${cluster}" cluster instance
474 local asok_file=$(daemon_asok_file "${cluster}:${instance}" "${cluster}")
475 test -S "${asok_file}"
477 ceph --admin-daemon ${asok_file} $@
482 local cluster_instance=$1 ; shift
483 local cluster="${cluster_instance%:*}"
484 local instance="${cluster_instance##*:}"
487 for s in 0 1 2 4 8 8 8 8 8 8 8 8 16 16; do
489 if [ "${instance}" != "${cluster_instance}" ]; then
490 admin_daemon "${cluster}:${instance}" $@ && return 0
492 for loop_instance in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
493 admin_daemon "${cluster}:${loop_instance}" $@ && return 0
502 local cluster=$1 ; shift
504 for instance in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
505 admin_daemon "${cluster}:${instance}" $@
511 local cluster daemon image_pool image_ns image
513 for cluster in ${CLUSTER1} ${CLUSTER2}
515 echo "${cluster} status
"
516 CEPH_ARGS='' ceph --cluster ${cluster} -s
517 CEPH_ARGS='' ceph --cluster ${cluster} service dump
518 CEPH_ARGS='' ceph --cluster ${cluster} service status
521 for image_pool in ${POOL} ${PARENT_POOL}
523 for image_ns in "" "${NS1}" "${NS2}"
525 echo "${cluster} ${image_pool} ${image_ns} images
"
526 rbd --cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" ls -l
529 echo "${cluster} ${image_pool}${image_ns} mirror pool info"
530 rbd
--cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" mirror pool info
533 echo "${cluster} ${image_pool}${image_ns} mirror pool status
"
534 CEPH_ARGS='' rbd --cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" mirror pool status
--verbose
537 for image
in `rbd --cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" ls 2>/dev/null`
539 echo "image ${image} info"
540 rbd
--cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" info ${image}
542 echo "image ${image} journal status"
543 rbd
--cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" journal status --image ${image}
547 echo "${cluster} ${image_pool} ${image_ns} rbd_mirroring omap vals"
548 rados
--cluster ${cluster} -p ${image_pool} --namespace "${image_ns}" listomapvals rbd_mirroring
556 for cluster in "${CLUSTER1}" "${CLUSTER2}"
558 for instance in `seq 0 ${LAST_MIRROR_INSTANCE}`; do
559 local pid_file=$(daemon_pid_file ${cluster}:${instance})
560 if [ ! -e ${pid_file} ]
562 echo "${cluster} rbd-mirror not running or unknown
" \
563 "(${pid_file} not exist
)"
568 pid=$(cat ${pid_file} 2>/dev/null) || :
571 echo "${cluster} rbd-mirror not running or unknown
" \
572 "(can
't find pid using ${pid_file})"
577 echo "${daemon} rbd-mirror process in ps output:"
579 awk -v pid=${pid} 'NR
== 1 {print
} $2 == pid
{print
; exit 1}'
582 echo "${cluster} rbd-mirror not running" \
583 "(can't
find pid
$pid in ps output
)"
589 local asok_file=$(daemon_asok_file ${cluster}:${instance} ${cluster})
590 if [ ! -S "${asok_file}" ]
592 echo "${cluster} rbd-mirror asok is unknown
(${asok_file} not exits
)"
597 echo "${cluster} rbd-mirror status
"
598 ceph --admin-daemon ${asok_file} rbd mirror status
611 local cmd="rbd mirror flush
"
615 cmd="${cmd} ${pool}/${image}"
618 admin_daemons "${cluster}" ${cmd}
621 test_image_replay_state()
628 local current_state=stopped
630 status_result=$(admin_daemons "${cluster}" rbd mirror status ${pool}/${image} |
grep -i 'state') ||
return 1
631 echo "${status_result}" |
grep -i 'Replaying' && current_state
=started
632 test "${test_state}" = "${current_state}"
635 wait_for_image_replay_state
()
643 # TODO: add a way to force rbd-mirror to update replayers
644 for s
in 1 2 4 8 8 8 8 8 8 8 8 16 16; do
646 test_image_replay_state
"${cluster}" "${pool}" "${image}" "${state}" && return 0
651 wait_for_image_replay_started
()
657 wait_for_image_replay_state
"${cluster}" "${pool}" "${image}" started
660 wait_for_image_replay_stopped
()
666 wait_for_image_replay_state
"${cluster}" "${pool}" "${image}" stopped
669 get_journal_position
()
676 # Parse line like below, looking for the first position
677 # [id=, commit_position=[positions=[[object_number=1, tag_tid=3, entry_tid=9], [object_number=0, tag_tid=3, entry_tid=8], [object_number=3, tag_tid=3, entry_tid=7], [object_number=2, tag_tid=3, entry_tid=6]]]]
679 local status_log
=${TEMPDIR}/$(mkfname ${CLUSTER2}-${pool}-${image}.status
)
680 rbd
--cluster ${cluster} journal status --image ${pool}/${image} |
681 tee ${status_log} >&2
682 sed -nEe 's/^.*\[id='"${id_regexp}"',.*positions=\[\[([^]]*)\],.*state=connected.*$/\1/p' \
686 get_master_journal_position
()
692 get_journal_position
"${cluster}" "${pool}" "${image}" ''
695 get_mirror_journal_position
()
701 get_journal_position
"${cluster}" "${pool}" "${image}" '..*'
704 wait_for_journal_replay_complete
()
706 local local_cluster
=$1
710 local s master_pos mirror_pos last_mirror_pos
711 local master_tag master_entry mirror_tag mirror_entry
714 for s
in 0.2 0.4 0.8 1.6 2 2 4 4 8 8 16 16 32 32; do
716 flush
"${local_cluster}" "${pool}" "${image}"
717 master_pos
=$
(get_master_journal_position
"${cluster}" "${pool}" "${image}")
718 mirror_pos
=$
(get_mirror_journal_position
"${cluster}" "${pool}" "${image}")
719 test -n "${master_pos}" -a "${master_pos}" = "${mirror_pos}" && return 0
720 test "${mirror_pos}" != "${last_mirror_pos}" && break
723 test "${mirror_pos}" = "${last_mirror_pos}" && return 1
724 last_mirror_pos
="${mirror_pos}"
726 # handle the case where the mirror is ahead of the master
727 master_tag
=$
(echo "${master_pos}" |
grep -Eo "tag_tid=[0-9]*" | cut
-d'=' -f 2)
728 mirror_tag
=$
(echo "${mirror_pos}" |
grep -Eo "tag_tid=[0-9]*" | cut
-d'=' -f 2)
729 master_entry
=$
(echo "${master_pos}" |
grep -Eo "entry_tid=[0-9]*" | cut
-d'=' -f 2)
730 mirror_entry
=$
(echo "${mirror_pos}" |
grep -Eo "entry_tid=[0-9]*" | cut
-d'=' -f 2)
731 test "${master_tag}" = "${mirror_tag}" -a ${master_entry} -le ${mirror_entry} && return 0
736 mirror_image_snapshot()
742 rbd --cluster "${cluster}" mirror image snapshot "${pool}/${image}"
745 get_newest_mirror_snapshot()
752 rbd --cluster "${cluster}" snap list --all "${pool}/${image}" --format xml | \
753 xmlstarlet sel -t -c "//snapshots
/snapshot
[namespace
/complete
='true' and position
()=last
()]" > \
757 wait_for_snapshot_sync_complete()
759 local local_cluster=$1
764 local status_log=${TEMPDIR}/$(mkfname ${cluster}-${pool}-${image}.status)
765 local local_status_log=${TEMPDIR}/$(mkfname ${local_cluster}-${pool}-${image}.status)
767 mirror_image_snapshot "${cluster}" "${pool}" "${image}"
768 get_newest_mirror_snapshot "${cluster}" "${pool}" "${image}" "${status_log}"
769 local snapshot_id=$(xmlstarlet sel -t -v "//snapshot
/id
" < ${status_log})
772 for s in 0.2 0.4 0.8 1.6 2 2 4 4 8 8 16 16 32 32; do
775 get_newest_mirror_snapshot "${local_cluster}" "${pool}" "${image}" "${local_status_log}"
776 local primary_snapshot_id=$(xmlstarlet sel -t -v "//snapshot
/namespace
/primary_snap_id
" < ${local_status_log})
778 test "${snapshot_id}" = "${primary_snapshot_id}" && return 0
786 wait_for_replay_complete()
788 local local_cluster=$1
793 if [ "${MIRROR_IMAGE_MODE}" = "journal
" ]; then
794 wait_for_journal_replay_complete ${local_cluster} ${cluster} ${pool} ${image}
795 elif [ "${MIRROR_IMAGE_MODE}" = "snapshot
" ]; then
796 wait_for_snapshot_sync_complete ${local_cluster} ${cluster} ${pool} ${image}
803 test_status_in_pool_dir()
808 local state_pattern="$4"
809 local description_pattern="$5"
810 local service_pattern="$6"
812 local status_log=${TEMPDIR}/$(mkfname ${cluster}-${pool}-${image}.mirror_status)
813 CEPH_ARGS='' rbd --cluster ${cluster} mirror image status ${pool}/${image} |
814 tee ${status_log} >&2
815 grep "^ state
: .
*${state_pattern}" ${status_log} || return 1
816 grep "^ description
: .
*${description_pattern}" ${status_log} || return 1
818 if [ -n "${service_pattern}" ]; then
819 grep "service
: *${service_pattern}" ${status_log} || return 1
820 elif echo ${state_pattern} | grep '^up+'; then
821 grep "service
: *${MIRROR_USER_ID_PREFIX}.
* on
" ${status_log} || return 1
823 grep "service
: " ${status_log} && return 1
826 # recheck using `mirror pool status` command to stress test it.
828 local last_update="$
(sed -nEe 's/^ last_update: *(.*) *$/\1/p' ${status_log})"
829 test_mirror_pool_status_verbose \
830 ${cluster} ${pool} ${image} "${state_pattern}" "${last_update}" &&
833 echo "'mirror pool status' test failed" >&2
837 test_mirror_pool_status_verbose
()
842 local state_pattern
="$4"
843 local prev_last_update
="$5"
845 local status_log
=${TEMPDIR}/$(mkfname ${cluster}-${pool}.mirror_status
)
847 rbd
--cluster ${cluster} mirror pool status
${pool} --verbose --format xml \
850 local last_update state
851 last_update
=$
($XMLSTARLET sel
-t -v \
852 "//images/image[name='${image}']/last_update" < ${status_log})
853 state
=$
($XMLSTARLET sel
-t -v \
854 "//images/image[name='${image}']/state" < ${status_log})
856 echo "${state}" |
grep "${state_pattern}" ||
857 test "${last_update}" '>' "${prev_last_update}"
860 wait_for_status_in_pool_dir
()
865 local state_pattern
="$4"
866 local description_pattern
="$5"
867 local service_pattern
="$6"
869 for s
in 1 2 4 8 8 8 8 8 8 8 8 16 16; do
871 test_status_in_pool_dir
${cluster} ${pool} ${image} "${state_pattern}" \
872 "${description_pattern}" "${service_pattern}" &&
880 local cluster=$1 ; shift
881 local pool=$1 ; shift
882 local image=$1 ; shift
890 rbd --cluster ${cluster} create --size ${size} \
891 --image-feature "${RBD_IMAGE_FEATURES}" $@ ${pool}/${image}
894 create_image_and_enable_mirror
()
896 local cluster
=$1 ; shift
897 local pool
=$1 ; shift
898 local image
=$1 ; shift
899 local mode
=${1:-${MIRROR_IMAGE_MODE}}
904 create_image
${cluster} ${pool} ${image} $@
905 enable_mirror
${cluster} ${pool} ${image} ${mode}
914 rbd
--cluster ${cluster} feature enable ${pool}/${image} journaling
925 rbd
--cluster ${cluster} image-meta set ${pool}/${image} $key $val
936 test `rbd --cluster ${cluster} image-meta get ${pool}/${image} ${key}` = "${value}"
946 rbd --cluster=${cluster} rename ${pool}/${image} ${pool}/${new_name}
955 rbd --cluster=${cluster} snap purge ${pool}/${image}
956 rbd --cluster=${cluster} rm ${pool}/${image}
965 for s in 0 1 2 4 8 16 32; do
967 remove_image ${cluster} ${pool} ${image} && return 0
977 rbd --cluster=${cluster} trash move ${pool}/${image}
985 rbd --cluster=${cluster} trash restore ${pool}/${image_id}
992 local parent_image=$3
999 rbd --cluster ${cluster} clone \
1000 ${parent_pool}/${parent_image}@${parent_snap} \
1001 ${clone_pool}/${clone_image} --image-feature "${RBD_IMAGE_FEATURES}" $@
1004 clone_image_and_enable_mirror()
1007 local parent_pool=$2
1008 local parent_image=$3
1009 local parent_snap=$4
1011 local clone_image=$6
1014 local mode=${1:-${MIRROR_IMAGE_MODE}}
1015 if [ -n "$1" ]; then
1019 clone_image ${cluster} ${parent_pool} ${parent_image} ${parent_snap} ${clone_pool} ${clone_image} $@
1020 enable_mirror ${cluster} ${clone_pool} ${clone_image} ${mode}
1029 rbd --cluster ${cluster} journal client disconnect \
1030 --image ${pool}/${image}
1040 rbd --cluster ${cluster} snap create ${pool}/${image}@${snap}
1050 rbd --cluster ${cluster} snap rm ${pool}/${image}@${snap}
1061 rbd --cluster ${cluster} snap rename ${pool}/${image}@${snap} \
1062 ${pool}/${image}@${new_snap}
1071 rbd --cluster ${cluster} snap purge ${pool}/${image}
1081 rbd --cluster ${cluster} snap protect ${pool}/${image}@${snap}
1084 unprotect_snapshot()
1091 rbd --cluster ${cluster} snap unprotect ${pool}/${image}@${snap}
1094 wait_for_snap_present()
1102 for s in 1 2 4 8 8 8 8 8 8 8 8 16 16 16 16 32 32 32 32; do
1104 rbd --cluster ${cluster} info ${pool}/${image}@${snap_name} || continue
1110 test_snap_moved_to_trash()
1117 rbd --cluster ${cluster} snap ls ${pool}/${image} --all |
1118 grep -F " trash (${snap_name})"
1121 wait_for_snap_moved_to_trash()
1125 for s in 1 2 4 8 8 8 8 8 8 8 8 16 16 16 16 32 32 32 32; do
1127 test_snap_moved_to_trash $@ || continue
1133 test_snap_removed_from_trash()
1135 test_snap_moved_to_trash $@ && return 1
1139 wait_for_snap_removed_from_trash()
1143 for s in 1 2 4 8 8 8 8 8 8 8 8 16 16 16 16 32 32 32 32; do
1145 test_snap_removed_from_trash $@ || continue
1159 test -n "${size}" || size=4096
1161 rbd --cluster ${cluster} bench ${pool}/${image} --io-type write \
1162 --io-size ${size} --io-threads 1 --io-total $((size * count)) \
1166 stress_write_image()
1171 local duration=$(awk 'BEGIN {srand(); print int(10 * rand()) + 5}')
1173 timeout ${duration}s ceph_test_rbd_mirror_random_write \
1174 --cluster ${cluster} ${pool} ${image} \
1175 --debug-rbd=20 --debug-journaler=20 \
1176 2> ${TEMPDIR}/rbd-mirror-random-write.log || true
1184 xxd ${file1} > ${file1}.xxd
1185 xxd ${file2} > ${file2}.xxd
1186 sdiff -s ${file1}.xxd ${file2}.xxd | head -n 64
1187 rm -f ${file1}.xxd ${file2}.xxd
1196 local rmt_export=${TEMPDIR}/$(mkfname ${CLUSTER2}-${pool}-${image}.export)
1197 local loc_export=${TEMPDIR}/$(mkfname ${CLUSTER1}-${pool}-${image}.export)
1199 rm -f ${rmt_export} ${loc_export}
1200 rbd --cluster ${CLUSTER2} export ${pool}/${image} ${rmt_export}
1201 rbd --cluster ${CLUSTER1} export ${pool}/${image} ${loc_export}
1202 if ! cmp ${rmt_export} ${loc_export}
1204 show_diff ${rmt_export} ${loc_export}
1207 rm -f ${rmt_export} ${loc_export}
1211 compare_image_snapshots()
1217 local rmt_export=${TEMPDIR}/${CLUSTER2}-${pool}-${image}.export
1218 local loc_export=${TEMPDIR}/${CLUSTER1}-${pool}-${image}.export
1220 for snap_name in $(rbd --cluster ${CLUSTER1} --format xml \
1221 snap list ${pool}/${image} | \
1222 $XMLSTARLET sel -t -v "//snapshot/name" | \
1223 grep -E -v "^\.rbd-mirror\."); do
1224 rm -f ${rmt_export} ${loc_export}
1225 rbd --cluster ${CLUSTER2} export ${pool}/${image}@${snap_name} ${rmt_export}
1226 rbd --cluster ${CLUSTER1} export ${pool}/${image}@${snap_name} ${loc_export}
1227 if ! cmp ${rmt_export} ${loc_export}
1229 show_diff ${rmt_export} ${loc_export}
1233 rm -f ${rmt_export} ${loc_export}
1243 rbd --cluster=${cluster} mirror image demote ${pool}/${image}
1253 rbd --cluster=${cluster} mirror image promote ${pool}/${image} ${force}
1256 set_pool_mirror_mode()
1260 local mode=${3:-${MIRROR_POOL_MODE}}
1262 rbd --cluster=${cluster} mirror pool enable ${pool} ${mode}
1271 rbd --cluster=${cluster} mirror image disable ${pool}/${image}
1279 local mode=${4:-${MIRROR_IMAGE_MODE}}
1281 rbd --cluster=${cluster} mirror image enable ${pool}/${image} ${mode}
1284 test_image_present()
1291 local current_state=deleted
1292 local current_image_id
1294 current_image_id=$(get_image_id ${cluster} ${pool} ${image})
1295 test -n "${current_image_id}" &&
1296 test -z "${image_id}" -o "${image_id}" = "${current_image_id}" &&
1297 current_state=present
1299 test "${test_state}" = "${current_state}"
1302 wait_for_image_present()
1311 test -n "${image_id}" ||
1312 image_id=$(get_image_id ${cluster} ${pool} ${image})
1314 # TODO: add a way to force rbd-mirror to update replayers
1315 for s in 0.1 1 2 4 8 8 8 8 8 8 8 8 16 16 32 32; do
1317 test_image_present \
1318 "${cluster}" "${pool}" "${image}" "${state}" "${image_id}" &&
1330 rbd --cluster=${cluster} info ${pool}/${image} |
1331 sed -ne 's/^.*block_name_prefix: rbd_data\.//p'
1334 request_resync_image()
1339 local image_id_var_name=$4
1341 eval "${image_id_var_name}='$(get_image_id ${cluster} ${pool} ${image})'"
1342 eval 'test -n "$'${image_id_var_name}'"'
1344 rbd --cluster=${cluster} mirror image resync ${pool}/${image}
1347 get_image_data_pool()
1353 rbd --cluster ${cluster} info ${pool}/${image} |
1354 awk '$1 == "data_pool:" {print $2}'
1363 rbd --cluster ${cluster} info ${pool}/${image} |
1370 /op_features: .*clone-child/ {
1385 if [ -z "${RBD_MIRROR_TEMDIR}" ]
1387 echo "RBD_MIRROR_TEMDIR is not set" >&2
1391 TEMPDIR="${RBD_MIRROR_TEMDIR}"