rbd --cluster=${cluster} mirror image promote ${POOL}/${image}
}
+set_pool_mirror_mode()
+{
+ local cluster=$1
+ local mode=$2
+
+ rbd --cluster=${cluster} -p ${POOL} mirror pool enable ${mode}
+}
+
+disable_mirror()
+{
+ local cluster=$1
+ local image=$2
+
+ rbd --cluster=${cluster} mirror image disable ${POOL}/${image}
+}
+
+enable_mirror()
+{
+ local cluster=$1
+ local image=$2
+
+ rbd --cluster=${cluster} mirror image enable ${POOL}/${image}
+}
+
+test_image_present()
+{
+ local cluster=$1
+ local image=$2
+ local test_state=$3
+ local current_state=deleted
+
+ rbd --cluster=${cluster} -p ${POOL} ls | grep "^${image}$" &&
+ current_state=present
+
+ test "${test_state}" = "${current_state}"
+}
+
+wait_for_image_present()
+{
+ local cluster=$1
+ local image=$2
+ local state=$3
+ local s
+
+ # TODO: add a way to force rbd-mirror to update replayers
+ for s in 1 2 4 8 8 8 8 8 8 8 8 16 16; do
+ sleep ${s}
+ test_image_present "${cluster}" "${image}" "${state}" && return 0
+ done
+ return 1
+}
+
#
# Main
#
test_status_in_pool_dir ${CLUSTER2} ${image} 'up+stopped'
compare_images ${image}
+testlog "TEST: disable mirroring / delete non-primary image"
+test_image_present ${CLUSTER1} ${image} 'present'
+set_pool_mirror_mode ${CLUSTER2} 'image'
+disable_mirror ${CLUSTER2} ${image}
+wait_for_image_present ${CLUSTER1} ${image} 'deleted'
+set_pool_mirror_mode ${CLUSTER2} 'pool'
+wait_for_image_present ${CLUSTER1} ${image} 'present'
+wait_for_image_replay_started ${CLUSTER1} ${image}
+
+testlog "TEST: disable mirror while daemon is stopped"
+stop_mirror ${CLUSTER1}
+stop_mirror ${CLUSTER2}
+set_pool_mirror_mode ${CLUSTER2} 'image'
+disable_mirror ${CLUSTER2} ${image}
+test_image_present ${CLUSTER1} ${image} 'present'
+start_mirror ${CLUSTER1}
+wait_for_image_present ${CLUSTER1} ${image} 'deleted'
+set_pool_mirror_mode ${CLUSTER2} 'pool'
+wait_for_image_present ${CLUSTER1} ${image} 'present'
+wait_for_image_replay_started ${CLUSTER1} ${image}
+
echo OK