From 051297114cb393d3eb1169520d474e81b4215bf0 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Sun, 15 Jul 2018 12:33:08 +0900 Subject: [PATCH] test/iscsi_tgt: Delete temporary files when trap catches error In iscsi_tgt tests, when error is caught by trap command, temporary files are not deleted. By this patch, delete temporary files in trap handlers. Change-Id: I317a102db346b345c3d25a4977528c737b861748 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/419311 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ziye Yang Reviewed-by: Changpeng Liu Reviewed-by: Seth Howell Reviewed-by: Ben Walker --- test/iscsi_tgt/calsoft/calsoft.sh | 8 +++++++- test/iscsi_tgt/ext4test/ext4test.sh | 4 ++-- test/iscsi_tgt/fio/fio.sh | 19 ++++++++++++------- test/iscsi_tgt/initiator/initiator.sh | 2 +- test/iscsi_tgt/nvme_remote/fio_remote_nvme.sh | 7 ++++--- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/test/iscsi_tgt/calsoft/calsoft.sh b/test/iscsi_tgt/calsoft/calsoft.sh index e50a4129b..13b844796 100755 --- a/test/iscsi_tgt/calsoft/calsoft.sh +++ b/test/iscsi_tgt/calsoft/calsoft.sh @@ -4,6 +4,11 @@ rootdir=$(readlink -f $testdir/../../..) source $rootdir/test/common/autotest_common.sh source $rootdir/test/iscsi_tgt/common.sh +delete_tmp_conf_files() { + rm -f /usr/local/etc/its.conf + rm -f /usr/local/etc/auth.conf +} + if [ ! -d /usr/local/calsoft ]; then echo "skipping calsoft tests" exit 0 @@ -31,7 +36,7 @@ $ISCSI_APP -c $testdir/iscsi.conf -m 0x1 & pid=$! echo "Process pid: $pid" -trap "killprocess $pid; exit 1 " SIGINT SIGTERM EXIT +trap "killprocess $pid; delete_tmp_conf_files; exit 1 " SIGINT SIGTERM EXIT waitforlisten $pid echo "iscsi_tgt is listening. Running tests..." @@ -59,5 +64,6 @@ fi trap - SIGINT SIGTERM EXIT killprocess $pid +delete_tmp_conf_files timing_exit calsoft exit $failed diff --git a/test/iscsi_tgt/ext4test/ext4test.sh b/test/iscsi_tgt/ext4test/ext4test.sh index 711eacf18..ce63eb9b1 100755 --- a/test/iscsi_tgt/ext4test/ext4test.sh +++ b/test/iscsi_tgt/ext4test/ext4test.sh @@ -23,7 +23,7 @@ $ISCSI_APP -c $testdir/iscsi.conf & pid=$! echo "Process pid: $pid" -trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT +trap "killprocess $pid; rm -f $testdir/iscsi.conf; exit 1" SIGINT SIGTERM EXIT waitforlisten $pid echo "iscsi_tgt is listening. Running tests..." @@ -43,7 +43,7 @@ iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT trap 'for new_dir in `dir -d /mnt/*dir`; do umount $new_dir; rm -rf $new_dir; done; \ - iscsicleanup; killprocess $pid; exit 1' SIGINT SIGTERM EXIT + iscsicleanup; killprocess $pid; rm -f $testdir/iscsi.conf; exit 1' SIGINT SIGTERM EXIT sleep 1 diff --git a/test/iscsi_tgt/fio/fio.sh b/test/iscsi_tgt/fio/fio.sh index 27b674727..093d9695c 100755 --- a/test/iscsi_tgt/fio/fio.sh +++ b/test/iscsi_tgt/fio/fio.sh @@ -5,6 +5,11 @@ rootdir=$(readlink -f $testdir/../../..) source $rootdir/test/common/autotest_common.sh source $rootdir/test/iscsi_tgt/common.sh +delete_tmp_files() { + rm -f $testdir/iscsi.conf + rm -f ./local-job0-0-verify.state +} + function running_config() { # generate a config file from the running iscsi_tgt # running_config.sh will leave the file at /tmp/iscsi.conf @@ -15,14 +20,14 @@ function running_config() { # keep the same iscsiadm configuration to confirm that the # config file matched the running configuration killprocess $pid - trap "iscsicleanup; exit 1" SIGINT SIGTERM EXIT + trap "iscsicleanup; delete_tmp_files; exit 1" SIGINT SIGTERM EXIT timing_enter start_iscsi_tgt2 $ISCSI_APP -c /tmp/iscsi.conf & pid=$! echo "Process pid: $pid" - trap "iscsicleanup; killprocess $pid; exit 1" SIGINT SIGTERM EXIT + trap "iscsicleanup; killprocess $pid; delete_tmp_files; exit 1" SIGINT SIGTERM EXIT waitforlisten $pid echo "iscsi_tgt is listening. Running tests..." @@ -58,7 +63,7 @@ $ISCSI_APP -c $testdir/iscsi.conf & pid=$! echo "Process pid: $pid" -trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT +trap "killprocess $pid; rm -f $testdir/iscsi.conf; exit 1" SIGINT SIGTERM EXIT waitforlisten $pid echo "iscsi_tgt is listening. Running tests..." @@ -78,7 +83,7 @@ sleep 1 iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT -trap "iscsicleanup; killprocess $pid; exit 1" SIGINT SIGTERM EXIT +trap "iscsicleanup; killprocess $pid; delete_tmp_files; exit 1" SIGINT SIGTERM EXIT sleep 1 $fio_py 4096 1 randrw 1 verify @@ -118,10 +123,10 @@ set -e iscsicleanup $rpc_py delete_target_node 'iqn.2016-06.io.spdk:Target3' -rm -f ./local-job0-0-verify.state +delete_tmp_files + trap - SIGINT SIGTERM EXIT -iscsicleanup -rm -f $testdir/iscsi.conf + killprocess $pid #echo 1 > /sys/bus/pci/rescan #sleep 2 diff --git a/test/iscsi_tgt/initiator/initiator.sh b/test/iscsi_tgt/initiator/initiator.sh index dbdfde05b..3197533fb 100755 --- a/test/iscsi_tgt/initiator/initiator.sh +++ b/test/iscsi_tgt/initiator/initiator.sh @@ -34,7 +34,7 @@ $rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE # "-d" ==> disable CHAP authentication $rpc_py construct_target_node disk1 disk1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 256 -d sleep 1 -trap "killprocess $pid; exit 1" SIGINT SIGTERM EXIT +trap "killprocess $pid; rm -f $testdir/bdev.conf; exit 1" SIGINT SIGTERM EXIT # Prepare config file for iSCSI initiator cp $testdir/bdev.conf.in $testdir/bdev.conf diff --git a/test/iscsi_tgt/nvme_remote/fio_remote_nvme.sh b/test/iscsi_tgt/nvme_remote/fio_remote_nvme.sh index 187200c3c..01df214fe 100755 --- a/test/iscsi_tgt/nvme_remote/fio_remote_nvme.sh +++ b/test/iscsi_tgt/nvme_remote/fio_remote_nvme.sh @@ -40,7 +40,7 @@ function run_nvme_remote() { $ISCSI_APP -r "$iscsi_rpc_addr" -c $testdir/iscsi.conf.tmp -m 0x1 -p 0 -s 512 & iscsipid=$! echo "iSCSI target launched. pid: $iscsipid" - trap "killprocess $iscsipid; killprocess $nvmfpid; exit 1" SIGINT SIGTERM EXIT + trap "killprocess $iscsipid; killprocess $nvmfpid; rm -f $testdir/iscsi.conf.tmp; exit 1" SIGINT SIGTERM EXIT waitforlisten $iscsipid "$iscsi_rpc_addr" echo "iSCSI target has started." @@ -67,7 +67,7 @@ NVMF_APP="$rootdir/app/nvmf_tgt/nvmf_tgt" $NVMF_APP -c $rootdir/test/nvmf/nvmf.conf -m 0x2 -p 1 -s 512 & nvmfpid=$! echo "NVMf target launched. pid: $nvmfpid" -trap "killprocess $nvmfpid; exit 1" SIGINT SIGTERM EXIT +trap "killprocess $nvmfpid; rm -f $testdir/iscsi.conf.tmp; exit 1" SIGINT SIGTERM EXIT waitforlisten $nvmfpid echo "NVMf target has started." bdevs=$($rpc_py construct_malloc_bdev 64 512) @@ -78,7 +78,8 @@ timing_enter start_iscsi_tgt run_nvme_remote "local" -trap "iscsicleanup; killprocess $iscsipid; killprocess $nvmfpid; exit 1" SIGINT SIGTERM EXIT +trap "iscsicleanup; killprocess $iscsipid; killprocess $nvmfpid; rm -f $testdir/iscsi.conf.tmp; \ + rm -f ./local-job0-0-verify.state; exit 1" SIGINT SIGTERM EXIT sleep 1 echo "Running FIO"