#
# Common routines for tests
#
+#
+# Environment variables that affect tests:
+# KEEP_TEMPDIR If set, the tempdir will not be deleted
+# when the test is over.
+#
-# Functions
+# Clean up the temporary directory
cleanup() {
- rm -rf "${TEMPDIR}"
+ if [ -n ${TEMPDIR} ]; then
+ rm -rf "${TEMPDIR}"
+ fi
}
+# Create a temporary directory where test files will be stored.
setup_tempdir() {
TEMPDIR=`mktemp -d`
- trap cleanup INT TERM EXIT
+ if [ -z $KEEP_TEMPDIR ]; then
+ trap cleanup INT TERM EXIT
+ fi
}
+# Standard initialization function for tests
+init() {
+ setup_tempdir
+ cd `dirname $0`/..
+}
+
+# Exit with an error message.
die() {
echo $@
exit 1
}
+# Stop an OSD started by vstart
stop_osd() {
osd_index=$1
pidfile="out/osd.$osd_index.pid"
return 1
}
+# Restart an OSD started by vstart
restart_osd() {
osd_index=$1
./cosd -i $osd_index -c ceph.conf &
}
+
+# Ask the user a yes/no question and get the response
+yes_or_no_choice() {
+ while true; do
+ echo -n "${1} [y/n] "
+ read ans
+ case "${ans}" in
+ y|Y|yes|YES|Yes) return 0 ;;
+ n|N|no|NO|No) return 1 ;;
+ *) echo "Please type yes or no."
+ echo ;;
+ esac
+ done
+}
+
+# Block until the user says "continue" or "c"
+continue_prompt() {
+ prompt=${1:-"to go on"}
+ while true; do
+ echo "Please type 'c' or 'continue' ${prompt}."
+ read ans
+ case "${ans}" in
+ c|continue) return 0 ;;
+ *) echo ;;
+ esac
+ done
+}
+
+# Write a bunch of objects to rados
+write_objects() {
+ start_ver=$1
+ stop_ver=$2
+ num_objs=$3
+ obj_size=$4
+ [ -d "${TEMPDIR}" ] || die "must setup_tempdir"
+ for v in `seq $start_ver $stop_ver`; do
+ chr=`perl -e "print chr(48+$v)"`
+ head -c $obj_size /dev/zero | tr '\0' "$chr" > $TEMPDIR/ver$v
+ for i in `seq -w 1 $num_objs`; do
+ ./rados -p data put obj$i $TEMPDIR/ver$v || die "radostool failed"
+ done
+ done
+}
+
+init
--- /dev/null
+#!/bin/bash -x
+
+#
+# Creates some unfound objects and then tests finding them.
+#
+
+# Includes
+source "`dirname $0`/test_common.sh"
+
+# Constants
+my_write_objects() {
+ write_objects $1 $2 50 1000000
+}
+
+setup() {
+ # Start ceph
+ ./stop.sh
+
+ # set recovery start to a really long time to ensure that we don't start recovery
+ CEPH_NUM_OSD=2 ./vstart.sh -d -n -o 'osd recovery delay start = 10000' || die "vstart failed"
+}
+
+do_test() {
+ # Write lots and lots of objects
+ my_write_objects 1 2
+
+ # Take down osd1
+ stop_osd 1
+
+ # Continue writing a lot of objects
+ my_write_objects 3 4
+
+ # Bring up osd1
+ restart_osd 1
+
+ # Finish peering.
+ sleep 15
+
+ # Stop osd0.
+ # At this point we have peered, but *NOT* recovered.
+ # Objects should be lost.
+ stop_osd 0
+
+ echo "There should be unfound objects."
+ continue_prompt "to test finding the unfound objects."
+
+ restart_osd 0
+}
+
+run() {
+ setup
+
+ do_test
+}
+
+$@