raisin: introduce tests
v3 cover raisin: introduce tests
Hi all,
this patch series introduces a framework to execute simple unit and functional tests in raisin. It can be used by developers to validate their changes before submitting a patch series to xen-devel. It can also be used by OSSTest to test for regressions on one particular functionality. This patch series only introduces two tests: a PV guest creation test and an HVM guest creation test. They are both based on busybox. More tests will follow.
Changes in v3:
- source test scripts
- expose a _test and a _cleanup function from the test script
- add local migration test
Stefano Stabellini (5):
raisin: introduce tests
raisin: add an hvm test
raisin: improve output
raisin: small stlye improvement in for_each_component
raisin: introduce a local migration test
README | 14 ++++ components/grub | 4 +- components/libvirt | 4 +- components/linux | 2 +- components/ovmf | 6 +- components/qemu | 2 +- components/qemu_traditional | 2 +- components/seabios | 6 +- components/xen | 8 +- defconfig | 5 ++ lib/commands.sh | 22 +++--- lib/common-functions.sh | 147 ++++++++++++++++++++++++++++++------ lib/common-tests.sh | 174 +++++++++++++++++++++++++++++++++++++++++++ raise | 8 +- scripts/lopartsetup | 67 +++++++++++++++++ tests/busybox-hvm | 43 +++++++++++ tests/busybox-hvm-migrate | 33 ++++++++ tests/busybox-pv | 37 +++++++++ tests/series | 3 + 19 files changed, 537 insertions(+), 50 deletions(-) create mode 100644 lib/common-tests.sh create mode 100755 scripts/lopartsetup create mode 100755 tests/busybox-hvm create mode 100755 tests/busybox-hvm-migrate create mode 100755 tests/busybox-pv create mode 100644 tests/series
Cheers,
Stefano
PATCH v3 1/5 raisin: introduce tests
Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.
Add a simple test script that boots a single busybox based PV guest.
---
Changes in v3:
- source test scripts
- expose a _test and a _cleanup function from the test script
Changes in v2:
- use found as a boolean
- print error to stderr
--- README | 14 ++++++ defconfig | 5 +++ lib/commands.sh | 4 ++ lib/common-functions.sh | 77 ++++++++++++++++++++++++++++++++ lib/common-tests.sh | 112 +++++++++++++++++++++++++++++++++++++++++++++++ raise | 8 ++-- tests/busybox-pv | 37 ++++++++++++++++ tests/series | 1 + 8 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 lib/common-tests.sh create mode 100755 tests/busybox-pv create mode 100644 tests/series
README +14 -0
@@ -102,3 +102,17 @@ check-package If your component comes with additional data, maybe a config script or anything else, place it under "data". + + += Testing = + +Raisin can also be used for testing. Make sure to have Xen already up +and running (raise build, raise install and host reboot). +Ask Raisin to run tests like this: + +./raise test + +You can specify a subset of tests to run with ENABLED_TESTS in the +config file, or the TESTS environmental variable: + +TESTS="busybox-pv" ./raise test
defconfig +5 -0
@@ -39,3 +39,8 @@ GRUB_REVISION="master" LIBVIRT_REVISION="master" OVMF_REVISION="master" LINUX_REVISION="master" + +# Tests +## All tests: busybox-pv +## ENABLED_TESTS is the list of test run by raise test +ENABLED_TESTS="busybox-pv"
lib/commands.sh +4 -0
@@ -103,3 +103,7 @@ function configure() { for_each_component configure } +function test() { + init_tests + run_tests +}
lib/common-functions.sh +77 -0
95 lines not on this page · raw message
lib/common-tests.sh new file +112 -0
112 lines not on this page · raw message
raise +5 -3
@@ -3,7 +3,7 @@ set -e _help() { - echo "Usage: ./build.sh <options> <command>" + echo "Usage: ./raise <options> <command>" echo "where options are:" echo " -v | --verbose Verbose" echo " -y | --yes Do not ask questions and continue"
@@ -14,6 +14,7 @@ _help() { echo " install Install binaries under / (requires sudo)" echo " configure Configure the system (requires sudo)" echo " unraise Uninstall and unconfigure the system (requires sudo)" + echo " test Runs tests on the system (requires sudo, Xen must be running)" } # Include your defaults
@@ -25,10 +26,11 @@ fi source ./config # To use this as a library, set RAISIN_PATH appropriately -[[ -z "$RAISIN_PATH" ]] && RAISIN_PATH="$PWD/lib" +[[ -z "$RAISIN_PATH" ]] && export RAISIN_PATH="$PWD/lib" # Then as many as the sub-libraries as you need source ${RAISIN_PATH}/common-functions.sh +source ${RAISIN_PATH}/common-tests.sh source ${RAISIN_PATH}/git-checkout.sh source ${RAISIN_PATH}/commands.sh
@@ -59,7 +61,7 @@ do done case "$1" in - "install-builddep" | "build" | "install" | "configure" | "unraise" ) + "install-builddep" | "build" | "install" | "configure" | "unraise" | "test" ) COMMAND=$1 ;; *)
tests/busybox-pv new file +37 -0
@@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -e + +function busybox-pv-cleanup() { + $SUDO xl destroy raisin-test || true + umount $LOOP || true + cd "$BASEDIR" + $SUDO losetup -d $LOOP + rm -rf $TMPDIR +} + +function busybox-pv-test() { + TMPDIR=`mktemp -d` + cd $TMPDIR + + allocate_disk busybox-vm-disk $((20*1024*1024)) + LOOP=`create_loop busybox-vm-disk` + busybox_rootfs $LOOP + busybox_network_init $LOOP + + cat >busybox-pv <<EOF +kernel = "`get_host_kernel`" +ramdisk = "`get_host_initrd`" +extra = "root=/dev/xvda console=hvc0" +memory = 512 +name = "raisin-test" +vcpus = 2 +disk = [ '$LOOP,raw,xvda,w' ] +serial="pty" +boot="c" +vif=['bridge=xenbr1'] +EOF + + $SUDO xl create busybox-pv + check_guest_alive +}
tests/series new file +1 -0
@@ -0,0 +1 @@ +busybox-pv
Signature · 1 line
1.7.10.4
Quoted 198 lines · Stefano Stabellini
Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.
Add a simple test script that boots a single busybox based PV guest.
Signed-off-by Stefano Stabellini <[email protected]>---
Changes in v3:
- source test scripts
- expose a_testand a_cleanupfunction from the test scriptChanges in v2:
- use found as a boolean
- print error to stderr--- README | 14 ++++++ defconfig | 5 +++ lib/commands.sh | 4 ++ lib/common-functions.sh | 77 ++++++++++++++++++++++++++++++++ lib/common-tests.sh | 112 +++++++++++++++++++++++++++++++++++++++++++++++ raise | 8 ++-- tests/busybox-pv | 37 ++++++++++++++++ tests/series | 1 + 8 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 lib/common-tests.sh create mode 100755 tests/busybox-pv create mode 100644 tests/seriesREADME +14
-0@@ -102,3 +102,17 @@ check-package If your component comes with additional data, maybe a config script or anything else, place it under "data". + + += Testing = + +Raisin can also be used for testing. Make sure to have Xen already up +and running (raise build, raise install and host reboot). +Ask Raisin to run tests like this: + +./raise test + +You can specify a subset of tests to run with ENABLED_TESTS in the +config file, or the TESTS environmental variable: + +TESTS="busybox-pv" ./raise testdefconfig +5
-0@@ -39,3 +39,8 @@ GRUB_REVISION="master" LIBVIRT_REVISION="master" OVMF_REVISION="master" LINUX_REVISION="master" + +# Tests +## All tests: busybox-pv +## ENABLED_TESTS is the list of test run by raise test +ENABLED_TESTS="busybox-pv"lib/commands.sh +4
-0@@ -103,3 +103,7 @@ function configure() { for_each_component configure } +function test() { + init_tests + run_tests +}lib/common-functions.sh +77
-0@@ -39,6 +39,7 @@ function common_init() { get_distro get_arch get_components + get_tests verbose_echo "Distro: $DISTRO" verbose_echo "Arch: $RAISIN_ARCH"@@ -73,6 +74,24 @@ function get_components() { export COMPONENTS } +function get_tests() { + if [[ -z "$TESTS" ]] + then + TESTS="$ENABLED_TESTS" + fi + + if [[ -z "$TESTS" ]] + then + local t + for t in `cat "$BASEDIR"/tests/series` + do + TESTS="$TESTS $t" + verbose_echo "Found test $t" + done + fi + export TESTS +} + function get_distro() { if [[ -x "`which lsb_release 2>/dev/null`" ]] then@@ -278,6 +297,64 @@ function for_each_component () { done } +function run_tests() { + local t + local enabled + local found + + for t in `cat "$BASEDIR"/tests/series` + do + found=false + for enabled in $TESTS + do + if [[ $enabled = $t ]] + then + found=true + break + fi + done + if ! $found + then + verbose_echo "$t" is disabled + continue + fi + + source "$BASEDIR"/tests/$t + + verbose_echo running test "$t" + "$t"_test + "$t"_cleanup + verbose_echo "test "$t" done" + done +} + +function init_tests() { + local -a missing + + check-package bridge-utils + if [[ $DISTRO = "Debian" ]] + then + check-package busybox-static + elif [[ $DISTRO = "Fedora" ]] + then + check-package busybox grub2 which + else + echo "I don't know distro $DISTRO. It might be missing packages." + fi + + if [[ -n "${missing[@]}" ]] + then + verbose_echo "Installing ${missing[@]}" + install-package "${missing[@]}" + fi + + if ! ifconfig xenbr1 &>/dev/null + then + $SUDO brctl addbr xenbr1 + $SUDO ifconfig xenbr1 169.254.0.1 up + fi +} + function _build_package_deb() { fakeroot bash ./scripts/mkdeb "$1" }lib/common-tests.sh new file +8
-0@@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +source ${RAISIN_PATH}/common-functions.sh + +# $1 disk name +# $2 disk size +function allocate_disk() { + local disk
lib/common-tests.sh line 18
Quoted 10 lines
lib/common-tests.sh new file +10
-0+ local size + + disk=$1 + size=$2 + + size=$((size+511)) + size=$((size/512)) + + dd if=/dev/zero of=$disk bs=512 count=$size + sync
This a lot faster if you use truncate:
function raw-create()
{
truncate -s "${size}"M "${image}"
}In addition, truncate makes the file sparse on most modern filesystems.
You might want to take a look at my testlib "lib/image.sh" for some more recipes.
Quoted 4 lines
lib/common-tests.sh new file +4
-0+} + +# $1 disk name +# print loop device name
lib/common-tests.sh line 32
Quoted 10 lines
lib/common-tests.sh new file +10
-0+function create_loop() { + local disk + local loop + + disk=`readlink -f $1` + + $SUDO losetup -f $disk + loop=`$SUDO losetup -a | grep $disk | cut -d : -f 1` + echo $loop +}
I think this is generally better done by attaching the disk to dom0; that way you can use the same code to initialize other kinds of disks and formats (e.g., qcow, vhd, &c).
But in both these cases I can send some patches to add these in later, I think. :-)
Quoted 174 lines
lib/common-tests.sh new file +80
-0+ +# $1 dev name +function busybox_rootfs() { + local dev + local tmpdir + + dev=$1 + + $SUDO mkfs.ext3 $dev + + tmpdir=`mktemp -d` + $SUDO mount $dev $tmpdir + mkdir -p $tmpdir/bin + mkdir -p $tmpdir/sbin + mkdir -p $tmpdir/dev + mkdir -p $tmpdir/proc + mkdir -p $tmpdir/sys + mkdir -p $tmpdir/lib + mkdir -p $tmpdir/var + cp `which busybox` $tmpdir/bin + $tmpdir/bin/busybox --install $tmpdir/bin + + $SUDO umount $tmpdir + rmdir $tmpdir +} + +function busybox_network_init() { + local dev + local tmpdir + + dev=$1 + tmpdir=`mktemp -d` + + $SUDO mount $dev $tmpdir + rm -f $tmpdir/bin/init + cat >$tmpdir/bin/init <<EOF +#!/bin/sh +mount -t proc proc /proc +mount -t sysfs sysfs /sys +ifconfig eth0 169.254.0.2 up +/bin/sh +EOF + chmod +x $tmpdir/bin/init + + $SUDO umount $tmpdir + rmdir $tmpdir +} + +function check_guest_alive() { + local i + i=0 + while ! ping -c 1 169.254.0.2 &> /dev/null + do + sleep 1 + i=$((i+1)) + if [[ $i -gt 60 ]] + then + echo Timeout connecting to guest + return 1 + fi + done + return 0 +} + +function get_host_kernel() { + echo "/boot/vmlinuz-`uname -r`" +} + +function get_host_initrd() { + if [[ $DISTRO = "Debian" ]] + then + echo "/boot/initrd.img-`uname -r`" + elif [[ $DISTRO = "Fedora" ]] + then + echo "/boot/initramfs-`uname -r`".img + else + echo "I don't know how to find the initrd" >&2 + exit 1 + fi +}raise +5
-3@@ -3,7 +3,7 @@ set -e _help() { - echo "Usage: ./build.sh <options> <command>" + echo "Usage: ./raise <options> <command>" echo "where options are:" echo " -v | --verbose Verbose" echo " -y | --yes Do not ask questions and continue"@@ -14,6 +14,7 @@ _help() { echo " install Install binaries under / (requires sudo)" echo " configure Configure the system (requires sudo)" echo " unraise Uninstall and unconfigure the system (requires sudo)" + echo " test Runs tests on the system (requires sudo, Xen must be running)" } # Include your defaults@@ -25,10 +26,11 @@ fi source ./config # To use this as a library, set RAISIN_PATH appropriately -[[ -z "$RAISIN_PATH" ]] && RAISIN_PATH="$PWD/lib" +[[ -z "$RAISIN_PATH" ]] && export RAISIN_PATH="$PWD/lib" # Then as many as the sub-libraries as you need source ${RAISIN_PATH}/common-functions.sh +source ${RAISIN_PATH}/common-tests.sh source ${RAISIN_PATH}/git-checkout.sh source ${RAISIN_PATH}/commands.sh@@ -59,7 +61,7 @@ do done case "$1" in - "install-builddep" | "build" | "install" | "configure" | "unraise" ) + "install-builddep" | "build" | "install" | "configure" | "unraise" | "test" ) COMMAND=$1 ;; *)tests/busybox-pv new file +37
-0@@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -e + +function busybox-pv-cleanup() { + $SUDO xl destroy raisin-test || true + umount $LOOP || true + cd "$BASEDIR" + $SUDO losetup -d $LOOP + rm -rf $TMPDIR +} + +function busybox-pv-test() { + TMPDIR=`mktemp -d` + cd $TMPDIR + + allocate_disk busybox-vm-disk $((20*1024*1024)) + LOOP=`create_loop busybox-vm-disk` + busybox_rootfs $LOOP + busybox_network_init $LOOP + + cat >busybox-pv <<EOF +kernel = "`get_host_kernel`" +ramdisk = "`get_host_initrd`" +extra = "root=/dev/xvda console=hvc0" +memory = 512 +name = "raisin-test" +vcpus = 2 +disk = [ '$LOOP,raw,xvda,w' ] +serial="pty" +boot="c" +vif=['bridge=xenbr1'] +EOF + + $SUDO xl create busybox-pv + check_guest_alive +}tests/series new file +1
-0@@ -0,0 +1 @@ +busybox-pv
Quoted 213 lines · George Dunlap
Quoted 198 lines · Stefano Stabellini
Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.
Add a simple test script that boots a single busybox based PV guest.
Signed-off-by Stefano Stabellini <[email protected]>---
Changes in v3:
- source test scripts
- expose a_testand a_cleanupfunction from the test scriptChanges in v2:
- use found as a boolean
- print error to stderr--- README | 14 ++++++ defconfig | 5 +++ lib/commands.sh | 4 ++ lib/common-functions.sh | 77 ++++++++++++++++++++++++++++++++ lib/common-tests.sh | 112 +++++++++++++++++++++++++++++++++++++++++++++++ raise | 8 ++-- tests/busybox-pv | 37 ++++++++++++++++ tests/series | 1 + 8 files changed, 255 insertions(+), 3 deletions(-) create mode 100644 lib/common-tests.sh create mode 100755 tests/busybox-pv create mode 100644 tests/seriesREADME +14
-0@@ -102,3 +102,17 @@ check-package If your component comes with additional data, maybe a config script or anything else, place it under "data". + + += Testing = + +Raisin can also be used for testing. Make sure to have Xen already up +and running (raise build, raise install and host reboot). +Ask Raisin to run tests like this: + +./raise test + +You can specify a subset of tests to run with ENABLED_TESTS in the +config file, or the TESTS environmental variable: + +TESTS="busybox-pv" ./raise testdefconfig +5
-0@@ -39,3 +39,8 @@ GRUB_REVISION="master" LIBVIRT_REVISION="master" OVMF_REVISION="master" LINUX_REVISION="master" + +# Tests +## All tests: busybox-pv +## ENABLED_TESTS is the list of test run by raise test +ENABLED_TESTS="busybox-pv"lib/commands.sh +4
-0@@ -103,3 +103,7 @@ function configure() { for_each_component configure } +function test() { + init_tests + run_tests +}lib/common-functions.sh +77
-0@@ -39,6 +39,7 @@ function common_init() { get_distro get_arch get_components + get_tests verbose_echo "Distro: $DISTRO" verbose_echo "Arch: $RAISIN_ARCH"@@ -73,6 +74,24 @@ function get_components() { export COMPONENTS } +function get_tests() { + if [[ -z "$TESTS" ]] + then + TESTS="$ENABLED_TESTS" + fi + + if [[ -z "$TESTS" ]] + then + local t + for t in `cat "$BASEDIR"/tests/series` + do + TESTS="$TESTS $t" + verbose_echo "Found test $t" + done + fi + export TESTS +} + function get_distro() { if [[ -x "`which lsb_release 2>/dev/null`" ]] then@@ -278,6 +297,64 @@ function for_each_component () { done } +function run_tests() { + local t + local enabled + local found + + for t in `cat "$BASEDIR"/tests/series` + do + found=false + for enabled in $TESTS + do + if [[ $enabled = $t ]] + then + found=true + break + fi + done + if ! $found + then + verbose_echo "$t" is disabled + continue + fi + + source "$BASEDIR"/tests/$t + + verbose_echo running test "$t" + "$t"_test + "$t"_cleanup + verbose_echo "test "$t" done" + done +} + +function init_tests() { + local -a missing + + check-package bridge-utils + if [[ $DISTRO = "Debian" ]] + then + check-package busybox-static + elif [[ $DISTRO = "Fedora" ]] + then + check-package busybox grub2 which + else + echo "I don't know distro $DISTRO. It might be missing packages." + fi + + if [[ -n "${missing[@]}" ]] + then + verbose_echo "Installing ${missing[@]}" + install-package "${missing[@]}" + fi + + if ! ifconfig xenbr1 &>/dev/null + then + $SUDO brctl addbr xenbr1 + $SUDO ifconfig xenbr1 169.254.0.1 up + fi +} + function _build_package_deb() { fakeroot bash ./scripts/mkdeb "$1" }lib/common-tests.sh new file +8
-0@@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +source ${RAISIN_PATH}/common-functions.sh + +# $1 disk name +# $2 disk size +function allocate_disk() { + local disklib/common-tests.sh line 18
Quoted 10 lines
lib/common-tests.sh new file +10
-0+ local size + + disk=$1 + size=$2 + + size=$((size+511)) + size=$((size/512)) + + dd if=/dev/zero of=$disk bs=512 count=$size + syncThis a lot faster if you use truncate:
function raw-create()
Quoted 8 lines
{ truncate -s "${size}"M "${image}" }In addition, truncate makes the file sparse on most modern filesystems.
You might want to take a look at my testlib "
lib/image.sh" for some more recipes.
Nice, I didn't know about it.
Quoted 19 lines
Quoted 4 lines
lib/common-tests.sh new file +4
-0+} + +# $1 disk name +# print loop device namelib/common-tests.sh line 32
Quoted 10 lines
lib/common-tests.sh new file +10
-0+function create_loop() { + local disk + local loop + + disk=`readlink -f $1` + + $SUDO losetup -f $disk + loop=`$SUDO losetup -a | grep $disk | cut -d : -f 1` + echo $loop +}I think this is generally better done by attaching the disk to dom0; that way you can use the same code to initialize other kinds of disks and formats (e.g., qcow, vhd, &c).
Quoted 2 lines
But in both these cases I can send some patches to add these in later, I think. :-)
OK, in that case I'll push my series as is.
Quoted 175 lines
Quoted 174 lines
lib/common-tests.sh new file +80
-0+ +# $1 dev name +function busybox_rootfs() { + local dev + local tmpdir + + dev=$1 + + $SUDO mkfs.ext3 $dev + + tmpdir=`mktemp -d` + $SUDO mount $dev $tmpdir + mkdir -p $tmpdir/bin + mkdir -p $tmpdir/sbin + mkdir -p $tmpdir/dev + mkdir -p $tmpdir/proc + mkdir -p $tmpdir/sys + mkdir -p $tmpdir/lib + mkdir -p $tmpdir/var + cp `which busybox` $tmpdir/bin + $tmpdir/bin/busybox --install $tmpdir/bin + + $SUDO umount $tmpdir + rmdir $tmpdir +} + +function busybox_network_init() { + local dev + local tmpdir + + dev=$1 + tmpdir=`mktemp -d` + + $SUDO mount $dev $tmpdir + rm -f $tmpdir/bin/init + cat >$tmpdir/bin/init <<EOF +#!/bin/sh +mount -t proc proc /proc +mount -t sysfs sysfs /sys +ifconfig eth0 169.254.0.2 up +/bin/sh +EOF + chmod +x $tmpdir/bin/init + + $SUDO umount $tmpdir + rmdir $tmpdir +} + +function check_guest_alive() { + local i + i=0 + while ! ping -c 1 169.254.0.2 &> /dev/null + do + sleep 1 + i=$((i+1)) + if [[ $i -gt 60 ]] + then + echo Timeout connecting to guest + return 1 + fi + done + return 0 +} + +function get_host_kernel() { + echo "/boot/vmlinuz-`uname -r`" +} + +function get_host_initrd() { + if [[ $DISTRO = "Debian" ]] + then + echo "/boot/initrd.img-`uname -r`" + elif [[ $DISTRO = "Fedora" ]] + then + echo "/boot/initramfs-`uname -r`".img + else + echo "I don't know how to find the initrd" >&2 + exit 1 + fi +}raise +5
-3@@ -3,7 +3,7 @@ set -e _help() { - echo "Usage: ./build.sh <options> <command>" + echo "Usage: ./raise <options> <command>" echo "where options are:" echo " -v | --verbose Verbose" echo " -y | --yes Do not ask questions and continue"@@ -14,6 +14,7 @@ _help() { echo " install Install binaries under / (requires sudo)" echo " configure Configure the system (requires sudo)" echo " unraise Uninstall and unconfigure the system (requires sudo)" + echo " test Runs tests on the system (requires sudo, Xen must be running)" } # Include your defaults@@ -25,10 +26,11 @@ fi source ./config # To use this as a library, set RAISIN_PATH appropriately -[[ -z "$RAISIN_PATH" ]] && RAISIN_PATH="$PWD/lib" +[[ -z "$RAISIN_PATH" ]] && export RAISIN_PATH="$PWD/lib" # Then as many as the sub-libraries as you need source ${RAISIN_PATH}/common-functions.sh +source ${RAISIN_PATH}/common-tests.sh source ${RAISIN_PATH}/git-checkout.sh source ${RAISIN_PATH}/commands.sh@@ -59,7 +61,7 @@ do done case "$1" in - "install-builddep" | "build" | "install" | "configure" | "unraise" ) + "install-builddep" | "build" | "install" | "configure" | "unraise" | "test" ) COMMAND=$1 ;; *)tests/busybox-pv new file +37
-0@@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -e + +function busybox-pv-cleanup() { + $SUDO xl destroy raisin-test || true + umount $LOOP || true + cd "$BASEDIR" + $SUDO losetup -d $LOOP + rm -rf $TMPDIR +} + +function busybox-pv-test() { + TMPDIR=`mktemp -d` + cd $TMPDIR + + allocate_disk busybox-vm-disk $((20*1024*1024)) + LOOP=`create_loop busybox-vm-disk` + busybox_rootfs $LOOP + busybox_network_init $LOOP + + cat >busybox-pv <<EOF +kernel = "`get_host_kernel`" +ramdisk = "`get_host_initrd`" +extra = "root=/dev/xvda console=hvc0" +memory = 512 +name = "raisin-test" +vcpus = 2 +disk = [ '$LOOP,raw,xvda,w' ] +serial="pty" +boot="c" +vif=['bridge=xenbr1'] +EOF + + $SUDO xl create busybox-pv + check_guest_alive +}tests/series new file +1
-0@@ -0,0 +1 @@ +busybox-pv
PATCH v3 2/5 raisin: add an hvm test
In reply to Stefano StabelliniAdd a few functions to create partitions, install and configure grub in the VM disk. Introduce a script to loopmount a partition within a VM disk.
Add a new test that creates a local HVM guest, boots it and check the network.
---
Changes in v3:
- expose a _test and a _cleanup function from the test script
--- defconfig | 4 +-- lib/common-tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/lopartsetup | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/busybox-hvm | 43 +++++++++++++++++++++++++++++++++ tests/series | 1 + 5 files changed, 175 insertions(+), 2 deletions(-) create mode 100755 scripts/lopartsetup create mode 100755 tests/busybox-hvm
defconfig +2 -2
@@ -41,6 +41,6 @@ OVMF_REVISION="master" LINUX_REVISION="master" # Tests -## All tests: busybox-pv +## All tests: busybox-pv busybox-hvm ## ENABLED_TESTS is the list of test run by raise test -ENABLED_TESTS="busybox-pv" +ENABLED_TESTS="busybox-pv busybox-hvm"
lib/common-tests.sh +62 -0
74 lines not on this page · raw message
scripts/lopartsetup new file +67 -0
67 lines not on this page · raw message
tests/busybox-hvm new file +43 -0
43 lines not on this page · raw message
tests/series +1 -0
@@ -1 +1,2 @@ busybox-pv +busybox-hvm
Signature · 1 line
1.7.10.4
PATCH v3 3/5 raisin: improve output
In reply to Stefano StabelliniIntroduce an error_echo function that prints to stderr. Call error_echo or verbose_echo, instead of echo, when possible and appropriate.
Redirect build and tests output to /dev/null unless VERBOSE==1. Redirect apt-get and yum output to /dev/null.
Fix echo arguments in check-package-deb.
---
Changes in v2:
- use "$@" instead of $* in error_echo and verbose_echo
--- components/grub | 4 +-- components/libvirt | 4 +-- components/linux | 2 +- components/ovmf | 6 ++-- components/qemu | 2 +- components/qemu_traditional | 2 +- components/seabios | 6 ++-- components/xen | 8 ++--- lib/commands.sh | 18 +++++------ lib/common-functions.sh | 74 +++++++++++++++++++++++++++++-------------- lib/common-tests.sh | 6 ++-- tests/busybox-hvm | 2 +- 12 files changed, 81 insertions(+), 53 deletions(-)
components/grub +2 -2
@@ -19,10 +19,10 @@ function grub_check_package() { if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] then - echo grub is only supported on x86_32 and x86_64 + verbose_echo grub is only supported on x86_32 and x86_64 return fi - echo Checking Grub dependencies + verbose_echo Checking Grub dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
components/libvirt +2 -2
@@ -22,7 +22,7 @@ function libvirt_check_package() { local DEP_CentOS_x86_32="$DEP_Fedora_x86_32" local DEP_CentOS_x86_64="$DEP_Fedora_x86_64" - echo Checking Libvirt dependencies + verbose_echo Checking Libvirt dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
@@ -52,7 +52,7 @@ function libvirt_build() { cp daemon/libvirtd.init "$INST_DIR"/etc/rc.d/init.d/libvirtd chmod +x "$INST_DIR"/etc/rc.d/init.d/libvirtd else - echo "I don't know how write an init script for Libvirt on $DISTRO" + error_echo "I don't know how write an init script for Libvirt on $DISTRO" fi cd .. }
components/linux +1 -1
@@ -15,7 +15,7 @@ function linux_check_package() { local DEP_CentOS_x86_32="$DEP_Fedora_x86_32" local DEP_CentOS_x86_64="$DEP_Fedora_x86_64" - echo Checking Linux dependencies + verbose_echo Checking Linux dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
components/ovmf +3 -3
@@ -14,10 +14,10 @@ function ovmf_check_package() { if [[ $RAISIN_ARCH != "x86_64" ]] then - echo ovmf is only supported on x86_64 + verbose_echo ovmf is only supported on x86_64 return fi - echo Checking OVMF dependencies + verbose_echo Checking OVMF dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
@@ -25,7 +25,7 @@ function ovmf_check_package() { function ovmf_build() { if [[ $RAISIN_ARCH != "x86_64" ]] then - echo ovmf is only supported on x86_64 + verbose_echo ovmf is only supported on x86_64 return fi
components/qemu +1 -1
@@ -11,7 +11,7 @@ function qemu_check_package() { local DEP_Fedora_x86_32="$DEP_Fedora_common" local DEP_Fedora_x86_64="$DEP_Fedora_common" - echo Checking QEMU dependencies + verbose_echo Checking QEMU dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
components/qemu_traditional +1 -1
@@ -12,7 +12,7 @@ function qemu_traditional_check_package() { local DEP_Fedora_x86_32="$DEP_Fedora_common" local DEP_Fedora_x86_64="$DEP_Fedora_common" - echo Checking QEMU dependencies + verbose_echo Checking QEMU dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
components/seabios +3 -3
@@ -14,10 +14,10 @@ function seabios_check_package() { if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] then - echo seabios is only supported on x86_32 and x86_64 + verbose_echo seabios is only supported on x86_32 and x86_64 return fi - echo Checking SeaBIOS dependencies + verbose_echo Checking SeaBIOS dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
@@ -25,7 +25,7 @@ function seabios_check_package() { function seabios_build() { if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] then - echo seabios is only supported on x86_32 and x86_64 + verbose_echo seabios is only supported on x86_32 and x86_64 return fi
components/xen +4 -4
@@ -19,7 +19,7 @@ function xen_check_package() { local DEP_CentOS_x86_32="$DEP_CentOS_common dev86 texinfo iasl" local DEP_CentOS_x86_64="$DEP_CentOS_x86_32 glibc-devel.i686" - echo Checking Xen dependencies + verbose_echo Checking Xen dependencies eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH" }
@@ -62,13 +62,13 @@ function _xen_create_bridge_Debian() { if [[ -z "$IFACE" ]] then - echo "Please refer to the following page to setup networking:" - echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)" + error_echo "Please refer to the following page to setup networking:" + error_echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)" return 1 fi if [[ "`grep $BRIDGE /etc/network/interfaces`" ]] then - echo "a network bridge seems to be already setup" + verbose_echo "a network bridge seems to be already setup" return 0 fi
lib/commands.sh +9 -9
@@ -17,29 +17,29 @@ function check-builddep() { if [[ -n "${missing[@]}" ]] then - echo "Missing packages: ${missing[@]}" + echo "$PREPEND Missing packages: ${missing[@]}" if [[ "$YES" = "n" ]] then return elif [[ "$YES" != "y" ]] then - echo "Do you want Raisin to automatically install them for you? (y/n)" + echo "$PREPEND Do you want Raisin to automatically install them for you? (y/n)" while read answer do if [[ "$answer" = "n" ]] then - echo "Please install, or run ./raise install-builddep" + echo "$PREPEND Please install, or run ./raise install-builddep" exit 1 elif [[ "$answer" = "y" ]] then break else - echo "Reply y or n" + echo "$PREPEND Reply y or n" fi done fi - echo "Installing..." + echo "$PREPEND Installing..." install-package "${missing[@]}" fi }
@@ -72,7 +72,7 @@ function install() { # need single braces for filename matching expansion if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ] then - echo You need to raise build first. + error_echo You need to raise build first. exit 1 fi install_package xen-system
@@ -84,8 +84,8 @@ function configure() { return elif [[ "$YES" != "y" ]] then - echo "Proceeding we'll make changes to the running system," - echo "are you sure that you want to continue? (y/n)" + echo "$PREPEND Proceeding we'll make changes to the running system," + echo "$PREPEND are you sure that you want to continue? (y/n)" while read answer do if [[ "$answer" = "n" ]]
@@ -95,7 +95,7 @@ function configure() { then break else - echo "Reply y or n" + echo "$PREPEND Reply y or n" fi done fi
lib/common-functions.sh +51 -23
175 lines not on this page · raw message
lib/common-tests.sh +3 -3
@@ -133,7 +133,7 @@ EOF --grub-mkdevicemap=$tmpdir/boot/grub/device.map \ --root-directory=$tmpdir $dev else - echo "I don't know how to install grub on $DISTRO" + echo "$PREPEND I don't know how to install grub on $DISTRO" fi $SUDO umount $tmpdir
@@ -149,7 +149,7 @@ function check_guest_alive() { i=$((i+1)) if [[ $i -gt 60 ]] then - echo Timeout connecting to guest + echo $PREPEND Timeout connecting to guest return 1 fi done
@@ -168,7 +168,7 @@ function get_host_initrd() { then echo "/boot/initramfs-`uname -r`".img else - echo "I don't know how to find the initrd" >&2 + echo "$PREPEND I don't know how to find the initrd" >&2 exit 1 fi }
tests/busybox-hvm +1 -1
@@ -13,7 +13,7 @@ function busybox-hvm-cleanup() { function busybox-hvm-test() { if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] then - echo busybox hvm test only valid on x86 + echo $PREPEND busybox hvm test only valid on x86 exit 0 fi
Signature · 1 line
1.7.10.4
PATCH v3 4/5 raisin: small stlye improvement in for_each_component
In reply to Stefano StabelliniUse the found variable as a boolean.
--- lib/common-functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/common-functions.sh +3 -3
@@ -281,16 +281,16 @@ function for_each_component () { for component in `cat "$BASEDIR"/components/series` do - found=0 + found=false for enabled in $COMPONENTS do if [[ $enabled = $component ]] then - found=1 + found=true break fi done - if [[ $found -eq 0 ]] + if ! $found then verbose_echo "$component" is disabled continue
Signature · 1 line
1.7.10.4
PATCH v3 5/5 raisin: introduce a local migration test
In reply to Stefano Stabellini--- tests/busybox-hvm-migrate | 33 +++++++++++++++++++++++++++++++++ tests/series | 1 + 2 files changed, 34 insertions(+) create mode 100755 tests/busybox-hvm-migrate
tests/busybox-hvm-migrate new file +33 -0
@@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -e + +source "$BASEDIR"/tests/busybox-hvm + +function busybox-hvm-migrate-cleanup() { + rm -f $TMPSCRIPT + busybox-hvm-cleanup +} + +function busybox-hvm-migrate-test() { + if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] + then + echo $PREPEND busybox hvm test only valid on x86 + exit 0 + fi + + busybox-hvm-test + + TMPSCRIPT=`mktemp` + + cat >$TMPSCRIPT <<EOF +#!/usr/bin/env bash + +shift +\$* +EOF + + chmod +x $TMPSCRIPT + xl migrate -s $TMPSCRIPT raisin-test localhost + check_guest_alive +}
tests/series +1 -0
@@ -1,2 +1,3 @@ busybox-pv busybox-hvm +busybox-hvm-migrate
Signature · 1 line
1.7.10.4