All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Géza Gémes" <geza.gemes@gmail.com>
To: xen-devel@lists.xenproject.org, sstabellini@kernel.org
Cc: george.dunlap@citrix.com, "Géza Gémes" <geza.gemes@gmail.com>
Subject: [PATCH 02/10] Introduce cirros tests
Date: Sat, 25 Mar 2017 20:28:54 +0100	[thread overview]
Message-ID: <1490470142-9032-3-git-send-email-geza.gemes@gmail.com> (raw)
In-Reply-To: <1490470142-9032-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>
---
 lib/common-functions.sh            |  33 +++++++++++
 lib/common-tests.sh                | 109 +++++++++++++++++++++++++++++++++++++
 tests-configs/config-cirros_x86_32 |  13 +++++
 tests-configs/config-cirros_x86_64 |  13 +++++
 4 files changed, 168 insertions(+)
 create mode 100644 tests-configs/config-cirros_x86_32
 create mode 100644 tests-configs/config-cirros_x86_64

diff --git a/lib/common-functions.sh b/lib/common-functions.sh
index d4476f3..efc92ff 100644
--- a/lib/common-functions.sh
+++ b/lib/common-functions.sh
@@ -439,3 +439,36 @@ function uninstall_package() {
         error_echo "Don't know how to uninstall packages on $DISTRO"
     fi
 }
+
+function get-qemu-img() {
+    set +e
+    QEMU_IMG=`which qemu-img`
+    set -e
+    if [[ -z "$QEMU_IMG" ]]
+    then
+        QEMU_IMG="/usr/lib/xen/bin/qemu-img"
+    fi
+    if [[ -x $QEMU_IMG ]]
+    then
+        export QEMU_IMG
+    else
+        error_echo "No working qemu-img found! Some tests may fail!"
+    fi
+}
+
+function get-pvgrub() {
+    local arch=$1
+    set +e
+    PVGRUB=`which grub-${arch}-xen`
+    set -e
+    if [[ -z "$PVGRUB" ]]
+    then
+        PVGRUB="/usr/lib/xen/boot/grub-${arch}-xen"
+    fi
+    if [[ -f $PVGRUB ]]
+    then
+        export PVGRUB
+    else
+        error_echo "No working pvgrub found! Some tests may fail!"
+    fi
+}
diff --git a/lib/common-tests.sh b/lib/common-tests.sh
index d346af4..c07bb18 100644
--- a/lib/common-tests.sh
+++ b/lib/common-tests.sh
@@ -178,3 +178,112 @@ function get_host_initrd() {
         exit 1
     fi
 }
+
+function cirros_network_init() {
+    rootdir=$1
+    ifile=`mktemp`
+    # Create static network config
+    cat >$ifile <<EOF
+auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet static
+    address 169.254.0.2
+    network 169.254.0.0
+    broadcast 169.254.0.255
+    netmask 255.255.255.0
+EOF
+    $SUDO mv -f $ifile $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
+    get-pvgrub $CIRROS_ARCH
+    grubroot="`echo $CIRROS_GRUB_CFG | cut -d ')' -f 1`)"
+    grubcfg="`echo $CIRROS_GRUB_CFG | cut -d ')' -f 2`"
+    grubdir=`dirname $grubcfg`
+    bootdir=`dirname $grubdir`
+    tmpgrubcfg=`mktemp`
+    cat > $tmpgrubcfg <<EOF
+root="$grubroot"
+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 -f $tmpgrubcfg ${rootdir}/${grubcfg}
+}
+
+function download_cirros_components() {
+    . tests-configs/config-cirros_$RAISIN_ARCH
+    mkdir -p $CIRROS_DOWNLOADS
+    if [[ ! -f $CIRROS_DOWNLOADS/$CIRROS_KERNEL_FILE ]]
+    then
+        verbose_echo "Downloading cirros kernel"
+        wget -q $CIRROS_KERNEL_URL -P $CIRROS_DOWNLOADS
+    fi
+    if [[ ! -f $CIRROS_DOWNLOADS/$CIRROS_INITRD_FILE ]]
+    then
+        verbose_echo "Downloading cirros initrd"
+        wget -q $CIRROS_INITRD_URL -P $CIRROS_DOWNLOADS
+    fi
+    if [[ ! -f $CIRROS_DOWNLOADS/$CIRROS_ROOTFS_FILE ]]
+    then
+        verbose_echo "Downloading cirros rootfs"
+        wget -q $CIRROS_ROOTFS_URL -P $CIRROS_DOWNLOADS
+        gunzip $CIRROS_DOWNLOADS/$CIRROS_ROOTFS_FILE.gz
+        local cirros_rootfs_loop=`create_loop $CIRROS_DOWNLOADS/$CIRROS_ROOTFS_FILE`
+        local cirros_rootfs_mntpt=`mktemp -d`
+        $SUDO mount $cirros_rootfs_loop $cirros_rootfs_mntpt
+        cirros_network_init $cirros_rootfs_mntpt
+        $SUDO umount $cirros_rootfs_mntpt
+        $SUDO rmdir $cirros_rootfs_mntpt
+        $SUDO losetup -d $cirros_rootfs_loop
+    fi
+    if [[ ! -f $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE ]]
+    then
+        verbose_echo "Downloading cirros disk"
+        wget -q $CIRROS_DISK_URL -P $CIRROS_DOWNLOADS
+        mv $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE.qcow2
+        get-qemu-img
+        $QEMU_IMG convert -f qcow2 -O raw $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE.qcow2 $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE
+        local cirros_disk_loop=`$SUDO $BASEDIR/scripts/lopartsetup $CIRROS_DOWNLOADS/$CIRROS_DISK_FILE | head -1 |
+                                cut -d ":" -f 1`
+        local cirros_disk_mntpt=`mktemp -d`
+        $SUDO mount $cirros_disk_loop $cirros_disk_mntpt
+        cirros_network_init $cirros_disk_mntpt
+        $SUDO umount $cirros_disk_mntpt
+        $SUDO rmdir $cirros_disk_mntpt
+        $SUDO losetup -d $cirros_disk_loop
+    fi
+}
+
+function tear_down_cirros_test() {
+    testdir=$1
+    if [[ `$SUDO xl vm-list | grep "raisin-test" | wc -l` -gt 0 ]]
+    then
+        $SUDO xl destroy "raisin-test"
+    fi
+    verbose_echo "$PREPEND deleting environment of cirros test"
+    $SUDO rm -rf $testdir
+}
diff --git a/tests-configs/config-cirros_x86_32 b/tests-configs/config-cirros_x86_32
new file mode 100644
index 0000000..628e568
--- /dev/null
+++ b/tests-configs/config-cirros_x86_32
@@ -0,0 +1,13 @@
+CIRROS_ARCH=i386
+CIRROS_BASE_URL="https://download.cirros-cloud.net/"
+CIRROS_VERSION="0.3.5"
+CIRROS_DOWNLOADS=$BASEDIR/downloads
+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"
diff --git a/tests-configs/config-cirros_x86_64 b/tests-configs/config-cirros_x86_64
new file mode 100644
index 0000000..7b78316
--- /dev/null
+++ b/tests-configs/config-cirros_x86_64
@@ -0,0 +1,13 @@
+CIRROS_ARCH=x86_64
+CIRROS_BASE_URL="https://download.cirros-cloud.net/"
+CIRROS_VERSION="0.3.5"
+CIRROS_DOWNLOADS=$BASEDIR/downloads
+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"
-- 
2.7.4


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

  parent reply	other threads:[~2017-03-25 19:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-25 19:28 [raisin][PATCH 00/10] pygrub fix + cirros tests Géza Gémes
2017-03-25 19:28 ` [PATCH 01/10] Fix installation of python libs Géza Gémes
2017-03-27 17:08   ` Stefano Stabellini
2017-03-25 19:28 ` Géza Gémes [this message]
2017-03-27 17:11   ` [PATCH 02/10] Introduce cirros tests Stefano Stabellini
2017-03-25 19:28 ` [PATCH 03/10] Introduce cirros-separate-kernel-pv test Géza Gémes
2017-03-27 17:12   ` Stefano Stabellini
2017-03-25 19:28 ` [PATCH 04/10] Introduce cirros-pygrub-pv test Géza Gémes
2017-03-27 17:13   ` Stefano Stabellini
2017-03-25 19:28 ` [PATCH 05/10] Introduce cirros-pvgrub2-pv test Géza Gémes
2017-03-27 17:13   ` Stefano Stabellini
2017-03-27 17:24     ` Stefano Stabellini
2017-03-27 18:38       ` Gémes Géza
2017-03-27 18:42         ` Stefano Stabellini
2017-03-25 19:28 ` [PATCH 06/10] Introduce cirros-qemu-hvm test Géza Gémes
2017-03-27 17:16   ` Stefano Stabellini
2017-03-25 19:28 ` [PATCH 07/10] Introduce cirros-minios-stubdom-hvm test Géza Gémes
2017-03-27 17:16   ` Stefano Stabellini
2017-03-25 19:29 ` [PATCH 08/10] Introduce cirros-qemu-pvhvm test Géza Gémes
2017-03-27 17:17   ` Stefano Stabellini
2017-03-25 19:29 ` [PATCH 09/10] Introduce cirros-minios-stubdom-pvhvm test Géza Gémes
2017-03-27 17:17   ` Stefano Stabellini
2017-03-25 19:29 ` [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-18 14:00 [raisin][PATCH 00/10] Introduce usage of cirros images Géza Gémes
2017-03-18 14:00 ` [PATCH 02/10] Introduce cirros tests Géza Gémes

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=1490470142-9032-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.