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 <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9224
This commit is contained in:
Ryan Moeller 2019-08-29 16:11:29 -04:00 committed by Tony Hutter
parent 2f1f18a6b4
commit 0302546b8d

View File

@ -953,61 +953,26 @@ function set_partition
# #
function delete_partitions 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 if [[ -z $DISKSARRAY ]]; then
DISKSARRAY=$DISKS DISKSARRAY=$DISKS
fi fi
if is_linux; then if is_linux; then
if (( $DISK_ARRAY_NUM == 1 )); then typeset -i part
while ((j < MAX_PARTITIONS)); do for disk in $DISKSARRAY; do
parted $DEV_DSKDIR/$DISK -s rm $j \ for (( part = 1; part < MAX_PARTITIONS; part++ )); do
> /dev/null 2>&1 typeset partition=${disk}${SLICE_PREFIX}${part}
if (( $? == 1 )); then parted $DEV_DSKDIR/$disk -s rm $part > /dev/null 2>&1
lsblk | egrep ${DISK}${SLICE_PREFIX}${j} > /dev/null if lsblk | grep -qF ${partition}; then
if (( $? == 1 )); then log_fail "Partition ${partition} not deleted"
log_note "Partitions for $DISK should be deleted"
else else
log_fail "Partition for ${DISK}${SLICE_PREFIX}${j} not deleted" log_note "Partition ${partition} deleted"
fi fi
return 0
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 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 done
fi fi
fi
return 0
} }
# #