Skip to content

Commit bfe4e40

Browse files
author
Shishir Mahajan
committed
Fix: 002-test-reject-disk-with-lvm-signature.sh
Signed-off-by: Shishir Mahajan <[email protected]>
1 parent 0d18761 commit bfe4e40

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

tests/002-test-reject-disk-with-lvm-signature.sh

+25-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ test_lvm_sig() {
77
local test_status=1
88
local testname=`basename "$0"`
99
local vg_name="css-test-foo"
10+
local tmplog=${WORKDIR}/tmplog
11+
local errmsg="Wipe signatures using wipefs or use WIPE_SIGNATURES=true and retry."
1012

1113
# Error out if any pre-existing volume group vg named css-test-foo
1214
if vg_exists "$vg_name"; then
@@ -25,17 +27,33 @@ EOF
2527
done
2628

2729
# Run container-storage-setup
28-
$CSSBIN >> $LOGS 2>&1
29-
30-
# Css should fail. If it did not, then test failed. This is very crude
31-
# check though as css can fail for so many reasons. A more precise check
32-
# would be too check for exact error message.
33-
[ $? -ne 0 ] && test_status=0
30+
$CSSBIN > $tmplog 2>&1
31+
rc=$?
32+
cat $tmplog >> $LOGS 2>&1
33+
34+
# Test failed.
35+
if [ $rc -ne 0 ]; then
36+
if grep --no-messages -q "$errmsg" $tmplog; then
37+
test_status=0
38+
else
39+
echo "ERROR: $testname: $CSSBIN Failed for a reason other then \"$errmsg\"" >> $LOGS
40+
fi
41+
else
42+
echo "ERROR: $testname: $CSSBIN Succeeded. Should have failed since LVM2_member signature exists on devices $devs" >> $LOGS
43+
fi
3444

35-
cleanup $vg_name "$devs"
45+
cleanup_pvs $devs
3646
return $test_status
3747
}
3848

49+
cleanup_pvs() {
50+
local devs=$1
51+
for dev in $devs; do
52+
pvremove -y ${dev} >> $LOGS 2>&1
53+
done
54+
wipe_signatures "$devs"
55+
}
56+
3957
# Make sure a disk with lvm signature is rejected and is not overriden
4058
# by css. Returns 0 on success and 1 on failure.
4159

tests/libtest.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ lv_exists() {
5858
return 1
5959
}
6060

61-
remove_pvs() {
61+
remove_pvs_part() {
6262
local dev devs=$1 pv
6363
for dev in $devs; do
6464
pv=$(lsblk -npl -o NAME "$dev" | tail -n +2 | head -1)
65-
pvremove -y ${pv} >> $LOGS 2>&1
65+
if [ -n "$pv" ];then
66+
pvremove -y ${pv} >> $LOGS 2>&1
67+
fi
6668
done
6769
}
6870

@@ -113,7 +115,7 @@ cleanup() {
113115

114116

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

0 commit comments

Comments
 (0)