From bdd95051ed6a71e447474e96f770b2d79baf4889 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 3 Jul 2017 20:36:27 +0200 Subject: [PATCH] tests: use bash array --- test/shell/mirror-names.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/test/shell/mirror-names.sh b/test/shell/mirror-names.sh index f3bfe410f..899d63d8a 100644 --- a/test/shell/mirror-names.sh +++ b/test/shell/mirror-names.sh @@ -22,27 +22,33 @@ SKIP_WITH_LVMLOCKD=1 lv_devices_() { local d + local i local lv=$1 shift - local devices=$@ + local devices=( "$@" ) local devs devs=$(get lv_devices "$lv") for d in $devs; do - (echo "$devices" | grep "$d") || return 1 - devices=$(echo "$devices" | sed "s/$d//") + (echo "${devices[@]}" | grep "$d") || return 1 + for i in "${!devices[@]}"; do + if [ "${devices[i]}" = "$d" ] ; then + unset "devices[i]" + fi + done done - test -z "$(echo $devices | sed 's/ //g')" + test "${#devices[@]}" -eq 0 || + die "Left devices " "${devices[@]}" } lv_mirror_log_() { - get lv_field $1 mirror_log | tr -d [] + get lv_field "$1" mirror_log | tr -d [] } lv_convert_lv_() { - get lv_field $1 convert_lv | tr -d [] + get lv_field "$1" convert_lv | tr -d [] } enable_devs() { @@ -84,7 +90,7 @@ lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg lv_devices_ $vg/$lv1 ${lv1}_mimage_0 ${lv1}_mimage_1 #COMM "mirror log is ${lv1}_mlog" -test $(lv_mirror_log_ $vg/$lv1) = ${lv1}_mlog +test "$(lv_mirror_log_ $vg/$lv1)" = "${lv1}_mlog" # "cleanup" check_and_cleanup_lvs_ @@ -119,13 +125,13 @@ lvcreate -aey -l2 --type mirror -m1 -n $lv1 $vg delay_devs LVM_TEST_TAG="kill_me_$PREFIX" lvconvert -m+1 -i+40 -b $vg/$lv1 convlv=$(lv_convert_lv_ $vg/$lv1) -test $convlv = ${lv1}_mimagetmp_2 +test "$convlv" = "${lv1}_mimagetmp_2" lv_devices_ $vg/$lv1 $convlv ${lv1}_mimage_2 lv_devices_ $vg/$convlv ${lv1}_mimage_0 ${lv1}_mimage_1 lv_mirror_log_ $vg/$convlv ${lv1}_mlog enable_devs -#COMM "mirror log name after re-adding is ${lv1}_mlog" \ +#COMM "mirror log name after re-adding is ${lv1}_mlog" lvconvert -f --mirrorlog core $vg/$lv1 lvconvert --mirrorlog disk $vg/$lv1 convlv=$(lv_convert_lv_ $vg/$lv1) @@ -133,7 +139,7 @@ lv_devices_ $vg/$lv1 $convlv ${lv1}_mimage_2 lv_devices_ $vg/$convlv ${lv1}_mimage_0 ${lv1}_mimage_1 lv_mirror_log_ $vg/$convlv ${lv1}_mlog -#COMM "renamed converting mirror names: $lv1 to $lv2" \ +#COMM "renamed converting mirror names: $lv1 to $lv2" lvrename $vg/$lv1 $vg/$lv2 convlv=$(lv_convert_lv_ $vg/$lv2) lv_devices_ $vg/$lv2 $convlv ${lv2}_mimage_2