[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 03/11] Introduce cirros tests
Add support for using cirros images in raisin tests Signed-off-by: Géza Gémes <geza.gemes@xxxxxxxxx> --- 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@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |