From e6df8074f317f5ac37751efff379121d14f8071c Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Tue, 26 Oct 2010 10:04:12 -0700 Subject: [PATCH] test: create test_unfound.sh 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 --- src/test/test_common.sh | 70 ++++++++++++++++++++++++++++++++++++++-- src/test/test_unfound.sh | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 3 deletions(-) create mode 100755 src/test/test_unfound.sh diff --git a/src/test/test_common.sh b/src/test/test_common.sh index 0df86b3404f03..566699f9c6ae2 100755 --- a/src/test/test_common.sh +++ b/src/test/test_common.sh @@ -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 index 0000000000000..1f99aac604eef --- /dev/null +++ b/src/test/test_unfound.sh @@ -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 +} + +$@ -- 2.39.5