Skip to content

Commit 0f306f0

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 0f306f0

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_sig $devs
3646
return $test_status
3747
}
3848

49+
cleanup_pvs_sig() {
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
@@ -72,11 +72,13 @@ lv_is_active() {
7272
return 1
7373
}
7474

75-
remove_pvs() {
75+
remove_pvs_part() {
7676
local dev devs=$1 pv
7777
for dev in $devs; do
7878
pv=$(lsblk -npl -o NAME "$dev" | tail -n +2 | head -1)
79-
pvremove -y ${pv} >> $LOGS 2>&1
79+
if [ -n "$pv" ];then
80+
pvremove -y ${pv} >> $LOGS 2>&1
81+
fi
8082
done
8183
}
8284

@@ -127,7 +129,7 @@ cleanup() {
127129

128130

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

0 commit comments

Comments
 (0)