Skip to content

Commit

Permalink
Fix: 002-test-reject-disk-with-lvm-signature.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Shishir Mahajan <shishir.mahajan@redhat.com>
  • Loading branch information
Shishir Mahajan committed Apr 19, 2017
1 parent 8276a1e commit 206504a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 17 additions & 7 deletions tests/002-test-reject-disk-with-lvm-signature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
27 changes: 24 additions & 3 deletions tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ vg_exists() {
return 1
}

# Tests if the physical volume pv_name exists
pv_exists() {
local pv pv_name="$1"

for pv in $(pvs --noheadings -o pv_name); do
if [ "$pv" == "$pv_name" ]; then
return 0
fi
done
return 1
}


# Tests if the logical volume lv_name exists
lv_exists() {
local vg_name=$1
Expand All @@ -76,7 +89,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
}

Expand Down Expand Up @@ -125,8 +145,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
Expand Down

0 comments on commit 206504a

Please sign in to comment.