diff --git a/tests/002-test-reject-disk-with-lvm-signature.sh b/tests/002-test-reject-disk-with-lvm-signature.sh index 31400ff..632ac3c 100755 --- a/tests/002-test-reject-disk-with-lvm-signature.sh +++ b/tests/002-test-reject-disk-with-lvm-signature.sh @@ -7,6 +7,8 @@ test_lvm_sig() { local test_status=1 local testname=`basename "$0"` local vg_name="css-test-foo" + local tmplog=${WORKDIR}/tmplog + local errmsg="Wipe signatures using wipefs or use WIPE_SIGNATURES=true and retry." # Error out if any pre-existing volume group vg named css-test-foo if vg_exists "$vg_name"; then @@ -25,14 +27,22 @@ EOF done # Run container-storage-setup - $CSSBIN >> $LOGS 2>&1 - - # Css should fail. If it did not, then test failed. This is very crude - # check though as css can fail for so many reasons. A more precise check - # would be too check for exact error message. - [ $? -ne 0 ] && test_status=0 + $CSSBIN > $tmplog 2>&1 + rc=$? + cat $tmplog >> $LOGS 2>&1 + + # Test failed. + if [ $rc -ne 0 ]; then + if grep --no-messages -q "$errmsg" $tmplog; then + test_status=0 + else + echo "ERROR: $testname: $CSSBIN Failed for a reason other then \"$errmsg\"" >> $LOGS + fi + else + echo "ERROR: $testname: $CSSBIN Succeeded. Should have failed since LVM2_member signature exists on devices $devs" >> $LOGS + fi - cleanup $vg_name "$devs" + cleanup "$vg_name" "$devs" return $test_status } diff --git a/tests/libtest.sh b/tests/libtest.sh index fc49420..54cd2ed 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -50,6 +50,11 @@ vg_exists() { return 1 } +# Tests if the physical volume exists +pv_exists() { + pvs $1 >/dev/null 2>&1 +} + # Tests if the logical volume lv_name exists lv_exists() { local vg_name=$1 @@ -76,7 +81,14 @@ remove_pvs() { local dev devs=$1 pv for dev in $devs; do pv=$(lsblk -npl -o NAME "$dev" | tail -n +2 | head -1) - pvremove -y ${pv} >> $LOGS 2>&1 + # If lsblk output physical volume (pv) name, pv exists on partition. + if [ -n "$pv" ]; then + pvremove -y ${pv} >> $LOGS 2>&1 + # If lsblk output nothing, there might be a pv on block device. + # pv name would be same as block device name in this case. + elif pv_exists "$dev"; then + pvremove -y ${dev} >> $LOGS 2>&1 + fi done } @@ -125,8 +137,9 @@ cleanup() { outfile=$4 fi - - vgremove -y $vg_name >> $LOGS 2>&1 + if vg_exists "$vg_name"; then + vgremove -y $vg_name >> $LOGS 2>&1 + fi remove_pvs "$devs" remove_partitions "$devs" # After removing partitions let udev settle down. In some