From 5764a8ce591e7f62cad2ee95b7041c115a1cd0f6 Mon Sep 17 00:00:00 2001 From: Parinay Kondekar Date: Tue, 12 Apr 2016 12:14:03 +0530 Subject: [PATCH] LU-7110 tests: sanity-hsm.sh can erase all files on filesystem For SINGLEAGT=client, $HSM_ARCHIVE & $hsm_root is empty. Thus purging of archive in copytool_setup() will result in execution of "rm -rf /*", resulting in permanent loss of files as well as cluster node. This change fixes it by checking the respective variables like HSM_ARCHIVE or hsm_root to be non-empty. Change-Id: I73cdc08a58409ae1f3ba85a9d12077062a38b321 Seagate-Bug-Id: MRP-2659 Signed-off-by: Parinay Kondekar Reviewed-on: http://es-gerrit.xyus.xyratex.com:8080/6471 Tested-by:Jenkins Reviewed-by: Elena V. Gryaznova Reviewed-by: Alexander Lezhoev Reviewed-on: http://review.whamcloud.com/16291 Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: jacques-Charles Lafoucriere Reviewed-by: Oleg Drokin --- lustre/tests/sanity-hsm.sh | 31 ++++++++++++++++++++++++------- lustre/tests/test-framework.sh | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lustre/tests/sanity-hsm.sh b/lustre/tests/sanity-hsm.sh index f73a502..9f8ec9c 100755 --- a/lustre/tests/sanity-hsm.sh +++ b/lustre/tests/sanity-hsm.sh @@ -103,7 +103,16 @@ init_agt_vars() { export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""} export HSMTOOL_TESTDIR export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ") + # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure + # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid + # deleting everything in filesystem, independent of any copytool. + export HSMTMP=${HSMTMP:-"shsm"} + HSM_ARCHIVE=$(copytool_device $SINGLEAGT) + + [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!" + HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP + HSM_ARCHIVE_NUMBER=2 # The test only support up to 10 MDTs @@ -244,6 +253,9 @@ copytool_setup() { local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}} local arc_id=$3 local hsm_root=${4:-$(copytool_device $facet)} + + [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!" + local agent=$(facet_active_host $facet) if [[ -z "$arc_id" ]] && @@ -254,14 +266,16 @@ copytool_setup() { if $HSM_ARCHIVE_PURGE; then echo "Purging archive on $agent" - do_facet $facet "rm -rf $hsm_root/*" + do_facet $facet "rm -rf $hsm_root/$HSMTMP/*" fi echo "Starting copytool $facet on $agent" - do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed" + do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" || + error "mkdir '$hsm_root/$HSMTMP' failed" # bandwidth is limited to 1MB/s so the copy time is known and # independent of hardware - local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root" + local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon" + cmd+=" --hsm-root $hsm_root/$HSMTMP" [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id" [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] || cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL" @@ -301,6 +315,9 @@ copytool_cleanup() { local agt_facet=$SINGLEAGT local agt_hosts=${1:-$(facet_active_host $agt_facet)} local hsm_root=$(copytool_device $agt_facet) + + [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!" + local i local facet local param @@ -349,7 +366,7 @@ copytool_cleanup() { done if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then - do_facet $agt_facet "rm -rf $hsm_root/*" + do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*" fi } @@ -794,12 +811,12 @@ parse_json_event() { echo $raw_event | python -c "$json_parser" } -# populate MDT device array -get_mdt_devices - # initiate variables init_agt_vars +# populate MDT device array +get_mdt_devices + # cleanup from previous bad setup kill_copytools diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index c413a35..9037f7e 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -817,7 +817,7 @@ facet_type() { facet_number() { local facet=$1 - if [ $facet == mgs ]; then + if [ $facet == mgs ] || [ $facet == client ]; then return 1 fi -- 1.8.3.1