From 1cbf84b6a43c87c321c2c4d92572223e567c9d0b Mon Sep 17 00:00:00 2001 From: Riku Voipio Date: Tue, 3 May 2016 16:23:25 +0300 Subject: start-kvm: new job to start kvm for pipeline jobs This starts kvm for multinode pipeline jobs. Guest image is configured using cloud-init, so any OS with cloud-init can be configured. Guest arch and URL for test image need to be passed: - from: git name: kvm-guest path: ubuntu/start-kvm.yaml parameters: GUEST_ARCH: 'aarch64' GUEST_IMAGE: 'https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-arm64-uefi1.img' repository: 'https://git.linaro.org/qa/test-definitions.git' Change-Id: I88a4cc874f87073b85cacc312eed3013f24e2202 Signed-off-by: Riku Voipio --- common/scripts/kvm-cloud/cloudinit.txt | 16 ++++ common/scripts/kvm-cloud/start-kvm.sh | 157 +++++++++++++++++++++++++++++++++ common/scripts/kvm-cloud/wait-ip.py | 24 +++++ ubuntu/start-kvm.yaml | 50 +++++++++++ 4 files changed, 247 insertions(+) create mode 100644 common/scripts/kvm-cloud/cloudinit.txt create mode 100755 common/scripts/kvm-cloud/start-kvm.sh create mode 100755 common/scripts/kvm-cloud/wait-ip.py create mode 100644 ubuntu/start-kvm.yaml diff --git a/common/scripts/kvm-cloud/cloudinit.txt b/common/scripts/kvm-cloud/cloudinit.txt new file mode 100644 index 0000000..d9363f1 --- /dev/null +++ b/common/scripts/kvm-cloud/cloudinit.txt @@ -0,0 +1,16 @@ +#cloud-config + +users: + - name: linaro + ssh-authorized-keys: + - LAVA_KEY + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + groups: sudo + shell: /bin/bash + +runcmd: + - cp /home/linaro/.ssh/authorized_keys /root/.ssh/authorized_keys + - chown root:root /root/.ssh/authorized_keys + +phone_home: + url: http://LOCALIP:8080/ diff --git a/common/scripts/kvm-cloud/start-kvm.sh b/common/scripts/kvm-cloud/start-kvm.sh new file mode 100755 index 0000000..ff3922b --- /dev/null +++ b/common/scripts/kvm-cloud/start-kvm.sh @@ -0,0 +1,157 @@ +#!/bin/bash +# +# Copyright (C) 2010 - 2016, Linaro Limited. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Maintainer: Riku Voipio + +# Create cloud-config image to set up credentials for image +configure_guest() +{ + IP=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` + SSH_KEY=`head -1 /root/.ssh/authorized_keys||head -1 $HOME/.ssh/authorized_keys` + sed -e "s,LAVA_KEY,$SSH_KEY,g" -e "s,LOCALIP,$IP,g" common/scripts/kvm-cloud/cloudinit.txt > cloudinit.tmp + cat cloudinit.tmp + cloud-localds cloud.img cloudinit.tmp +} + +# Download url and puts the filename of downloaded file in first argument +download_file() +{ + local _outvar=$1 + local url=$2 + local filename=`basename $url` + if [ ! -e $filename ] + then + if [ -z $url -o $url = none ] + then + >&2 echo "Error, url for $_outvar not set!" + exit 2 + fi + if ! curl --retry 3 -SOL -# $url + then + >&2 echo "Error downloading $url for $_outvar" + exit 3 + fi + fi + eval $_outvar=\$filename +} + +start_qemu_x86_64_aarch64() +{ + image=$1 + configimage=$2 + download_file efi $GUEST_FIRMWARE + + qemu-system-aarch64 -smp 2 -m 1024 -cpu cortex-a57 -M virt \ + -bios $efi \ + -device virtio-blk-device,drive=image \ + -drive if=none,id=image,file=$image \ + -device virtio-blk-device,drive=cloud \ + -drive if=none,id=cloud,file=$configimage \ + -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \ + -daemonize -display vnc=none \ + -serial file:qemu_aarch64.txt +} + +start_qemu_aarch64_aarch64() +{ + image=$1 + configimage=$2 + download_file efi $GUEST_FIRMWARE + + qemu-system-aarch64 -smp 2 -m 1024 -cpu host -M virt \ + -bios $efi \ + -device virtio-blk-device,drive=image \ + -drive if=none,id=image,file=$image \ + -device virtio-blk-device,drive=cloud \ + -drive if=none,id=cloud,file=$configimage \ + -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \ + -daemonize -enable-kvm -display vnc=none \ + -serial file:kvm-aarch64_aarch64.txt +} + +start_qemu_x86_64_armv7l() +{ + image=$1 + configimage=$2 + download_file kernel $GUEST_KERNEL + + qemu-system-arm -smp 2 -m 1024 -cpu cortex-a15 -M virt \ + -kernel $kernel \ + -append 'root=/dev/vdb1 rw rootwait mem=1024M console=ttyAMA0,38400n8' \ + -device virtio-blk-device,drive=image \ + -drive if=none,id=image,file=$image \ + -device virtio-blk-device,drive=cloud \ + -drive if=none,id=cloud,file=$configimage \ + -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \ + -daemonize -display vnc=none \ + -serial file:qemu_armv7l.txt +} + +start_qemu_aarch64_armv7l() +{ + image=$1 + configimage=$2 + download_file kernel $GUEST_KERNEL + + qemu-system-aarch64 -smp 2 -m 1024 -cpu host,aarch64=off -M virt \ + -kernel $kernel \ + -append 'root=/dev/vdb1 rw rootwait mem=1024M console=ttyAMA0,38400n8' \ + -device virtio-blk-device,drive=image \ + -drive if=none,id=image,file=$image \ + -device virtio-blk-device,drive=cloud \ + -drive if=none,id=cloud,file=$configimage \ + -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \ + -daemonize -enable-kvm -display vnc=none \ + -serial file:kvm-aarch64_armv7l.txt +} + +start_qemu_armv7l_armv7l() +{ + image=$1 + configimage=$2 + download_file kernel $GUEST_KERNEL + + qemu-system-arm -smp 2 -m 1024 -cpu cortex-a15 -M vexpress-a15 \ + -kernel $kernel \ + -append 'root=/dev/vdb1 rw rootwait mem=1024M console=ttyAMA0,38400n8' \ + -device virtio-blk-device,drive=image \ + -drive if=none,id=image,file=$image \ + -device virtio-blk-device,drive=cloud \ + -drive if=none,id=cloud,file=$configimage \ + -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \ + -daemonize -enable-kvm -display vnc=none \ + -serial file:kvm-armv7l_armv7l.txt +} + +# This testcase expects a predefined br0 to connect to +tunctl -u root +ifconfig tap0 0.0.0.0 up +brctl addif br0 tap0 + +ARCH=`uname -m` +GUEST_ARCH=$1 +GUEST_IMAGE=$2 +GUEST_FIRMWARE=$3 +GUEST_KERNEL=$4 + +download_file IMAGE $GUEST_IMAGE +configure_guest + +start_qemu_${ARCH}_${GUEST_ARCH} ${IMAGE} cloud.img +sleep 10 +tail *.txt diff --git a/common/scripts/kvm-cloud/wait-ip.py b/common/scripts/kvm-cloud/wait-ip.py new file mode 100755 index 0000000..392fc8c --- /dev/null +++ b/common/scripts/kvm-cloud/wait-ip.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +# Wait for a HTTP post and echo the IP of the first visitor + +from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer + +class MyHandler(BaseHTTPRequestHandler): + def returnIP(self): + self.send_response(200) + self.end_headers() + print self.client_address[0] + return + + def log_message(self, format, *args): + return + + def do_POST(self): + self.returnIP() + + def do_GET(self): + self.returnIP() + +server = HTTPServer(('', 8080), MyHandler) +server.handle_request() + diff --git a/ubuntu/start-kvm.yaml b/ubuntu/start-kvm.yaml new file mode 100644 index 0000000..031a031 --- /dev/null +++ b/ubuntu/start-kvm.yaml @@ -0,0 +1,50 @@ +metadata: + name: kvm + format: "Lava-Test-Shell Test Definition 1.0" + description: "Start KVM for secondary testing" + maintainer: + - riku.voipio@linaro.org + scope: + - functional + - virtualization + os: + - ubuntu + devices: + - arndale + - vexpress-tc2 + - mustang + - midway + - juno + +params: + # guest architecture for constructing qemu command line + GUEST_ARCH: aarch64 + # URL to cloud-init enabled guest image + GUEST_IMAGE: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-arm64-uefi1.img + # Bios or firmware needed to boot + GUEST_FIRMWARE: https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd + # kernel for platforms that are booted without firmware + GUEST_KERNEL: none + +install: + deps: + - qemu-system + - qemu-utils + - bridge-utils + - uml-utilities + - curl + - hwloc-nox + - cloud-utils + - genisoimage + +run: + steps: + - 'lava-test-case kvm-init --shell [ -c /dev/kvm ]' + - 'sudo ./common/scripts/kvm-cloud/start-kvm.sh $GUEST_ARCH $GUEST_IMAGE $GUEST_FIRMWARE $GUEST_KERNEL' + - 'lava-send ipv4 ipaddr=$(./common/scripts/kvm-cloud/wait-ip.py)' + - lava-send lava_start + - lava-sync clients + - 'cat *.txt' + +parse: + pattern: '^(?P[^:]+):\s*(?P[0-9.]+)\s+(?P\w+)\s+(?P\w+)' -- cgit v1.2.3