Skip to content

Commit

Permalink
Integration tests: Handle partition names like loop0p1.
Browse files Browse the repository at this point in the history
Setting DEVS to a loop device partition e.g. /dev/loop0p1 should fail.

Signed-off-by: Shishir Mahajan <shishir.mahajan@redhat.com>

Closes: #234
Approved by: rhvgoyal
  • Loading branch information
Shishir Mahajan authored and rh-atomic-bot committed Apr 11, 2017
1 parent d8b5932 commit 0d18761
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/015-test-fail-loop-to-create-thin-pool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
source $SRCDIR/libtest.sh

test_fail_if_loop_partition_passed() {
local lbdevice tmpfile
local test_status=1
local testname=`basename "$0"`
local vg_name="css-test-foo"
local tmplog=${WORKDIR}/tmplog
local errmsg="Partition specification unsupported at this time."

# Error out if any pre-existing volume group vg named css-test-foo
if vg_exists "$vg_name"; then
echo "ERROR: $testname: Volume group $vg_name already exists." >> $LOGS
return $test_status
fi

# Create loopback device.
tmpfile=$(mktemp /tmp/c-s-s.XXXXXX)
truncate --size=6G $tmpfile
lbdevice=$(losetup -f)
losetup --partscan $lbdevice $tmpfile
if ! create_partition $lbdevice;then
echo "ERROR: Failed partitioning $lbdevice"
cleanup_loop_device "$tmpfile" "$lbdevice"
return $test_status
fi

cat << EOF > /etc/sysconfig/docker-storage-setup
DEVS="${lbdevice}p1"
VG=$vg_name
EOF

# Run container-storage-setup
$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 ${lbdevice}p1 is a loop device partition." >> $LOGS
fi
cleanup $vg_name "$lbdevice"
cleanup_loop_device "$tmpfile" "$lbdevice"
return $test_status
}

cleanup_loop_device() {
local tmpfile=$1
local lbdevice=$2
losetup -d $lbdevice
rm $tmpfile > /dev/null 2>&1
}

# Make sure command fails if loop device partition /dev/loop0p1 is passed.
test_fail_if_loop_partition_passed

65 changes: 65 additions & 0 deletions tests/115-test-fail-loop-to-create-thin-pool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
source $SRCDIR/libtest.sh

test_fail_if_loop_partition_passed() {
local lbdevice tmpfile
local test_status=1
local testname=`basename "$0"`
local vg_name="css-test-foo"
local infile=${WORKDIR}/container-storage-setup
local outfile=${WORKDIR}/container-storage
local tmplog=${WORKDIR}/tmplog
local errmsg="Partition specification unsupported at this time."

# Error out if any pre-existing volume group vg named css-test-foo
if vg_exists "$vg_name"; then
echo "ERROR: $testname: Volume group $vg_name already exists." >> $LOGS
return $test_status
fi

# Create loopback device.
tmpfile=$(mktemp /tmp/c-s-s.XXXXXX)
truncate --size=6G $tmpfile
lbdevice=$(losetup -f)
losetup --partscan $lbdevice $tmpfile
if ! create_partition $lbdevice;then
echo "ERROR: Failed partitioning $lbdevice"
cleanup_loop_device "$tmpfile" "$lbdevice"
return $test_status
fi

cat << EOF > $infile
DEVS="${lbdevice}p1"
VG=$vg_name
CONTAINER_THINPOOL=container-thinpool
EOF

# Run container-storage-setup
$CSSBIN $infile $outfile > $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 ${lbdevice}p1 is a loop device partition." >> $LOGS
fi
cleanup $vg_name "$lbdevice" "$infile" "$outfile"
cleanup_loop_device "$tmpfile" "$lbdevice"
return $test_status
}

cleanup_loop_device() {
local tmpfile=$1
local lbdevice=$2
losetup -d $lbdevice
rm $tmpfile > /dev/null 2>&1
}

# Make sure command fails if loop device partition /dev/loop0p1 is passed.
test_fail_if_loop_partition_passed

0 comments on commit 0d18761

Please sign in to comment.