test: appease shellcheck

reviewable/pr706/r2
Tamir Duberstein 1 year ago
parent 571c38b1c6
commit 5a398504cf
No known key found for this signature in database

@ -1,12 +1,13 @@
#!/bin/sh #!/usr/bin/env bash
set -e set -ex
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
export PATH="$(dirname $(brew list gnu-getopt | grep "bin/getopt$")):$PATH" PATH="$(dirname "$(brew list gnu-getopt | grep "bin/getopt$")"):$PATH"
export PATH
fi fi
AYA_SOURCE_DIR="$(realpath $(dirname $0)/..)" AYA_SOURCE_DIR="$(realpath "$(dirname "$0")"/..)"
# Temporary directory for tests to use. # Temporary directory for tests to use.
AYA_TMPDIR="${AYA_SOURCE_DIR}/.tmp" AYA_TMPDIR="${AYA_SOURCE_DIR}/.tmp"
@ -108,7 +109,7 @@ ssh_authorized_keys:
- ${pub_key} - ${pub_key}
EOF EOF
$AYA_SOURCE_DIR/test/cloud-localds "${AYA_TMPDIR}/seed.img" "${AYA_TMPDIR}/user-data.yaml" "${AYA_TMPDIR}/metadata.yaml" "$AYA_SOURCE_DIR"/test/cloud-localds "${AYA_TMPDIR}/seed.img" "${AYA_TMPDIR}/user-data.yaml" "${AYA_TMPDIR}/metadata.yaml"
case "${AYA_GUEST_ARCH}" in case "${AYA_GUEST_ARCH}" in
x86_64) x86_64)
QEMU=qemu-system-x86_64 QEMU=qemu-system-x86_64
@ -129,7 +130,7 @@ EOF
QEMU=qemu-system-aarch64 QEMU=qemu-system-aarch64
machine="virt" machine="virt"
cpu="cortex-a57" cpu="cortex-a57"
uefi="-drive file=${AARCH64_UEFI},if=pflash,format=raw,readonly=on" uefi=("-drive" "file=${AARCH64_UEFI},if=pflash,format=raw,readonly=on")
if [ "${AYA_HOST_ARCH}" = "${AYA_GUEST_ARCH}" ]; then if [ "${AYA_HOST_ARCH}" = "${AYA_GUEST_ARCH}" ]; then
if [ -c /dev/kvm ]; then if [ -c /dev/kvm ]; then
machine="${machine},accel=kvm" machine="${machine},accel=kvm"
@ -153,10 +154,8 @@ EOF
if [ ! -f "${AYA_IMGDIR}/vm.qcow2" ]; then if [ ! -f "${AYA_IMGDIR}/vm.qcow2" ]; then
echo "Creating VM image" echo "Creating VM image"
qemu-img create -F qcow2 -f qcow2 -o backing_file="${AYA_IMGDIR}/${AYA_TEST_IMAGE}.${AYA_GUEST_ARCH}.qcow2" "${AYA_IMGDIR}/vm.qcow2" || return 1 qemu-img create -F qcow2 -f qcow2 -o backing_file="${AYA_IMGDIR}/${AYA_TEST_IMAGE}.${AYA_GUEST_ARCH}.qcow2" "${AYA_IMGDIR}/vm.qcow2" || return 1
CACHED_VM=0
else else
echo "Reusing existing VM image" echo "Reusing existing VM image"
CACHED_VM=1
fi fi
$QEMU \ $QEMU \
-machine "${machine}" \ -machine "${machine}" \
@ -169,7 +168,7 @@ EOF
-pidfile "${AYA_TMPDIR}/vm.pid" \ -pidfile "${AYA_TMPDIR}/vm.pid" \
-device virtio-net-pci,netdev=net0 \ -device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \ -netdev user,id=net0,hostfwd=tcp::2222-:22 \
$uefi \ "${uefi[@]}" \
-drive if=virtio,format=qcow2,file="${AYA_IMGDIR}/vm.qcow2" \ -drive if=virtio,format=qcow2,file="${AYA_IMGDIR}/vm.qcow2" \
-drive if=virtio,format=raw,file="${AYA_TMPDIR}/seed.img" || return 1 -drive if=virtio,format=raw,file="${AYA_TMPDIR}/seed.img" || return 1
@ -177,7 +176,7 @@ EOF
echo "Waiting for SSH on port 2222..." echo "Waiting for SSH on port 2222..."
retry=0 retry=0
max_retries=300 max_retries=300
while ! ssh -q -F "${AYA_TMPDIR}/ssh_config" -o ConnectTimeout=1 -i "${AYA_TMPDIR}/test_rsa" ${AYA_SSH_USER}@localhost -p 2222 echo "Hello VM"; do while ! ssh -q -F "${AYA_TMPDIR}/ssh_config" -o ConnectTimeout=1 -i "${AYA_TMPDIR}/test_rsa" "${AYA_SSH_USER}"@localhost -p 2222 echo "Hello VM"; do
retry=$((retry+1)) retry=$((retry+1))
if [ ${retry} -gt ${max_retries} ]; then if [ ${retry} -gt ${max_retries} ]; then
echo "Unable to connect to VM" echo "Unable to connect to VM"
@ -209,14 +208,14 @@ scp_vm() {
} }
rsync_vm() { rsync_vm() {
rsync -a -e "ssh -p 2222 -F ${AYA_TMPDIR}/ssh_config -i ${AYA_TMPDIR}/test_rsa" $1 $AYA_SSH_USER@localhost: rsync -a -e "ssh -p 2222 -F ${AYA_TMPDIR}/ssh_config -i ${AYA_TMPDIR}/test_rsa" "$1" "$AYA_SSH_USER"@localhost:
} }
exec_vm() { exec_vm() {
ssh -q -F "${AYA_TMPDIR}/ssh_config" \ ssh -q -F "${AYA_TMPDIR}/ssh_config" \
-i "${AYA_TMPDIR}/test_rsa" \ -i "${AYA_TMPDIR}/test_rsa" \
-p 2222 \ -p 2222 \
${AYA_SSH_USER}@localhost \ "${AYA_SSH_USER}"@localhost \
"$@" "$@"
} }
@ -229,8 +228,7 @@ stop_vm() {
} }
cleanup_vm() { cleanup_vm() {
stop_vm if ! stop_vm; then
if [ "$?" != "0" ]; then
rm -f "${AYA_IMGDIR}/vm.qcow2" rm -f "${AYA_IMGDIR}/vm.qcow2"
fi fi
} }

Loading…
Cancel
Save