This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kvm infrastructure for running local tests (#139)
- Loading branch information
Omer Akram
authored and
David Barth
committed
Feb 14, 2017
1 parent
869af40
commit 1da0882
Showing
5 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/bin/sh | ||
|
||
FILE_PID=kvm.pid | ||
FILE_MONITOR=monitor | ||
PORT_SSH=8022 | ||
IMAGE_BOOTABLE=${IMAGE_BOOTABLE:-ubuntu-core-16.img} | ||
|
||
is_vm_running() { | ||
if [ -e $FILE_PID ] && [ -e $FILE_MONITOR ]; then | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
send_cmd() { | ||
QEMU_MONITOR_COMMAND=$1 | ||
echo "${QEMU_MONITOR_COMMAND}" | socat - UNIX-CONNECT:${FILE_MONITOR} | ||
} | ||
|
||
stop_vm() { | ||
send_cmd quit | ||
} | ||
|
||
start_vm() { | ||
|
||
if [ ! -e ${IMAGE_BOOTABLE} ]; then | ||
IMAGE_BOOTABLE=${HOME}/.spread/qemu/${IMAGE_BOOTABLE} | ||
if [ ! -e ${IMAGE_BOOTABLE} ]; then | ||
echo "Unable to find a bootable image" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
qemu-system-x86_64 \ | ||
-enable-kvm -snapshot \ | ||
-m 500 \ | ||
-net nic -net user,hostfwd=tcp::$PORT_SSH-:22,hostfwd=tcp::4201-:4201 \ | ||
-drive file=$IMAGE_BOOTABLE,format=raw \ | ||
-pidfile $FILE_PID \ | ||
-monitor unix:$FILE_MONITOR,server,nowait \ | ||
-serial unix:$FILE_MONITOR.serial,server,nowait \ | ||
-nographic & | ||
} | ||
|
||
if [ $# -ne 1 ]; then | ||
echo "Need exactly one argument to run." | ||
echo "Try running as $0 start|stop|status" | ||
exit 1 | ||
fi | ||
|
||
if [ $1 != "start" ] && [ $1 != "stop" ] && [ $1 != "status" ]; then | ||
echo "Invalid argument provided." | ||
echo "Try running as $0 start|stop|status" | ||
exit 1 | ||
fi | ||
|
||
if [ $1 = "start" ]; then | ||
if is_vm_running; then | ||
echo "Cannot start vm is already running." | ||
exit 1 | ||
fi | ||
echo "Starting" | ||
start_vm | ||
fi | ||
|
||
if [ $1 = "stop" ]; then | ||
if is_vm_running; then | ||
stop_vm | ||
# If VM still running, force clean | ||
if is_vm_running; then | ||
rm $FILE_PID | ||
rm $FILE_MONITOR | ||
fi | ||
echo "Stopped" | ||
exit 1 | ||
fi | ||
echo "Nothing to stop." | ||
exit 1 | ||
fi | ||
|
||
if [ $1 = "status" ]; then | ||
if is_vm_running; then | ||
echo "Running" | ||
else | ||
echo "Not running" | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
set +x | ||
|
||
user=$1 | ||
host=$2 | ||
port=$3 | ||
snap=$4 | ||
kvm_user=test | ||
home=~ | ||
|
||
if [ $# -lt 4 ]; then | ||
echo "Invalid number of arguments provided" | ||
echo "Run as ./$0 user host kvm_ssh_port snap_file" | ||
exit 1 | ||
fi | ||
|
||
ssh $user@$host "if [ -d image ]; then rm -rf image; fi" | ||
scp -r ../spread/image/ $user@$host:~/ | ||
scp -r kvm-exec.sh $user@$host:~/image/ | ||
ssh $user@$host "apt update" | ||
ssh $user@$host "apt -y install qemu-kvm socat ubuntu-image kpartx" | ||
ssh $user@$host "cd image; ./create-image.sh" | ||
ssh $user@$host "cd image; ./kvm-exec.sh stop" | ||
ssh $user@$host "cd image; ./kvm-exec.sh start >/dev/null" | ||
sleep 120 | ||
ssh-keygen -f "$home/.ssh/known_hosts" -R [$host]:$port | ||
./remote-install-snap.sh $kvm_user $host $port $4 | ||
./run-tests.sh $kvm_user $host $port true |