From f6bbcf4367da6b0e43b53378b2529f258ed6ca94 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 29 Dec 2013 13:21:02 +0100 Subject: [PATCH] mon: tests for ceph-mon --mkfs * auth none must not require a keyring * --key can be used as an alternative to --keyring * --mkfs is idempotent * the --mon-data directory is created if it does not exist * auth ceph requires --keyring Signed-off-by: Loic Dachary --- src/test/Makefile.am | 1 + src/test/mon/mkfs.sh | 172 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100755 src/test/mon/mkfs.sh diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 590a7fb948ba..22bc834bfc59 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -242,6 +242,7 @@ check_SCRIPTS += \ unittest_bufferlist.sh \ test/encoding/check-generated.sh \ test/mon/osd-pool-create.sh \ + test/mon/mkfs.sh \ test/vstart_wrapped_tests.sh # target to build but not run the unit tests diff --git a/src/test/mon/mkfs.sh b/src/test/mon/mkfs.sh new file mode 100755 index 000000000000..a3f139728c1a --- /dev/null +++ b/src/test/mon/mkfs.sh @@ -0,0 +1,172 @@ +#!/bin/bash +# +# Copyright (C) 2013 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: ' + +DIR=mkfs +export CEPH_CONF=/dev/null +unset CEPH_ARGS +MON_ID=a +MON_DIR=$DIR/$MON_ID +PORT=7451 +MONA=127.0.0.1:$PORT + +function setup() { + teardown + mkdir $DIR +} + +function teardown() { + kill_daemons + rm -fr $DIR +} + +function mon_mkfs() { + local fsid=$(uuidgen) + + ./ceph-mon \ + --id $MON_ID \ + --fsid $fsid \ + --mkfs \ + --mon-data=$MON_DIR \ + --mon-initial-members=$MON_ID \ + --mon-host=$MONA \ + "$@" +} + +function mon_run() { + ./ceph-mon \ + --id $MON_ID \ + --chdir= \ + --mon-data=$MON_DIR \ + --log-file=$MON_DIR/log \ + --mon-cluster-log-file=$MON_DIR/log \ + --run-dir=$MON_DIR \ + --pid-file=$MON_DIR/pidfile \ + --public-addr $MONA \ + "$@" +} + +function kill_daemons() { + for pidfile in $(find $DIR -name pidfile) ; do + for try in 0 1 1 1 2 3 ; do + kill $(cat $pidfile) || break + sleep $try + done + done +} + +function auth_none() { + mon_mkfs --auth-supported=none + + ./ceph-mon \ + --id $MON_ID \ + --mon-data=$MON_DIR \ + --extract-monmap $MON_DIR/monmap + + [ -f $MON_DIR/monmap ] || return 1 + + [ ! -f $MON_DIR/keyring ] || return 1 + + mon_run --auth-supported=none + + timeout 10 ./ceph --mon-host $MONA mon stat || return 1 +} + +function auth_cephx_keyring() { + cat > $DIR/keyring <&1 | tee $DIR/makedir.log + grep 'toodeep.*No such file' $DIR/makedir.log > /dev/null + rm $DIR/makedir.log + + # an empty directory does not mean the mon exists + mkdir $MON_DIR + mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log + ! grep "$MON_DIR already exists" $DIR/makedir.log || return 1 +} + +function idempotent() { + mon_mkfs --auth-supported=none + mon_mkfs --auth-supported=none 2>&1 | tee $DIR/makedir.log + grep "$MON_DIR already exists" $DIR/makedir.log > /dev/null || return 1 +} + +function run() { + local actions + actions+="makedir " + actions+="idempotent " + actions+="auth_cephx_key " + actions+="auth_cephx_keyring " + actions+="auth_none " + for action in $actions ; do + setup + $action || return 1 + teardown + done +} + +run + +# Local Variables: +# compile-command: "cd ../.. ; make TESTS=test/mon/mkfs.sh check" +# End: -- 2.47.3