Commit 0488fd84 authored by Karol Latecki's avatar Karol Latecki Committed by Jim Harris
Browse files

vhost_test: update vhost ext4test for spdk vhost



- Renamed to integrity filesystem test
- Add detecting if qemu is installed
- Default vhost.conf using NVMe; ramdisk may be too small
  for copying & building both dpdk and spdk
- Use kernel source (present on VM) for running test compilation
- rename to integrity test

Change-Id: Id369a5aac3008700cffbc51a5197b72f10645a1b
Signed-off-by: default avatarKarol Latecki <karolx.latecki@intel.com>
parent 1edd9bf3
Loading
Loading
Loading
Loading

test/vhost/ext4test/ext4start.sh

deleted100755 → 0
+0 −101
Original line number Diff line number Diff line
#!/usr/bin/env bash

testdir=$(readlink -f $(dirname $0))
rootdir=$testdir/../../..
source $rootdir/scripts/autotest_common.sh

if [ -z "$VM_IMG" ]; then
    echo "VM_IMG: path to qcow2 image not provided - not running"
    exit 1
fi

if [ -z "$VM_QEMU" ]; then
    echo "VM_QEMU: path to qemu binary not provided - not running"
    exit 1
fi

HOST_IP=192.168.122.1
VM_IP=192.168.122.254
VM_UNAME="root"
VM_PASS="root"
VM_NAME="ext4test_vm"
VM_NET_NAME="test_net"
VM_MAC="02:de:ad:de:ad:01"
VM_BAK_IMG="/tmp/ext4test_backing.img"
TIMEO=60
SSHCMD="sshpass -p $VM_PASS ssh"
SCPCMD="sshpass -p $VM_PASS scp"

function cleanup_virsh() {
    virsh destroy $VM_NAME
    virsh net-destroy $VM_NET_NAME
    rm $VM_BAK_IMG
}

timing_enter ext4test

qemu-img create -f qcow2 -o backing_file=$VM_IMG $VM_BAK_IMG

cp $testdir/spdk_vm_base.xml $testdir/spdk_vm.xml
cp $testdir/spdk_vnet_base.xml $testdir/spdk_vnet.xml

cp $testdir/vhost.conf.in $testdir/vhost.conf
$rootdir/scripts/gen_nvme.sh >> $testdir/vhost.conf

sed -i "s@<name></name>@<name>$VM_NAME</name>@g" $testdir/spdk_vm.xml
sed -i "s@source file=''@source file='$VM_BAK_IMG'@g" $testdir/spdk_vm.xml
sed -i "s@<emulator></emulator>@<emulator>$VM_QEMU</emulator>@g" $testdir/spdk_vm.xml
sed -i "s@<name></name>@<name>$VM_NET_NAME</name>@g" $testdir/spdk_vnet.xml

trap "cleanup_virsh; killprocess $pid; exit 1" SIGINT SIGTERM EXIT

virsh net-create $testdir/spdk_vnet.xml

# Change directory and ownership because virsh has issues with
# paths that are in /root tree
cd /tmp
$rootdir/app/vhost/vhost -c $testdir/vhost.conf &
pid=$!
echo "Process pid: $pid"
sleep 10
chmod 777 /tmp/naa.123

tar --exclude '.git' --exclude 'spdk.tgz' --exclude '*.d' --exclude '*.o' -zcf /tmp/spdk_host.tgz $rootdir

virsh create $testdir/spdk_vm.xml
virsh net-update $VM_NET_NAME add ip-dhcp-host "<host mac='$VM_MAC' name='$VM_NAME' ip='$VM_IP'/>"

# Wait for VM to boot, disable trap temporarily
# so that we don't exit on first fail
echo "Trying to connect to virtual machine..."
trap - SIGINT SIGTERM EXIT
set +xe
rc=-1
while [[ $TIMEO -gt 0 && rc -ne 0 ]]; do
    $SSHCMD root@$VM_IP -q -oStrictHostKeyChecking=no 'echo Hello'
    rc=$?
    ((TIMEO-=1))
done
set -xe
trap "cleanup_virsh; killprocess $pid; exit 1" SIGINT SIGTERM EXIT

if [[ $TIMEO -eq 0  ||  rc -ne 0 ]]; then
    echo "VM did not boot properly, exiting"
    exit 1
fi

$SSHCMD root@$VM_IP 'mkdir -p /tmp/spdk'
$SCPCMD -r /tmp/spdk_host.tgz root@$VM_IP:/tmp/spdk
$SSHCMD root@$VM_IP 'cd /tmp/spdk; tar xf spdk_host.tgz'
$SSHCMD root@$VM_IP '/tmp/spdk/test/vhost/ext4test/ext4connect.sh'

#read -p "Hit enter to exit..."

trap - SIGINT SIGTERM EXIT

cleanup_virsh
rm $testdir/spdk_vm.xml
rm $testdir/spdk_vnet.xml
rm $testdir/vhost.conf
killprocess $pid
timing_exit ext4test
+0 −11
Original line number Diff line number Diff line
<?xml version="1.0"?>
<network>
  <name/>
  <bridge name="virbr123"/>
  <forward/>
  <ip address="192.168.122.1" netmask="255.255.255.0">
    <dhcp>
      <range end="192.168.122.254" start="192.168.122.2"/>
    </dhcp>
  </ip>
</network>
+68 −0
Original line number Diff line number Diff line
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name></name>
  <memory unit='GiB'>4</memory>
  <currentMemory unit='GiB'>4</currentMemory>
  <vcpu placement='static'>8</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-1.6'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu mode='host-model'>
    <model fallback='allow'/>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator></emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file=''/>
			<backingStore/>
      <target dev='hda' bus='ide'/>
      <address type='drive' domain='0' bus='0' slot='0' function='0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <interface type='network'>
      <mac address=''/>
      <source network=''/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <video>
      <model type='cirrus' vram='16384' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </memballoon>
  </devices>
    <qemu:commandline>
        <qemu:arg value='-object'/>
    <qemu:arg value='memory-backend-file,id=mem,size=4096M,mem-path=/dev/hugepages,share=on'/>
        <qemu:arg value='-numa'/>
    <qemu:arg value='node,memdev=mem'/>
    <qemu:arg value='-chardev'/>
    <qemu:arg value='socket,id=char0,path=/tmp/naa.0'/>
        <qemu:arg value='-device'/>
    <qemu:arg value='vhost-user-scsi-pci,id=scsi0,chardev=char0'/>
    </qemu:commandline>
</domain>
+8 −0
Original line number Diff line number Diff line
<network>
    <name></name>
    <bridge name="int_test_br" />
    <forward />
    <ip address="192.200.200.1" netmask="255.255.255.0">
        <dhcp><range end="192.200.200.254" start="192.200.200.2" /></dhcp>
    </ip>
</network>
+158 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash

basedir=$(readlink -f $(dirname $0))
rootdir=$basedir/../../..
testdir=$rootdir/..
qemu_src_dir="$testdir/qemu"
qemu_build_dir="$testdir/qemu/build"
qemu_install_dir="$testdir/root"
MAKE="make -j$(( $(nproc)  * 2 ))"

source $rootdir/scripts/autotest_common.sh

if [ -z "$VM_IMG" ]; then
    echo "ERROR: VM_IMG: path to qcow2 image not provided - not running"
    exit 1
fi

if [ -z "$VM_QEMU" ]; then
    echo "INFO: VM_QEMU: path to qemu binary not provided"
    echo "INFO: Will use qemu from repository"
fi

if [ -z "$VM_FS" ]; then
    VM_FS="ext4"
    echo "INFO: Using default value for filesystem: $VM_FS"
fi

HOST_IP=192.200.200.1
VM_IP=192.200.200.254
VM_UNAME="root"
VM_PASS="root"
VM_NAME="int_test_vm"
VM_NET_NAME="int_test_net"
VM_MAC="02:de:ad:de:ad:01"
VM_BAK_IMG="/tmp/int_test_backing.img"
TIMEO=60
SSHCMD="sshpass -p $VM_PASS ssh"
SCPCMD="sshpass -p $VM_PASS scp"

echo "FS: $VM_FS"

function cleanup_virsh() {
    virsh shutdown $VM_NAME || true
    sleep 5
    virsh net-destroy $VM_NET_NAME || true
    rm $VM_BAK_IMG || true
}

timing_enter integrity_test

# If no VM_QEMU argument is given - check if needed qemu is installed
echo "INFO: Checking qemu..."
if [[ ! -d $qemu_src_dir && -z "$VM_QEMU" ]]; then
    echo "INFO: Cloning $qemu_src_dir"
    rm -rf $qemu_src_dir
    mkdir -p $qemu_src_dir
    cd $(dirname $qemu_src_dir)
    git clone -b dev/vhost_scsi ssh://az-sg-sw01.ch.intel.com:29418/qemu
    echo "INFO: Cloning Qemu Done"
else
    echo "INFO: Qemu source exist $qemu_src_dir - not cloning"
fi

# Check if Qemu binary is present; build it if not
if [[ ! -x $qemu_install_dir/bin/qemu-system-x86_64 && -z "$VM_QEMU" ]]; then
    echo "INFO: Can't find $qemu_install_dir/bin/qemu-system-x86_64 - building and installing"
    mkdir -p $qemu_build_dir
    cd $qemu_build_dir

    $qemu_src_dir/configure --prefix=$qemu_install_dir \
    --target-list="x86_64-softmmu" \
    --enable-kvm --enable-linux-aio --enable-numa

    echo "INFO: Compiling and installing QEMU in $qemu_install_dir"
    $MAKE install
    VM_QEMU="$qemu_install_dir/bin/qemu-system-x86_64"
    echo "INFO: DONE"
elif [[ -z "$VM_QEMU" ]]; then
    VM_QEMU="$qemu_install_dir/bin/qemu-system-x86_64"
fi

# Backing image for VM
qemu-img create -f qcow2 -o backing_file=$VM_IMG $VM_BAK_IMG

# Prepare vhost config
cp $basedir/vhost.conf.in $basedir/vhost.conf
$rootdir/scripts/gen_nvme.sh >> $basedir/vhost.conf

# Prepare .xml files for Virsh
cp $basedir/base_vm.xml $basedir/vm_conf.xml
cp $basedir/base_vnet.xml $basedir/vnet_conf.xml
sed -i "s@<name></name>@<name>$VM_NAME</name>@g" $basedir/vm_conf.xml
sed -i "s@source file=''@source file='$VM_BAK_IMG'@g" $basedir/vm_conf.xml
sed -i "s@<emulator></emulator>@<emulator>$VM_QEMU</emulator>@g" $basedir/vm_conf.xml
sed -i "s@mac address=''@mac address='$VM_MAC'@g" $basedir/vm_conf.xml
sed -i "s@source network=''@source network='$VM_NET_NAME'@g" $basedir/vm_conf.xml
sed -i "s@<name></name>@<name>$VM_NET_NAME</name>@g" $basedir/vnet_conf.xml

trap "cleanup_virsh; killprocess $pid; exit 1" SIGINT SIGTERM EXIT

virsh net-create $basedir/vnet_conf.xml

# Change directory and ownership because virsh has issues with
# paths that are in /root tree
cd /tmp
$rootdir/app/vhost/vhost -c $basedir/vhost.conf &
pid=$!
echo "Process pid: $pid"
sleep 10
chmod 777 /tmp/naa.0

virsh create $basedir/vm_conf.xml
virsh net-update $VM_NET_NAME add ip-dhcp-host "<host mac='$VM_MAC' name='$VM_NAME' ip='$VM_IP'/>"

# Wait for VM to boot, disable trap temporarily
# so that we don't exit on first fail
echo "INFO: Trying to connect to virtual machine..."
trap - SIGINT SIGTERM EXIT
set +xe
rc=-1
while [[ $TIMEO -gt 0 && rc -ne 0 ]]; do
    $SSHCMD root@$VM_IP -q -oStrictHostKeyChecking=no 'echo Hello'
    rc=$?
    ((TIMEO-=1))
done
set -xe
trap "cleanup_virsh; killprocess $pid; exit 1" SIGINT SIGTERM EXIT

if [[ $TIMEO -eq 0  ||  rc -ne 0 ]]; then
    echo "ERROR: VM did not boot properly, exiting"
    exit 1
fi

# Run test on Virtual Machine
$SCPCMD -r $basedir/integrity_vm.sh root@$VM_IP:~
$SSHCMD root@$VM_IP "fs=$VM_FS ~/integrity_vm.sh"

# Kill VM, cleanup config files
cleanup_virsh
rm $basedir/vm_conf.xml || true
rm $basedir/vnet_conf.xml || true
rm $basedir/vhost.conf || true

# Try to gracefully stop spdk vhost
if /bin/kill -INT $pid; then
    while /bin/kill -0 $pid; do
        sleep 1
    done
elif /bin/kill -0 $pid; then
    killprocess $pid
    echo "ERROR: Vhost was not closed gracefully..."
    exit 1
else
    exit 1
fi

trap - SIGINT SIGTERM EXIT
timing_exit integrity_test
Loading