|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 2/5] raisin: add an hvm test
Add 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.
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
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
diff --git a/defconfig b/defconfig
index e88f3d3..664aee6 100644
--- a/defconfig
+++ b/defconfig
@@ -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"
diff --git a/lib/common-tests.sh b/lib/common-tests.sh
index 8d2ee6b..abbc91a 100644
--- a/lib/common-tests.sh
+++ b/lib/common-tests.sh
@@ -31,6 +31,18 @@ function create_loop() {
echo $loop
}
+# $1 disk name
+# print loop device name of the partition
+function create_one_partition() {
+ local disk
+ local dev
+
+ disk=$1
+ echo -e "o\nn\np\n1\n\n\nw" | $SUDO fdisk $disk &>/dev/null
+ dev=`$SUDO $BASEDIR/scripts/lopartsetup $disk | head -1 | cut -d ":" -f 1`
+ echo $dev
+}
+
# $1 dev name
function busybox_rootfs() {
local dev
@@ -78,6 +90,56 @@ EOF
rmdir $tmpdir
}
+function bootloader_init() {
+ local dev
+ local devp
+ local tmpdir
+
+ dev=$1
+ devp=$2
+ tmpdir=`mktemp -d`
+
+ $SUDO mount $devp $tmpdir
+ mkdir -p $tmpdir/boot/grub
+ cp "`get_host_kernel`" $tmpdir/boot
+ cp "`get_host_initrd`" $tmpdir/boot || true
+ cat >$tmpdir/boot/grub/grub.cfg <<EOF
+set default="0"
+set timeout=0
+
+menuentry 'Xen Guest' {
+ set root=hd0,1
+ linux `get_host_kernel` root=/dev/xvda1 console=ttyS0
+EOF
+ if [[ -e `get_host_initrd` ]]
+ then
+ echo "initrd `get_host_initrd`" >> $tmpdir/boot/grub/grub.cfg
+ fi
+ echo "}" >> $tmpdir/boot/grub/grub.cfg
+
+ cat >$tmpdir/boot/grub/device.map <<EOF
+(hd0) $dev
+(hd0,1) $devp
+EOF
+
+ if [[ $DISTRO = "Debian" ]]
+ then
+ $SUDO grub-install --no-floppy \
+ --grub-mkdevicemap=$tmpdir/boot/grub/device.map \
+ --root-directory=$tmpdir $dev
+ elif [[ $DISTRO = "Fedora" ]]
+ then
+ $SUDO grub2-install --no-floppy \
+ --grub-mkdevicemap=$tmpdir/boot/grub/device.map \
+ --root-directory=$tmpdir $dev
+ else
+ echo "I don't know how to install grub on $DISTRO"
+ fi
+
+ $SUDO umount $tmpdir
+ rmdir $tmpdir
+}
+
function check_guest_alive() {
local i
i=0
diff --git a/scripts/lopartsetup b/scripts/lopartsetup
new file mode 100755
index 0000000..bf33a28
--- /dev/null
+++ b/scripts/lopartsetup
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Need root privileges
+#
+# Create loop devices corresponding to partitions within an existing
+# file.
+
+set -e
+
+function _help() {
+ echo "Usage: lopartsetup file"
+}
+
+function _create_loop_device() {
+ local devnode
+ local filename
+ local offset
+ local index
+
+ filename="$1"
+ index="$2"
+ offset="$3"
+
+ devnode="`losetup -f 2>/dev/null`"
+ if [[ -z "$devnode" ]]
+ then
+ echo "no loop devices available"
+ exit 1
+ fi
+
+ echo "$devnode: partition $index of $filename"
+ losetup "$devnode" "$filename" -o "$offset"
+}
+
+if [[ $# -lt 1 ]]
+then
+ _help
+ exit 1
+fi
+
+if [[ -f "$1" && -r "$1" ]]
+then
+ filename="$1"
+ shift
+else
+ echo invalid image file
+ exit 1
+fi
+
+if [[ ! "`file -b $filename`" = *"boot sector"* ]]
+then
+ echo "$filename does not have a partition table"
+ exit 1
+fi
+
+unit="`fdisk -lu $filename 2>/dev/null | grep -e "^Units = " | cut -d " " -f
9`"
+index=0
+for i in "`fdisk -lu $filename 2>/dev/null | grep -e "^$filename"`"
+do
+ index=$((index+1))
+ offset=`echo $i | tr -s " " | cut -d " " -f 2`
+ offset=$((unit*offset))
+
+ _create_loop_device "$filename" "$index" "$offset"
+done
+
+exit 0
diff --git a/tests/busybox-hvm b/tests/busybox-hvm
new file mode 100755
index 0000000..269ef2a
--- /dev/null
+++ b/tests/busybox-hvm
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+set -e
+
+function busybox-hvm-cleanup() {
+ $SUDO xl destroy raisin-test || true
+ umount $LOOP_P0 || true
+ cd "$BASEDIR"
+ $SUDO losetup -d $LOOP_P0 $LOOP
+ rm -rf $TMPDIR
+}
+
+function busybox-hvm-test() {
+ if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
+ then
+ echo busybox hvm test only valid on x86
+ exit 0
+ fi
+
+ TMPDIR=`mktemp -d`
+ cd $TMPDIR
+
+ allocate_disk busybox-vm-disk $((20*1024*1024))
+ LOOP=`create_loop busybox-vm-disk`
+ LOOP_P0=`create_one_partition busybox-vm-disk`
+ busybox_rootfs $LOOP_P0
+ busybox_network_init $LOOP_P0
+ bootloader_init $LOOP $LOOP_P0
+
+ cat >busybox-hvm <<EOF
+builder = "hvm"
+memory = 512
+name = "raisin-test"
+vcpus = 2
+disk = [ '$LOOP,raw,hda,w' ]
+serial="pty"
+boot="c"
+vif=['bridge=xenbr1']
+EOF
+
+ $SUDO xl create busybox-hvm
+ check_guest_alive
+}
diff --git a/tests/series b/tests/series
index a5ec626..1f5f5c6 100644
--- a/tests/series
+++ b/tests/series
@@ -1 +1,2 @@
busybox-pv
+busybox-hvm
--
1.7.10.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |