Skip to content

Commit 919d4da

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

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

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

Lines changed: 17 additions & 7 deletions
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,14 +27,22 @@ 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 "$vg_name" "$devs"
3646
return $test_status
3747
}
3848

tests/libtest.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ vg_exists() {
5050
return 1
5151
}
5252

53+
# Tests if the physical volume exists
54+
pv_exists() {
55+
pvs $1 >/dev/null 2>&1
56+
}
57+
5358
# Tests if the logical volume lv_name exists
5459
lv_exists() {
5560
local vg_name=$1
@@ -76,7 +81,14 @@ remove_pvs() {
7681
local dev devs=$1 pv
7782
for dev in $devs; do
7883
pv=$(lsblk -npl -o NAME "$dev" | tail -n +2 | head -1)
79-
pvremove -y ${pv} >> $LOGS 2>&1
84+
# If lsblk output physical volume (pv) name, pv exists on partition.
85+
if [ -n "$pv" ]; then
86+
pvremove -y ${pv} >> $LOGS 2>&1
87+
# If lsblk output nothing, there might be a pv on block device.
88+
# pv name would be same as block device name in this case.
89+
elif pv_exists "$dev"; then
90+
pvremove -y ${dev} >> $LOGS 2>&1
91+
fi
8092
done
8193
}
8294

@@ -125,8 +137,9 @@ cleanup() {
125137
outfile=$4
126138
fi
127139

128-
129-
vgremove -y $vg_name >> $LOGS 2>&1
140+
if vg_exists "$vg_name"; then
141+
vgremove -y $vg_name >> $LOGS 2>&1
142+
fi
130143
remove_pvs "$devs"
131144
remove_partitions "$devs"
132145
# After removing partitions let udev settle down. In some

0 commit comments

Comments
 (0)