summaryrefslogtreecommitdiff
path: root/automated/linux
diff options
context:
space:
mode:
authorRiku Voipio <riku.voipio@linaro.org>2017-05-11 13:47:23 +0300
committerMilosz Wasilewski <milosz.wasilewski@linaro.org>2017-05-12 15:47:09 +0000
commit2b26706ffe60224ea87b7c9c5fa9561350e32dcb (patch)
tree4d84c74a52c38422e9999d9f0b1e296deda5cb9c /automated/linux
parentdaec34dad7e701c5f92c7fb19b73f07ae68c7028 (diff)
kvm-cloud: de-race shutdown
- move to automated dir - start qemu with pidfile - call shutdown with 1m timeout in guest for clean poweroff - wait for qemu process recorded in pidfile to exit to avoid primary lava connection to poweroff the machine before guest has finished Change-Id: I105ec3bbe3246a05552b3d13123ef4a3c7ea4c82 Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'automated/linux')
-rw-r--r--automated/linux/kvm/cloudinit.txt16
-rwxr-xr-xautomated/linux/kvm/start-kvm.sh169
-rw-r--r--automated/linux/kvm/start-kvm.yaml54
-rw-r--r--automated/linux/kvm/stop-guest.yaml23
-rwxr-xr-xautomated/linux/kvm/wait-ip.py24
-rwxr-xr-xautomated/linux/kvm/wait-kvm.sh8
6 files changed, 294 insertions, 0 deletions
diff --git a/automated/linux/kvm/cloudinit.txt b/automated/linux/kvm/cloudinit.txt
new file mode 100644
index 0000000..d9363f1
--- /dev/null
+++ b/automated/linux/kvm/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/automated/linux/kvm/start-kvm.sh b/automated/linux/kvm/start-kvm.sh
new file mode 100755
index 0000000..6ed3a67
--- /dev/null
+++ b/automated/linux/kvm/start-kvm.sh
@@ -0,0 +1,169 @@
+#!/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 <riku.voipio@linaro.org>
+
+# 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" 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 -SsOL $url
+ then
+ >&2 echo "Error downloading $url for $_outvar"
+ exit 3
+ fi
+ fi
+ eval $_outvar=\$filename
+}
+
+start_qemu_x86_64_aarch64()
+{
+ image=$1
+ download_file efi $GUEST_FIRMWARE
+
+ set -x
+ qemu-system-aarch64 -smp $GUEST_CORES -m ${GUEST_RAM} -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=cloud.img \
+ -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \
+ -daemonize -display vnc=none \
+ -pidfile /run/qemu.pid \
+ -serial file:qemu_aarch64.log
+}
+
+start_qemu_aarch64_aarch64()
+{
+ image=$1
+ download_file efi $GUEST_FIRMWARE
+
+ set -x
+ qemu-system-aarch64 -smp $GUEST_CORES -m ${GUEST_RAM} -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=cloud.img \
+ -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \
+ -daemonize -enable-kvm -display vnc=none \
+ -pidfile /run/qemu.pid \
+ -serial file:kvm-aarch64_aarch64.log
+}
+
+start_qemu_x86_64_armv7l()
+{
+ image=$1
+ download_file kernel $GUEST_KERNEL
+
+ set -x
+ qemu-system-arm -smp $GUEST_CORES -m ${GUEST_RAM} -cpu cortex-a15 -M virt \
+ -kernel $kernel \
+ -append "root=/dev/vdb1 rw rootwait mem=${GUEST_RAM}M 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=cloud.img \
+ -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \
+ -daemonize -display vnc=none \
+ -serial file:qemu_armv7l.log
+}
+
+start_qemu_aarch64_armv7l()
+{
+ image=$1
+ download_file kernel $GUEST_KERNEL
+
+ set -x
+ qemu-system-aarch64 -smp $GUEST_CORES -m ${GUEST_RAM} -cpu host,aarch64=off -M virt \
+ -kernel $kernel \
+ -append "root=/dev/vdb1 rw rootwait mem=${GUEST_RAM}M 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=cloud.img \
+ -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \
+ -daemonize -enable-kvm -display vnc=none \
+ -pidfile /run/qemu.pid \
+ -serial file:kvm-aarch64_armv7l.log
+}
+
+start_qemu_armv7l_armv7l()
+{
+ image=$1
+ download_file kernel $GUEST_KERNEL
+
+ set -x
+ qemu-system-arm -smp $GUEST_CORES -m ${GUEST_RAM} -cpu cortex-a15 -M vexpress-a15 \
+ -kernel $kernel \
+ -append "root=/dev/vdb1 rw rootwait mem=${GUEST_RAM}M 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=cloud.img \
+ -device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0 \
+ -daemonize -enable-kvm -display vnc=none \
+ -pidfile /run/qemu.pid \
+ -serial file:kvm-armv7l_armv7l.log
+}
+
+# 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
+GUEST_CORES=${5:-2}
+GUEST_RAM=${6:-1024}
+
+download_file IMAGE $GUEST_IMAGE
+configure_guest
+
+if grep -q Juno /proc/device-tree/model
+then
+ echo "Juno detected, forcing a53 cluster"
+ hwloc-bind socket:0 --pid $$
+fi
+
+start_qemu_${ARCH}_${GUEST_ARCH} ${IMAGE}
+sleep 10
+tail *.log
diff --git a/automated/linux/kvm/start-kvm.yaml b/automated/linux/kvm/start-kvm.yaml
new file mode 100644
index 0000000..567c57c
--- /dev/null
+++ b/automated/linux/kvm/start-kvm.yaml
@@ -0,0 +1,54 @@
+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
+ # how many cores to allocate to guest
+ GUEST_CORES: "2"
+ # how much RAM allocate to guest
+ GUEST_RAM: "1024"
+
+install:
+ deps:
+ - qemu-system
+ - qemu-utils
+ - bridge-utils
+ - uml-utilities
+ - curl
+ - hwloc-nox
+ - cloud-utils
+ - genisoimage
+
+run:
+ steps:
+ - cd ./automated/linux/kvm
+ - "lava-test-case kvm-init --shell [ -c /dev/kvm ]"
+ - sudo ./start-kvm.sh $GUEST_ARCH $GUEST_IMAGE $GUEST_FIRMWARE $GUEST_KERNEL $GUEST_CORES $GUEST_RAM
+ - lava-send ipv4 ipaddr=$(./wait-ip.py)
+ - lava-send lava_start
+ - lava-sync clients
+ - sudo ./wait-kvm.sh /run/qemu.pid
+ - cat *.log
+
diff --git a/automated/linux/kvm/stop-guest.yaml b/automated/linux/kvm/stop-guest.yaml
new file mode 100644
index 0000000..f04bf42
--- /dev/null
+++ b/automated/linux/kvm/stop-guest.yaml
@@ -0,0 +1,23 @@
+metadata:
+ name: guest-complete
+ format: "Lava-Test-Shell Test Definition 1.0"
+ description: "Signal tests inside guest complete and power off"
+ maintainer:
+ - riku.voipio@linaro.org
+ scope:
+ - functional
+ - virtualization
+ os:
+ - ubuntu
+ devices:
+ - arndale
+ - vexpress-tc2
+ - mustang
+ - midway
+ - juno
+
+run:
+ steps:
+ - lava-sync clients
+ - shutdown -h +1
+
diff --git a/automated/linux/kvm/wait-ip.py b/automated/linux/kvm/wait-ip.py
new file mode 100755
index 0000000..392fc8c
--- /dev/null
+++ b/automated/linux/kvm/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/automated/linux/kvm/wait-kvm.sh b/automated/linux/kvm/wait-kvm.sh
new file mode 100755
index 0000000..1ba1d07
--- /dev/null
+++ b/automated/linux/kvm/wait-kvm.sh
@@ -0,0 +1,8 @@
+#!/bin/sh -e
+
+[ -r "$1" ]||exit 0
+
+while [ -d "/proc/$(cat $1)/" ]
+do
+ sleep 10
+done