]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: create test_unfound.sh
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 26 Oct 2010 17:04:12 +0000 (10:04 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 1 Nov 2010 16:50:08 +0000 (09:50 -0700)
Create test_unfound.sh to test handling unfound objects.

Move more test functions into test/test_common.sh to facilitate code
reuse.

Allow the user to keep the temporary directory around after the test is
over by setting KEEP_TEMPDIR.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/test/test_common.sh
src/test/test_unfound.sh [new file with mode: 0755]

index 0df86b3404f03c888cc4fffa5983eec784c9f573..566699f9c6ae254706e0b32b9da2292fee9ddfe5 100755 (executable)
@@ -5,22 +5,40 @@
 #
 # 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"
@@ -32,7 +50,53 @@ stop_osd() {
         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
diff --git a/src/test/test_unfound.sh b/src/test/test_unfound.sh
new file mode 100755 (executable)
index 0000000..1f99aac
--- /dev/null
@@ -0,0 +1,56 @@
+#!/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
+}
+
+$@