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 11, 2017
1 parent 0d18761 commit bfe4e40
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
32 changes: 25 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,17 +27,33 @@ 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_pvs $devs
return $test_status
}

cleanup_pvs() {
local devs=$1
for dev in $devs; do
pvremove -y ${dev} >> $LOGS 2>&1
done
wipe_signatures "$devs"
}

# Make sure a disk with lvm signature is rejected and is not overriden
# by css. Returns 0 on success and 1 on failure.

Expand Down
8 changes: 5 additions & 3 deletions tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ lv_exists() {
return 1
}

remove_pvs() {
remove_pvs_part() {
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 [ -n "$pv" ];then
pvremove -y ${pv} >> $LOGS 2>&1
fi
done
}

Expand Down Expand Up @@ -113,7 +115,7 @@ cleanup() {


vgremove -y $vg_name >> $LOGS 2>&1
remove_pvs "$devs"
remove_pvs_part "$devs"
remove_partitions "$devs"
# After removing partitions let udev settle down. In some
# cases it has been observed that udev rule kept the device
Expand Down

0 comments on commit bfe4e40

Please sign in to comment.