]> git.proxmox.com Git - mirror_zfs.git/blobdiff - tests/zfs-tests/tests/functional/fault/auto_online_001_pos.ksh
ZTS: Make fault cleanup function more robust
[mirror_zfs.git] / tests / zfs-tests / tests / functional / fault / auto_online_001_pos.ksh
index 3321b5a60cb88342e53313cd05bba4854d03017f..bc925bc91c815080dc8f98c378db7db66d2069ac 100755 (executable)
@@ -21,6 +21,7 @@
 #
 #
 # Copyright (c) 2016, 2017 by Intel Corporation. All rights reserved.
+# Copyright (c) 2019 by Delphix. All rights reserved.
 #
 
 . $STF_SUITE/include/libtest.shlib
@@ -54,9 +55,17 @@ fi
 
 function cleanup
 {
-       #online last disk before fail
-       on_off_disk $offline_disk "online" $host
-       poolexists $TESTPOOL && destroy_pool $TESTPOOL
+       typeset disk
+
+       # Replace any disk that may have been removed at failure time.
+       for disk in $DISK1 $DISK2 $DISK3; do
+               # Skip loop devices and devices that currently exist.
+               is_loop_device $disk && continue
+               is_real_device $disk && continue
+               insert_disk $disk $(get_scsi_host $disk)
+       done
+       destroy_pool $TESTPOOL
+       unload_scsi_debug
 }
 
 log_assert "Testing automated auto-online FMA test"
@@ -65,8 +74,8 @@ log_onexit cleanup
 
 # If using the default loop devices, need a scsi_debug device for auto-online
 if is_loop_device $DISK1; then
-       SD=$($LSSCSI | $NAWK '/scsi_debug/ {print $6; exit}')
-       SDDEVICE=$($ECHO $SD | $NAWK -F / '{print $3}')
+       load_scsi_debug $SDSIZE $SDHOSTS $SDTGTS $SDLUNS '512b'
+       SDDEVICE=$(get_debug_device)
        SDDEVICE_ID=$(get_persistent_disk_name $SDDEVICE)
        autoonline_disks="$SDDEVICE"
 else
@@ -76,46 +85,45 @@ fi
 # Clear disk labels
 for i in {0..2}
 do
-       log_must $ZPOOL labelclear -f /dev/disk/by-id/"${devs_id[i]}"
+       zpool labelclear -f /dev/disk/by-id/"${devs_id[i]}"
 done
 
 if is_loop_device $DISK1; then
        # create a pool with one scsi_debug device and 3 loop devices
-       log_must $ZPOOL create -f $TESTPOOL raidz1 $SDDEVICE_ID $DISK1 \
+       log_must zpool create -f $TESTPOOL raidz1 $SDDEVICE_ID $DISK1 \
            $DISK2 $DISK3
 elif ( is_real_device $DISK1 || is_mpath_device $DISK1 ); then
        # else use the persistent names for sd devices
-       log_must $ZPOOL create -f $TESTPOOL raidz1 ${devs_id[0]} \
+       log_must zpool create -f $TESTPOOL raidz1 ${devs_id[0]} \
            ${devs_id[1]} ${devs_id[2]}
 else
        log_fail "Disks are not supported for this test"
 fi
 
 # Add some data to the pool
-log_must $MKFILE $FSIZE /$TESTPOOL/data
+log_must mkfile $FSIZE /$TESTPOOL/data
 
 for offline_disk in $autoonline_disks
 do
-       log_must $ZPOOL export -F $TESTPOOL
+       log_must zpool export -F $TESTPOOL
 
-       host=$($LS /sys/block/$offline_disk/device/scsi_device \
-           | $NAWK -F : '{ print $1}')
+       host=$(get_scsi_host $offline_disk)
 
        # Offline disk
-       on_off_disk $offline_disk "offline"
+       remove_disk $offline_disk
 
        # Reimport pool with drive missing
-       log_must $ZPOOL import $TESTPOOL
+       log_must zpool import $TESTPOOL
        check_state $TESTPOOL "" "degraded"
        if (($? != 0)); then
                log_fail "$TESTPOOL is not degraded"
        fi
 
        # Clear zpool events
-       $ZPOOL events -c $TESTPOOL
+       log_must zpool events -c
 
        # Online disk
-       on_off_disk $offline_disk "online" $host
+       insert_disk $offline_disk $host
 
        log_note "Delay for ZED auto-online"
        typeset -i timeout=0
@@ -124,12 +132,13 @@ do
                        log_fail "Timeout occured"
                fi
                ((timeout++))
-               $SLEEP 1
-               $ZPOOL events $TESTPOOL \
-                   | $EGREP sysevent.fs.zfs.resilver_finish > /dev/null
+
+               sleep 1
+               zpool events $TESTPOOL \
+                   | egrep sysevent.fs.zfs.resilver_finish > /dev/null
                if (($? == 0)); then
                        log_note "Auto-online of $offline_disk is complete"
-                       $SLEEP 1
+                       sleep 1
                        break
                fi
        done
@@ -139,8 +148,8 @@ do
        if (($? != 0)); then
                log_fail "$TESTPOOL is not back online"
        fi
-       $SLEEP 2
+       sleep 2
 done
-log_must $ZPOOL destroy $TESTPOOL
+log_must zpool destroy $TESTPOOL
 
 log_pass "Auto-online test successful"