From e102e5a0e261f407913c5d47991c2549f6664ffc Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 10 Dec 2015 15:20:32 +0100 Subject: [PATCH] tests: verify it is possible to reuse an OSD id When an OSD id is removed via ceph osd rm, it will be reused by the next ceph osd create command. Verify that and OSD reusing such an id successfully comes up. http://tracker.ceph.com/issues/13988 Refs: #13988 Signed-off-by: Loic Dachary (cherry picked from commit 7324615bdb829f77928fa10d4e988c6422945937) --- qa/workunits/ceph-helpers.sh | 69 ++++++++++++++++++++++++++++++++++++ src/test/Makefile.am | 1 + src/test/osd/osd-reuse-id.sh | 51 ++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100755 src/test/osd/osd-reuse-id.sh diff --git a/qa/workunits/ceph-helpers.sh b/qa/workunits/ceph-helpers.sh index 5ee290962c30a..3c942bb6f2085 100755 --- a/qa/workunits/ceph-helpers.sh +++ b/qa/workunits/ceph-helpers.sh @@ -438,6 +438,42 @@ function test_run_osd() { ####################################################################### +## +# Shutdown and remove all traces of the osd by the name osd.**id**. +# +# The OSD is shutdown with the TERM signal. It is then removed from +# the auth list, crush map, osd map etc and the files associated with +# it are also removed. +# +# @param dir path name of the environment +# @param id osd identifier +# @return 0 on success, 1 on error +# +function destroy_osd() { + local dir=$1 + local id=$2 + + kill_daemons $dir TERM osd.$id || return 1 + ceph osd out osd.$id || return 1 + ceph auth del osd.$id || return 1 + ceph osd crush remove osd.$id || return 1 + ceph osd rm $id || return 1 + rm -fr $dir/$id +} + +function test_destroy_osd() { + local dir=$1 + + setup $dir || return 1 + run_mon $dir a || return 1 + run_osd $dir 0 || return 1 + destroy_osd $dir 0 || return 1 + ! ceph osd dump | grep "osd.$id " || return 1 + teardown $dir || return 1 +} + +####################################################################### + ## # Run (activate) an osd by the name osd.**id** with data in # **dir**/**id**. The logs can be found in **dir**/osd.**id**.log, @@ -1135,10 +1171,42 @@ function test_erasure_code_plugin_exists() { ####################################################################### +## +# Display all log files from **dir** on stdout. +# +# @param dir directory in which all data is stored +# + +function display_logs() { + local dir=$1 + + find $dir -maxdepth 1 -name '*.log' | \ + while read file ; do + echo "======================= $file" + cat $file + done +} + +function test_display_logs() { + local dir=$1 + + setup $dir || return 1 + run_mon $dir a || return 1 + kill_daemons $dir || return 1 + display_logs $dir > $dir/log.out + grep --quiet mon.a.log $dir/log.out || return 1 + teardown $dir || return 1 +} + +####################################################################### + ## # Call the **run** function (which must be defined by the caller) with # the **dir** argument followed by the caller argument list. # +# If the **run** function returns on error, all logs found in **dir** +# are displayed for diagnostic purposes. +# # **teardown** function is called when the **run** function returns # (on success or on error), to cleanup leftovers. The CEPH_CONF is set # to /dev/null and CEPH_ARGS is unset so that the tests are protected from @@ -1171,6 +1239,7 @@ function main() { if run $dir "$@" ; then code=0 else + display_logs $dir code=1 fi teardown $dir || return 1 diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 89fc7dfa7603a..fa813bab08aac 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -80,6 +80,7 @@ check_SCRIPTS += \ test/mon/mon-scrub.sh \ test/osd/osd-scrub-repair.sh \ test/osd/osd-config.sh \ + test/osd/osd-reuse-id.sh \ test/osd/osd-bench.sh \ test/osd/osd-copy-from.sh \ test/mon/mon-handle-forward.sh \ diff --git a/src/test/osd/osd-reuse-id.sh b/src/test/osd/osd-reuse-id.sh new file mode 100755 index 0000000000000..8efdf5c88bb1d --- /dev/null +++ b/src/test/osd/osd-reuse-id.sh @@ -0,0 +1,51 @@ +#! /bin/bash +# +# Copyright (C) 2015 Red Hat +# +# 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. +# +source ../qa/workunits/ceph-helpers.sh + +function run() { + local dir=$1 + shift + + export CEPH_MON="127.0.0.1:7123" # git grep '\<7123\>' : there must be only one + export CEPH_ARGS + CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " + CEPH_ARGS+="--mon-host=$CEPH_MON " + + local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} + for func in $funcs ; do + $func $dir || return 1 + done +} + +function TEST_reuse_id() { + local dir=$1 + + setup $dir || return 1 + run_mon $dir a --osd_pool_default_size=1 || return 1 + run_osd $dir 0 || return 1 + run_osd $dir 1 || return 1 + wait_for_clean || return 1 + destroy_osd $dir 1 || return 1 + run_osd $dir 1 || return 1 +} + +main osd-reuse-id "$@" + +# Local Variables: +# compile-command: "cd ../.. ; make -j4 && test/osd/osd-reuse-id.sh" +# End: + -- 2.39.5