Blame tests/p_kvdo/kvdo_runtest.sh

7bfb61
#!/bin/bash
7bfb61
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
7bfb61
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7bfb61
#
7bfb61
#   runtest.sh of VDO smoke test
7bfb61
#   Description: Check that VDO is able to read/write data and start/stop
7bfb61
#   Author: Andy Walsh <awalsh@redhat.com>
7bfb61
#   Vendored into sig-core-t_functional by Adam Saleh <asaleh@redhat.com>
7bfb61
#
7bfb61
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7bfb61
#
7bfb61
#   Copyright (c) 2018 Red Hat, Inc.
7bfb61
#
7bfb61
#   This program is free software: you can redistribute it and/or
7bfb61
#   modify it under the terms of the GNU General Public License as
7bfb61
#   published by the Free Software Foundation, either version 2 of
7bfb61
#   the License, or (at your option) any later version.
7bfb61
#
7bfb61
#   This program is distributed in the hope that it will be
7bfb61
#   useful, but WITHOUT ANY WARRANTY; without even the implied
7bfb61
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7bfb61
#   PURPOSE.  See the GNU General Public License for more details.
7bfb61
#
7bfb61
#   You should have received a copy of the GNU General Public License
7bfb61
#   along with this program. If not, see http://www.gnu.org/licenses/.
7bfb61
#
7bfb61
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7bfb61
Adam Saleh 4ed491
# only run on centos 8 for now
Adam Saleh 4ed491
if [ "$centos_ver" -ne "8" ]; then
Adam Saleh 4ed491
  t_Log "non c8 => SKIPPING"
Adam Saleh 4ed491
  exit 0
Adam Saleh 4ed491
fi
Adam Saleh 4ed491
7bfb61
# Include Beaker environment
7bfb61
. /usr/share/beakerlib/beakerlib.sh || exit 1
7bfb61
7bfb61
arch=$(uname -m)
7bfb61
7bfb61
function insertModuleWithDMesgOutput() {
7bfb61
        moduleName=$1
7bfb61
7bfb61
        modulePath=$(rpm -ql kmod-kvdo | grep "${1}.ko$")
7bfb61
7bfb61
        exitVal=0
7bfb61
        rlRun "dmesg -c > /dev/null"
7bfb61
        rlRun "insmod ${modulePath}" || exitVal=255
7bfb61
        rlRun "dmesg"
7bfb61
7bfb61
        if [ ${exitVal} -ne 0 ]; then
7bfb61
          rlDie "Exiting with failure due to module/kernel incompatibility"
7bfb61
        fi
7bfb61
}
7bfb61
7bfb61
# Check whether we received URLs (via environment variables), and if not, let
7bfb61
# the system just use the enabled repositories to install the packages.
7bfb61
if [ -z ${kvdo_version} ] || [ -z ${kvdo_release} ]; then
7bfb61
        kvdo_pkg=kmod-kvdo
7bfb61
else
7bfb61
        kvdo_pkg=${brew_base_url}/kmod-kvdo/${kvdo_version}/${kvdo_release}/${arch}/kmod-kvdo-${kvdo_version}-${kvdo_release}.${arch}.rpm
7bfb61
fi
7bfb61
7bfb61
if [ -z ${vdo_version} ] || [ -z ${vdo_release} ]; then
7bfb61
        vdo_pkg=vdo
7bfb61
else
7bfb61
        vdo_pkg=${brew_base_url}/vdo/${vdo_version}/${vdo_release}/${arch}/vdo-${vdo_version}-${vdo_release}.${arch}.rpm
7bfb61
fi
7bfb61
7bfb61
rlJournalStart
7bfb61
7bfb61
rlPhaseStartSetup "Create backing device"
7bfb61
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
7bfb61
        rlRun "pushd $TmpDir"
7bfb61
        rlRun "df ."
7bfb61
7bfb61
        # If we end up with less than 10G of available space, then we can't
7bfb61
        # create a VDO volume sufficient for testing.  We should bail out as a
7bfb61
        # result.
7bfb61
        loopbackSize=$(($(df --sync --output=avail / | tail -1) * 1024 - 1024*1024*1024))
7bfb61
        if [ ${loopbackSize} -lt $((1024*1024*1024*10)) ]; then
7bfb61
          rlDie "Not enough space to create loopback device."
7bfb61
        fi
7bfb61
        rlRun "truncate -s ${loopbackSize} $TmpDir/loop0.bin" 0 "Laying out loopfile backing"
7bfb61
        rlRun "losetup /dev/loop0 $TmpDir/loop0.bin" 0 "Creating loopdevice"
7bfb61
        rlRun "mkdir -p /mnt/testmount" 0 "Creating test mountpoint dir"
7bfb61
rlPhaseEnd
7bfb61
7bfb61
rlPhaseStartSetup "Install software"
7bfb61
        if ! rlCheckRpm kmod-kvdo
7bfb61
        then
7bfb61
                rlRun "yum install -y ${kvdo_pkg}" 0 "Installing kmod-kvdo" || rlDie "Unable to install 'kmod-kvdo' package"
7bfb61
        	rlAssertRpm kmod-kvdo
7bfb61
        fi
7bfb61
        if ! rlCheckRpm vdo
7bfb61
        then
7bfb61
                rlRun "yum install -y ${vdo_pkg}" 0 "Installing vdo" || rlDie "Unable to install 'vdo' package"
7bfb61
        	rlAssertRpm vdo
7bfb61
        fi
7bfb61
rlPhaseEnd
7bfb61
7bfb61
rlPhaseStartTest "Gather Relevant Info"
7bfb61
        # Gather some system information for debug purposes
7bfb61
        rlRun "uname -a"
7bfb61
        rlRun "find /lib/modules -name kvdo.ko"
7bfb61
        rlRun "modinfo uds" || insertModuleWithDMesgOutput uds
7bfb61
        rlRun "modinfo kvdo" || insertModuleWithDMesgOutput kvdo
7bfb61
rlPhaseEnd
7bfb61
7bfb61
rlPhaseStartTest "Generate Test Data"
7bfb61
        # Write some data, check statistics
7bfb61
        rlRun "dd if=/dev/urandom of=${TmpDir}/urandom_fill_file bs=1M count=100"
7bfb61
        rlRun "ls -lh ${TmpDir}/urandom_fill_file"
7bfb61
rlPhaseEnd
7bfb61
7bfb61
for partition_type in "raw" "lvm" "part"
7bfb61
do
7bfb61
        case $partition_type in
7bfb61
                "raw"*)
7bfb61
                        backing_device=/dev/loop0
7bfb61
                        ;;
7bfb61
                "lvm"*)
7bfb61
                        rlPhaseStartTest "Create LVM backing device"
7bfb61
                                rlRun "pvcreate /dev/loop0" 0 "Creating PV"
7bfb61
                                rlRun "vgcreate vdo_base /dev/loop0" 0 "Creating VG"
7bfb61
                                rlRun "lvcreate -n vdo_base -l100%FREE vdo_base" 0 "Creating LV"
7bfb61
                        rlPhaseEnd
7bfb61
                        backing_device=/dev/vdo_base/vdo_base
7bfb61
                        ;;
7bfb61
                "part"*)
7bfb61
                        rlPhaseStartTest "Create partitioned backing device"
7bfb61
                                rlRun "parted -s /dev/loop0 mklabel msdos" 0 "Creating label"
7bfb61
                                rlRun 'parted -s /dev/loop0 mkpart primary "" 1M -- -1M' 0 "Creating partition"
7bfb61
                        rlPhaseEnd
7bfb61
                        backing_device=/dev/loop0p1
7bfb61
                        ;;
7bfb61
                *)
7bfb61
                        ;;
7bfb61
        esac
7bfb61
7bfb61
        rlPhaseStartTest "Smoke Test"
7bfb61
                # Create the VDO volume and get the initial statistics
7bfb61
                rlRun "vdo create --name=vdo1 --device=${backing_device} --verbose" 0 "Creating VDO volume vdo1"
7bfb61
                rlRun "vdostats vdo1"
7bfb61
7bfb61
                # Create a filesystem and mount the device, check statistics
7bfb61
                rlRun "mkfs.xfs -K /dev/mapper/vdo1" 0 "Making xfs filesystem on VDO volume"
7bfb61
                rlRun "mount -o discard /dev/mapper/vdo1 /mnt/testmount" 0 "Mounting xfs filesystem on VDO volume"
7bfb61
                rlRun "df --sync /mnt/testmount"
7bfb61
                rlRun "vdostats vdo1"
7bfb61
7bfb61
                # Copy the test data onto VDO volume 4 times to get some deduplication
7bfb61
                for i in {1..4}
7bfb61
                do
7bfb61
                  rlRun "cp ${TmpDir}/urandom_fill_file /mnt/testmount/test_file-${i}"
7bfb61
                done
7bfb61
                rlRun "df --sync /mnt/testmount"
7bfb61
                rlRun "vdostats vdo1"
7bfb61
7bfb61
                # Verify the data
7bfb61
                for i in {1..4}
7bfb61
                do
7bfb61
                        rlRun "cmp ${TmpDir}/urandom_fill_file /mnt/testmount/test_file-${i}"
7bfb61
                done
7bfb61
7bfb61
                # Unmount and stop the volume, check statistics
7bfb61
                rlRun "umount /mnt/testmount" 0 "Unmounting testmount"
7bfb61
                rlRun "vdostats vdo1"
7bfb61
                rlRun "vdo stop --name=vdo1 --verbose" 0 "Stopping VDO volume vdo1"
7bfb61
7bfb61
                # Start the VDO volume, mount it, check statistics, verify data.
7bfb61
                rlRun "vdo start --name=vdo1 --verbose" 0 "Starting VDO volume vdo1"
7bfb61
                rlRun "mount -o discard /dev/mapper/vdo1 /mnt/testmount" 0 "Mounting xfs filesystem on VDO volume"
7bfb61
7bfb61
                rlRun "df --sync /mnt/testmount"
7bfb61
                rlRun "vdostats vdo1"
7bfb61
7bfb61
                # Verify the data
7bfb61
                for i in {1..4}
7bfb61
                do
7bfb61
                        rlRun "cmp ${TmpDir}/urandom_fill_file /mnt/testmount/test_file-${i}"
7bfb61
                done
7bfb61
        rlPhaseEnd
7bfb61
7bfb61
        rlPhaseStartCleanup
7bfb61
                rlRun "umount /mnt/testmount" 0 "Unmounting testmount"
7bfb61
                rlRun "vdo remove --name=vdo1 --verbose" 0 "Removing VDO volume vdo1"
7bfb61
                case $partition_type in
7bfb61
                        "lvm"*)
7bfb61
                                rlPhaseStartCleanup
7bfb61
                                        rlRun "lvremove -ff ${backing_device}" 0 "Removing LV"
7bfb61
                                        rlRun "vgremove vdo_base" 0 "Removing VG"
7bfb61
                                        rlRun "pvremove /dev/loop0" 0 "Removing PV"
7bfb61
                                rlPhaseEnd
7bfb61
                                ;;
7bfb61
                        "part"*)
7bfb61
                                rlPhaseStartCleanup
7bfb61
                                    rlRun "parted -s /dev/loop0 rm 1" 0 "Removing partition"
7bfb61
                                rlPhaseEnd
7bfb61
                                ;;
7bfb61
                        *)
7bfb61
                                ;;
7bfb61
                esac
7bfb61
7bfb61
                rlRun "dd if=/dev/zero of=/dev/loop0 bs=1M count=10 oflag=direct" 0 "Wiping Block Device"
7bfb61
7bfb61
        rlPhaseEnd
7bfb61
done
7bfb61
7bfb61
rlPhaseStartCleanup
7bfb61
        rlRun "losetup -d /dev/loop0" 0 "Deleting loopdevice"
7bfb61
        rlRun "rm -f $TmpDir/loop0.bin" 0 "Removing loopfile backing"
7bfb61
        rlRun "popd"
7bfb61
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
7bfb61
rlPhaseEnd
7bfb61
7bfb61
rlJournalPrintText
7bfb61
rlJournalEnd