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 <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/419311
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Seth Howell <seth.howell5141@gmail.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-07-15 12:33:08 +09:00 committed by Changpeng Liu
parent 64ac643aa5
commit 051297114c
5 changed files with 26 additions and 14 deletions

View File

@ -4,6 +4,11 @@ rootdir=$(readlink -f $testdir/../../..)
source $rootdir/test/common/autotest_common.sh source $rootdir/test/common/autotest_common.sh
source $rootdir/test/iscsi_tgt/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 if [ ! -d /usr/local/calsoft ]; then
echo "skipping calsoft tests" echo "skipping calsoft tests"
exit 0 exit 0
@ -31,7 +36,7 @@ $ISCSI_APP -c $testdir/iscsi.conf -m 0x1 &
pid=$! pid=$!
echo "Process pid: $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 waitforlisten $pid
echo "iscsi_tgt is listening. Running tests..." echo "iscsi_tgt is listening. Running tests..."
@ -59,5 +64,6 @@ fi
trap - SIGINT SIGTERM EXIT trap - SIGINT SIGTERM EXIT
killprocess $pid killprocess $pid
delete_tmp_conf_files
timing_exit calsoft timing_exit calsoft
exit $failed exit $failed

View File

@ -23,7 +23,7 @@ $ISCSI_APP -c $testdir/iscsi.conf &
pid=$! pid=$!
echo "Process pid: $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 waitforlisten $pid
echo "iscsi_tgt is listening. Running tests..." 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 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; \ 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 sleep 1

View File

@ -5,6 +5,11 @@ rootdir=$(readlink -f $testdir/../../..)
source $rootdir/test/common/autotest_common.sh source $rootdir/test/common/autotest_common.sh
source $rootdir/test/iscsi_tgt/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() { function running_config() {
# generate a config file from the running iscsi_tgt # generate a config file from the running iscsi_tgt
# running_config.sh will leave the file at /tmp/iscsi.conf # 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 # keep the same iscsiadm configuration to confirm that the
# config file matched the running configuration # config file matched the running configuration
killprocess $pid killprocess $pid
trap "iscsicleanup; exit 1" SIGINT SIGTERM EXIT trap "iscsicleanup; delete_tmp_files; exit 1" SIGINT SIGTERM EXIT
timing_enter start_iscsi_tgt2 timing_enter start_iscsi_tgt2
$ISCSI_APP -c /tmp/iscsi.conf & $ISCSI_APP -c /tmp/iscsi.conf &
pid=$! pid=$!
echo "Process pid: $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 waitforlisten $pid
echo "iscsi_tgt is listening. Running tests..." echo "iscsi_tgt is listening. Running tests..."
@ -58,7 +63,7 @@ $ISCSI_APP -c $testdir/iscsi.conf &
pid=$! pid=$!
echo "Process pid: $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 waitforlisten $pid
echo "iscsi_tgt is listening. Running tests..." 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 discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
iscsiadm -m node --login -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 sleep 1
$fio_py 4096 1 randrw 1 verify $fio_py 4096 1 randrw 1 verify
@ -118,10 +123,10 @@ set -e
iscsicleanup iscsicleanup
$rpc_py delete_target_node 'iqn.2016-06.io.spdk:Target3' $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 trap - SIGINT SIGTERM EXIT
iscsicleanup
rm -f $testdir/iscsi.conf
killprocess $pid killprocess $pid
#echo 1 > /sys/bus/pci/rescan #echo 1 > /sys/bus/pci/rescan
#sleep 2 #sleep 2

View File

@ -34,7 +34,7 @@ $rpc_py construct_malloc_bdev $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
# "-d" ==> disable CHAP authentication # "-d" ==> disable CHAP authentication
$rpc_py construct_target_node disk1 disk1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 256 -d $rpc_py construct_target_node disk1 disk1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 256 -d
sleep 1 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 # Prepare config file for iSCSI initiator
cp $testdir/bdev.conf.in $testdir/bdev.conf cp $testdir/bdev.conf.in $testdir/bdev.conf

View File

@ -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 & $ISCSI_APP -r "$iscsi_rpc_addr" -c $testdir/iscsi.conf.tmp -m 0x1 -p 0 -s 512 &
iscsipid=$! iscsipid=$!
echo "iSCSI target launched. pid: $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" waitforlisten $iscsipid "$iscsi_rpc_addr"
echo "iSCSI target has started." 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 & $NVMF_APP -c $rootdir/test/nvmf/nvmf.conf -m 0x2 -p 1 -s 512 &
nvmfpid=$! nvmfpid=$!
echo "NVMf target launched. pid: $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 waitforlisten $nvmfpid
echo "NVMf target has started." echo "NVMf target has started."
bdevs=$($rpc_py construct_malloc_bdev 64 512) bdevs=$($rpc_py construct_malloc_bdev 64 512)
@ -78,7 +78,8 @@ timing_enter start_iscsi_tgt
run_nvme_remote "local" 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 sleep 1
echo "Running FIO" echo "Running FIO"