xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Géza Gémes" <geza.gemes@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: sstabellini@kernel.org, george.dunlap@citrix.com,
	"Géza Gémes" <geza.gemes@gmail.com>
Subject: [PATCH 02/10] Introduce cirros tests
Date: Sat, 18 Mar 2017 15:00:03 +0100	[thread overview]
Message-ID: <1489845611-6322-3-git-send-email-geza.gemes@gmail.com> (raw)
In-Reply-To: <1489845611-6322-1-git-send-email-geza.gemes@gmail.com>

Add support for using cirros images in raisin tests

Signed-off-by: Géza Gémes <geza.gemes@gmail.com>
---
 configs/config-cirros |  44 ++++++++++++++++++++++
 defconfig             |   2 +
 lib/common-tests.sh   | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 configs/config-cirros

diff --git a/configs/config-cirros b/configs/config-cirros
new file mode 100644
index 0000000..fa2823e
--- /dev/null
+++ b/configs/config-cirros
@@ -0,0 +1,44 @@
+CIRROS_BASE_URL="https://download.cirros-cloud.net/"
+CIRROS_VERSION="0.3.5"
+
+source `pwd`/lib/common-functions.sh
+get_arch
+case $RAISIN_ARCH in
+    x86_64)
+        CIRROS_ARCH=x86_64
+        ;;
+    x86_32)
+        CIRROS_ARCH=i386
+        ;;
+    *)
+        echo $PREPEND cirros tests only valid on x86, 32 or 64 bit
+        exit 1
+esac
+
+CIRROS_KERNEL_FILE=cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-kernel
+CIRROS_INITRD_FILE=cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-initramfs
+CIRROS_ROOTFS_FILE=cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-rootfs.img
+CIRROS_DISK_FILE=cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-disk.img
+CIRROS_KERNEL_URL=${CIRROS_BASE_URL}/${CIRROS_VERSION}/${CIRROS_KERNEL_FILE}
+CIRROS_INITRD_URL=${CIRROS_BASE_URL}/${CIRROS_VERSION}/${CIRROS_INITRD_FILE}
+CIRROS_ROOTFS_URL=${CIRROS_BASE_URL}/${CIRROS_VERSION}/${CIRROS_ROOTFS_FILE}.gz
+CIRROS_DISK_URL=${CIRROS_BASE_URL}/${CIRROS_VERSION}/${CIRROS_DISK_FILE}
+
+CIRROS_GRUB_CFG="(xen/xvda,msdos1)/boot/grub/grub.cfg"
+
+set +e
+QEMU_IMG=`which qemu-img`
+set -e
+if [[ -z "$QEMU_IMG" ]]
+then
+    QEMU_IMG="/usr/lib/xen/bin/qemu-img"
+fi
+
+set +e
+PVGRUB=`which grub-${CIRROS_ARCH}-xen`
+set -e
+if [[ -z "$PVGRUB" ]]
+then
+    PVGRUB="/usr/lib/xen/boot/grub-${CIRROS_ARCH}-xen"
+fi
+
diff --git a/defconfig b/defconfig
index f8ef398..111554e 100644
--- a/defconfig
+++ b/defconfig
@@ -32,3 +32,5 @@ GIT_TRANSPORT="git"
 ## All tests: busybox-pv busybox-hvm
 ## ENABLED_TESTS is the list of test run by raise test
 ENABLED_TESTS="busybox-pv busybox-hvm"
+
+. configs/config-cirros
diff --git a/lib/common-tests.sh b/lib/common-tests.sh
index d346af4..79815ce 100644
--- a/lib/common-tests.sh
+++ b/lib/common-tests.sh
@@ -178,3 +178,105 @@ function get_host_initrd() {
         exit 1
     fi
 }
+
+function cirros_network_init() {
+    rootdir=$1
+    # Configure static ip
+    $SUDO sed -i -e 's/iface eth0 inet dhcp/iface eth0 inet static/' ${rootdir}/etc/network/interfaces
+    $SUDO sed -i -e '/iface eth0 inet static/a\    address 169.254.0.2' ${rootdir}/etc/network/interfaces
+    $SUDO sed -i -e '/address/a\    network 169.254.0.0' ${rootdir}/etc/network/interfaces
+    $SUDO sed -i -e '/network/a\    broadcast 169.254.0.255' ${rootdir}/etc/network/interfaces
+    $SUDO sed -i -e '/broadcast/a\    netmask 255.255.255.0' ${rootdir}/etc/network/interfaces
+    # Disable cloud-init
+    $SUDO rm -f ${rootdir}/etc/rc3.d/S*cirros*ds*
+    $SUDO rm -f ${rootdir}/etc/rc3.d/S*-cirros-userdata
+}
+
+function get_cirros_kernel() {
+    bootdir=$1
+    basename `find $bootdir -name vmlinuz* 2>/dev/null | head -1`
+}
+
+function get_cirros_initrd() {
+    bootdir=$1
+    basename `find $bootdir -name initrd* 2>/dev/null | head -1`
+}
+
+function cirros_grub_cfg() {
+    rootdir=$1
+    grubcfg="`echo $CIRROS_GRUB_CFG | cut -d ')' -f 2`"
+    grubdir=`dirname $grubcfg`
+    bootdir=`dirname $grubdir`
+    tmpgrubcfg=`mktemp`
+    cat > $tmpgrubcfg <<EOF
+root='(xen/xvda,msdos1)'
+insmod xzio
+insmod gzio
+insmod btrfs
+insmod ext2
+set timeout=1
+set default=0
+menuentry Cirros {
+    linux `echo $bootdir`/`get_cirros_kernel ${rootdir}/${bootdir}` root=/dev/xvda1 ro
+    initrd `echo $bootdir`/`get_cirros_initrd ${rootdir}/${bootdir}`
+}
+EOF
+    $SUDO mv $tmpgrubcfg ${rootdir}/${grubcfg}
+}
+
+function set_up_cirros_tests() {
+    verbose_echo "Setting up environment for cirros tests"
+    tmpdir=`mktemp -d`
+    wget -q $CIRROS_KERNEL_URL -P $tmpdir
+    wget -q $CIRROS_INITRD_URL -P $tmpdir
+    wget -q $CIRROS_ROOTFS_URL -P $tmpdir
+    wget -q $CIRROS_DISK_URL -P $tmpdir
+    gunzip ${tmpdir}/${CIRROS_ROOTFS_FILE}.gz
+    mv ${tmpdir}/${CIRROS_DISK_FILE} ${tmpdir}/${CIRROS_DISK_FILE}.qcow2
+    $QEMU_IMG convert -f qcow2 -O raw ${tmpdir}/${CIRROS_DISK_FILE}.qcow2 ${tmpdir}/${CIRROS_DISK_FILE}
+    CIRROS_ROOTFS_LOOP=`create_loop ${tmpdir}/${CIRROS_ROOTFS_FILE}`
+    CIRROS_DISK_LOOP_P0=`$SUDO $BASEDIR/scripts/lopartsetup ${tmpdir}/${CIRROS_DISK_FILE} | head -1 | cut -d ":" -f 1`
+    CIRROS_ROOTFS_MNTPT=`mktemp -d`
+    CIRROS_DISK_MNTPT=`mktemp -d`
+    $SUDO mount $CIRROS_ROOTFS_LOOP $CIRROS_ROOTFS_MNTPT
+    $SUDO mount $CIRROS_DISK_LOOP_P0 $CIRROS_DISK_MNTPT
+    cirros_network_init $CIRROS_ROOTFS_MNTPT
+    cirros_network_init $CIRROS_DISK_MNTPT
+    cirros_grub_cfg $CIRROS_DISK_MNTPT
+    $SUDO umount $CIRROS_ROOTFS_MNTPT
+    $SUDO umount $CIRROS_DISK_MNTPT
+    $SUDO rmdir $CIRROS_ROOTFS_MNTPT
+    $SUDO rmdir $CIRROS_DISK_MNTPT
+    $SUDO losetup -d $CIRROS_ROOTFS_LOOP
+    $SUDO losetup -d $CIRROS_DISK_LOOP_P0
+}
+
+function tear_down_cirros_tests() {
+    tmpdir=$1
+    if [[ `$SUDO xl vm-list | grep -e "raisin-test" | wc -l` -gt 0 ]]
+    then
+        $SUDO xl destroy "raisin-test"
+    fi
+    number_of_cirros_tests=0
+    for test in $TESTS
+    do
+        if [[ "`echo $test | cut -d '-' -f 1`" == "cirros" ]]
+        then
+            number_of_cirros_tests=$((number_of_cirros_tests+1))
+        fi
+    done
+    number_of_run_cirros_tests=0
+    for test in $TESTS
+    do
+        if [[ -f ${tmpdir}/${test}.cfg ]]
+        then
+            number_of_run_cirros_tests=$((number_of_run_cirros_tests+1))
+        fi
+    done
+    if [[ $number_of_cirros_tests == $number_of_run_cirros_tests ]]
+    then
+        verbose_echo "Deleting environment of cirros tests"
+        $SUDO rm -rf $tmpdir
+    fi
+}
+
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-03-18 14:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-18 14:00 [raisin][PATCH 00/10] Introduce usage of cirros images Géza Gémes
2017-03-18 14:00 ` [PATCH 01/10] Fix lopartsetup parsing of fdisk output Géza Gémes
2017-03-18 14:00 ` Géza Gémes [this message]
2017-03-18 14:00 ` [PATCH 03/10] Introduce cirros-separate-kernel-pv test Géza Gémes
2017-03-18 14:00 ` [PATCH 04/10] Introduce cirros-pygrub-pv test Géza Gémes
2017-03-18 14:00 ` [PATCH 05/10] Introduce cirros-pvgrub2-pv test Géza Gémes
2017-03-18 14:00 ` [PATCH 06/10] Introduce cirros-qemu-hvm test Géza Gémes
2017-03-18 14:00 ` [PATCH 07/10] Introduce cirros-minios-stubdom-hvm test Géza Gémes
2017-03-18 14:00 ` [PATCH 08/10] Introduce cirros-qemu-pvhvm test Géza Gémes
2017-03-18 14:00 ` [PATCH 09/10] Introduce cirros-minios-stubdom-pvhvm test Géza Gémes
2017-03-18 14:00 ` [PATCH 10/10] Enable cirros tests in the default config Géza Gémes
  -- strict thread matches above, loose matches on Subject: below --
2017-03-25 19:28 [raisin][PATCH 00/10] pygrub fix + cirros tests Géza Gémes
2017-03-25 19:28 ` [PATCH 02/10] Introduce " Géza Gémes
2017-03-27 17:11   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489845611-6322-3-git-send-email-geza.gemes@gmail.com \
    --to=geza.gemes@gmail.com \
    --cc=george.dunlap@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).