From: Loic Dachary Date: Sat, 15 Feb 2014 17:34:04 +0000 (+0100) Subject: ceph-disk: unit tests X-Git-Tag: v0.67.7~2^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fec55a2174b49ef68c816755c1218f9cd69033b6;p=ceph.git ceph-disk: unit tests src/test/ceph-disk.sh replaces src/test/cli/ceph-disk/data-dir.t Signed-off-by: Loic Dachary --- diff --git a/src/Makefile.am b/src/Makefile.am index b72ea91b16e..c79bbaecab3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,6 +50,7 @@ TESTS = $(check_PROGRAMS) unittest_bufferlist.sh check-local: $(srcdir)/test/encoding/check-generated.sh + $(srcdir)/test/ceph-disk.sh $(srcdir)/test/encoding/readable.sh ../ceph-object-corpus EXTRALIBS = -luuid @@ -1362,6 +1363,7 @@ EXTRA_DIST += \ $(ceph_tool_gui_DATA) \ $(srcdir)/test/encoding/readable.sh \ $(srcdir)/test/encoding/check-generated.sh \ + $(srcdir)/test/ceph-disk.sh \ $(srcdir)/upstart/ceph-all.conf \ $(srcdir)/upstart/ceph-mon.conf \ $(srcdir)/upstart/ceph-mon-all.conf \ diff --git a/src/ceph.in b/src/ceph.in index 35a60021752..1e7315a6c74 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -35,7 +35,8 @@ if MYDIR.endswith('src') and \ if 'LD_LIBRARY_PATH' in os.environ: if MYLIBPATH not in os.environ['LD_LIBRARY_PATH']: os.environ['LD_LIBRARY_PATH'] += ':' + MYLIBPATH - os.environ['PATH'] += ':' + MYDIR + if os.environ.has_key('PATH'): + os.environ['PATH'] += ':' + MYDIR print >> sys.stderr, DEVMODEMSG os.execvp('python', ['python'] + sys.argv) else: diff --git a/src/test/ceph-disk.sh b/src/test/ceph-disk.sh new file mode 100755 index 00000000000..668319c55a0 --- /dev/null +++ b/src/test/ceph-disk.sh @@ -0,0 +1,241 @@ +#!/bin/bash +# +# Copyright (C) 2014 Cloudwatt +# +# Author: Loic Dachary +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library Public License for more details. +# +set -xe +PS4='${FUNCNAME[0]}: $LINENO: ' + +export PATH=:$PATH # make sure program from sources are prefered +DIR=test-ceph-disk +MON_ID=a +MONA=127.0.0.1:7451 +FSID=$(uuidgen) +export CEPH_CONF=/dev/null +export CEPH_ARGS="--fsid $FSID" +CEPH_ARGS+=" --chdir=" +CEPH_ARGS+=" --run-dir=$DIR" +CEPH_ARGS+=" --mon-host=$MONA" +CEPH_ARGS+=" --log-file=$DIR/\$name.log" +CEPH_ARGS+=" --pid-file=$DIR/\$name.pidfile" +CEPH_ARGS+=" --auth-supported=none" +CEPH_DISK_ARGS= +CEPH_DISK_ARGS+=" --statedir=$DIR" +CEPH_DISK_ARGS+=" --sysconfdir=$DIR" +CEPH_DISK_ARGS+=" --prepend-to-path=" +CEPH_DISK_ARGS+=" --verbose" +TIMEOUT=3600 + +mkdir=$(which mkdir) +touch=$(which touch) +cat=$(which cat) +timeout=$(which timeout) +diff=$(which diff) + +function setup() { + teardown + mkdir $DIR + touch $DIR/ceph.conf +} + +function teardown() { + kill_daemons + rm -fr $DIR +} + +function run_mon() { + local mon_dir=$DIR/$MON_ID + $mkdir -p $mon_dir + ./ceph-mon \ + --id $MON_ID \ + --mkfs \ + --mon-data=$mon_dir \ + --keyring=/dev/null \ + --mon-initial-members=$MON_ID \ + "$@" + $touch $mon_dir/keyring + ./ceph-mon \ + --id $MON_ID \ + --mon-data=$mon_dir \ + --mon-cluster-log-file=$mon_dir/log \ + --public-addr $MONA \ + "$@" +} + +function kill_daemons() { + for pidfile in $(find $DIR | grep pidfile) ; do + for try in 0 1 1 1 2 3 ; do + kill $(cat $pidfile) || break + sleep $try + done + done +} + +function command_fixture() { + local command=$1 + + [ $(which $command) = ./$command ] || return 1 + + cat > $DIR/$command < $DIR/out 2>&1 + grep --quiet 'Is a directory' $DIR/out || return 1 + ! [ -f $osd_data/magic ] || return 1 + rmdir $osd_data/fsid + + echo successfully prepare the OSD + + CEPH_ARGS="--fsid $uuid" \ + ./ceph-disk $CEPH_DISK_ARGS prepare $osd_data 2>&1 | tee $DIR/out + grep --quiet 'Preparing osd data dir' $DIR/out || return 1 +# does not work because of CEPH_ARGS parsing precendence that was fixed post emperor +# grep --quiet $uuid $osd_data/ceph_fsid || return 1 + [ -f $osd_data/magic ] || return 1 + + echo will not override an existing OSD + + CEPH_ARGS="--fsid $(uuidgen)" \ + ./ceph-disk $CEPH_DISK_ARGS prepare $osd_data 2>&1 | tee $DIR/out + grep --quiet 'ceph-disk:Data dir .* already exists' $DIR/out || return 1 +# grep --quiet $uuid $osd_data/ceph_fsid || return 1 +} + +function test_activate_dir() { + run_mon + + local osd_data=$DIR/osd + + ./ceph-disk $CEPH_DISK_ARGS \ + prepare $osd_data || return 1 + + CEPH_ARGS="$CEPH_ARGS --osd-journal-size=100 --osd-data=$osd_data" \ + $timeout $TIMEOUT ./ceph-disk $CEPH_DISK_ARGS \ + activate \ + --mark-init=none \ + $osd_data || return 1 + $timeout $TIMEOUT ./ceph osd pool set data size 1 || return 1 + local id=$($cat $osd_data/whoami) + local weight=1 + ./ceph osd crush add osd.$id $weight root=default host=localhost || return 1 + echo FOO > $DIR/BAR + $timeout $TIMEOUT ./rados --pool data put BAR $DIR/BAR || return 1 + $timeout $TIMEOUT ./rados --pool data get BAR $DIR/BAR.copy || return 1 + $diff $DIR/BAR $DIR/BAR.copy || return 1 +} + +function test_find_cluster_by_uuid() { + setup + test_activate_dir 2>&1 | tee $DIR/test_find + ! grep "No cluster conf found in $DIR" $DIR/test_find || return 1 + teardown + + setup + rm $DIR/ceph.conf + test_activate_dir > $DIR/test_find 2>&1 + grep --quiet "No cluster conf found in $DIR" $DIR/test_find || return 1 + teardown +} + +function run() { + local default_actions + default_actions+="test_path " + default_actions+="test_no_path " + default_actions+="test_find_cluster_by_uuid " + default_actions+="test_prepend_to_path " + default_actions+="test_activate_dir_magic " + default_actions+="test_activate_dir " + local actions=${@:-$default_actions} + for action in $actions ; do + setup + $action || return 1 + teardown + done +} + +run $@ + +# Local Variables: +# compile-command: "cd .. ; test/ceph-disk.sh # test_activate_dir" +# End: diff --git a/src/test/cli/ceph-disk/data-dir.t b/src/test/cli/ceph-disk/data-dir.t deleted file mode 100644 index a0bb563f2a1..00000000000 --- a/src/test/cli/ceph-disk/data-dir.t +++ /dev/null @@ -1,22 +0,0 @@ - $ uuid=$(uuidgen) - $ export CEPH_CONF=$TESTDIR/ceph.conf - $ echo "[global]\nfsid = $uuid\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF - $ osd_data=$(ceph-conf osd_data) - $ mkdir $osd_data -# a failure to create the fsid file implies the magic file is not created - $ mkdir $osd_data/fsid - $ ceph-disk --verbose prepare $osd_data 2>&1 | grep 'Is a directory' - OSError: [Errno 21] Is a directory - $ ! [ -f $osd_data/magic ] - $ rmdir $osd_data/fsid -# successfully prepare the OSD - $ ceph-disk --verbose prepare $osd_data - DEBUG:ceph-disk:Preparing osd data dir .* (re) - $ grep $uuid $osd_data/ceph_fsid > /dev/null - $ [ -f $osd_data/magic ] -# will not override an existing OSD - $ echo "[global]\nfsid = $(uuidgen)\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF - $ ceph-disk --verbose prepare $osd_data - DEBUG:ceph-disk:Data dir .* already exists (re) - $ grep $uuid $osd_data/ceph_fsid > /dev/null - $ rm -fr $osd_data $TESTDIR/ceph.conf