Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 002-test-reject-disk-with-lvm-signature.sh #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 16 additions & 3 deletions tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down