diff options
author | Ryan Moeller <[email protected]> | 2019-08-29 16:11:29 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-08-29 13:11:29 -0700 |
commit | 815a6456928b56b98bea3c9508f4037b6d6f4759 (patch) | |
tree | 15126bbf4792d47e8fa6068c166d871e494c1f39 /tests | |
parent | f66ad580cca5493b6f4b7acb23aa7d82f3b82755 (diff) |
Simplify deleting partitions in libtest
Eliminate unnecessary code duplication. We can use a for-loop instead
of a while-loop. There is no need to echo $DISKSARRAY in a subshell or
return 0. Declare all variables with typeset.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #9224
Diffstat (limited to 'tests')
-rw-r--r-- | tests/zfs-tests/include/libtest.shlib | 55 |
1 files changed, 10 insertions, 45 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 5d536fda3..cda4b04cd 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -966,61 +966,26 @@ function set_partition # function delete_partitions { - typeset -i j=1 + typeset disk - if [[ -z $DISK_ARRAY_NUM ]]; then - DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}') - fi if [[ -z $DISKSARRAY ]]; then DISKSARRAY=$DISKS fi if is_linux; then - if (( $DISK_ARRAY_NUM == 1 )); then - while ((j < MAX_PARTITIONS)); do - parted $DEV_DSKDIR/$DISK -s rm $j \ - > /dev/null 2>&1 - if (( $? == 1 )); then - lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null - if (( $? == 1 )); then - log_note "Partitions for $DISK should be deleted" - else - log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted" - fi - return 0 + typeset -i part + for disk in $DISKSARRAY; do + for (( part = 1; part < MAX_PARTITIONS; part++ )); do + typeset partition=${disk}${SLICE_PREFIX}${part} + parted $DEV_DSKDIR/$disk -s rm $part > /dev/null 2>&1 + if lsblk | grep -qF ${partition}; then + log_fail "Partition ${partition} not deleted" else - lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null - if (( $? == 0 )); then - log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted" - fi + log_note "Partition ${partition} deleted" fi - ((j = j+1)) - done - else - for disk in `echo $DISKSARRAY`; do - while ((j < MAX_PARTITIONS)); do - parted $DEV_DSKDIR/$disk -s rm $j > /dev/null 2>&1 - if (( $? == 1 )); then - lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null - if (( $? == 1 )); then - log_note "Partitions for $disk should be deleted" - else - log_fail "Partition for ${disk}${SLICE_PREFIX}${j} not deleted" - fi - j=7 - else - lsblk | egrep ${disk}${SLICE_PREFIX}${j} > /dev/null - if (( $? == 0 )); then - log_fail "Partition for ${disk}${SLICE_PREFIX}${j} not deleted" - fi - fi - ((j = j+1)) - done - j=1 done - fi + done fi - return 0 } # |