Skip to content

Commit 206504a

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 206504a

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

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

+17-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,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

+24-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ vg_exists() {
5050
return 1
5151
}
5252

53+
# Tests if the physical volume pv_name exists
54+
pv_exists() {
55+
local pv pv_name="$1"
56+
57+
for pv in $(pvs --noheadings -o pv_name); do
58+
if [ "$pv" == "$pv_name" ]; then
59+
return 0
60+
fi
61+
done
62+
return 1
63+
}
64+
65+
5366
# Tests if the logical volume lv_name exists
5467
lv_exists() {
5568
local vg_name=$1
@@ -76,7 +89,14 @@ remove_pvs() {
7689
local dev devs=$1 pv
7790
for dev in $devs; do
7891
pv=$(lsblk -npl -o NAME "$dev" | tail -n +2 | head -1)
79-
pvremove -y ${pv} >> $LOGS 2>&1
92+
# If lsblk output physical volume (pv) name, pv exists on partition.
93+
if [ -n "$pv" ]; then
94+
pvremove -y ${pv} >> $LOGS 2>&1
95+
# If lsblk output nothing, there might be a pv on block device.
96+
# pv name would be same as block device name in this case.
97+
elif pv_exists "$dev"; then
98+
pvremove -y ${dev} >> $LOGS 2>&1
99+
fi
80100
done
81101
}
82102

@@ -125,8 +145,9 @@ cleanup() {
125145
outfile=$4
126146
fi
127147

128-
129-
vgremove -y $vg_name >> $LOGS 2>&1
148+
if vg_exists "$vg_name"; then
149+
vgremove -y $vg_name >> $LOGS 2>&1
150+
fi
130151
remove_pvs "$devs"
131152
remove_partitions "$devs"
132153
# After removing partitions let udev settle down. In some

0 commit comments

Comments
 (0)