Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 178 lines (147 sloc) 5.43 KB
#!/bin/bash
# git-ubuntu integration test wrapper
#
# Copyright 2017 Canonical Ltd.
# Joshua Powers <josh.powers@canonical.com>
VERBOSITY=0
TEMP_D=""
ARCH="$(dpkg --print-architecture)"
LTS=$(distro-info --lts)
NAME_RAND=$(uuidgen -r | cut -c1-8)
VM_LTS="$LTS-$NAME_RAND"
error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
bad_usage() { usage 1>&2; return 1; }
cleanup() {
[ -z "${TEMP_D}" ] || [ ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
vm_destroy "$VM_LTS"
}
debug() {
local level=${1}; shift;
[ "${level}" -gt "${VERBOSITY}" ] && return
error "${@}"
}
usage() {
cat <<EOF
Usage: ${0##*/} [ -hv ] [ -u repo_url ]
git-ubuntu integration test wrapper
options:
-b --branch Specific branch to checkout, default: master
-u --url URL to repo to build and run tests from,
default: https://git.launchpad.net/usd-importer
EOF
}
vm_launch() {
local name=$1 release=$2
shift 2
uvt-simplestreams-libvirt --verbose \
sync --source http://cloud-images.ubuntu.com/daily \
"release~($release)" arch="$ARCH"
uvt-kvm create "$name" release="$release" label=daily
uvt-kvm wait --insecure "$name"
}
vm_destroy() {
local name=$1
shift
if virsh list --name | grep -q "$name"; then
uvt-kvm destroy "$name" ||
fail "could not destory $name"
fi
}
vm_exec() {
local name=$1 cmd=$2
shift 2
uvt-kvm ssh --insecure "$name" -- "$cmd" ||
fail "failed: '$cmd'"
}
vm_pull() {
local name=$1 from=$2 to=$3
shift 3
ip=$(uvt-kvm ip "$name")
scp -oStrictHostKeyChecking=no "ubuntu@$ip:$from" "$to" ||
fail "pull: failed to pull '$from' to '$to'"
}
vm_push() {
local name=$1 from=$2 to=$3
shift 3
ip=$(uvt-kvm ip "$name")
scp -oStrictHostKeyChecking=no "$from" "ubuntu@$ip:$to" ||
fail "push: failed to push '$from' to '$to'"
}
main() {
local short_opts="b:hu:v"
local long_opts="branch:,help,url:,verbose"
local getopt_out=""
getopt_out=$(getopt --name "${0##*/}" \
--options "${short_opts}" --long "${long_opts}" -- "$@") ||
{ bad_usage; return; }
eval set -- "${getopt_out}" ||
{ bad_usage; return; }
local url="https://git.launchpad.net/usd-importer"
local branch="master"
local cur="" next=""
while [ $# -ne 0 ]; do
cur="$1"; next="$2";
case "$cur" in
-b|--branch) branch=$next; shift;;
-h|--help) usage ; exit 0;;
-u|--url) url=$next; shift;;
-v|--verbose) VERBOSITY=$((VERBOSITY+1));;
--) shift; break;;
esac
shift;
done
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
fail "failed to make tempdir"
trap cleanup EXIT
# program starts here
echo "testing $branch@$url"
echo "setup: creating $LTS VM to build and test snap"
vm_launch "$VM_LTS" "$LTS" ||
fail "could not create $LTS VM"
if [ ! -z "${https_proxy-}" ]; then
echo "setup: configuring lxc profile https_proxy"
vm_exec "$VM_LTS" "lxc profile set default environment.https_proxy ${https_proxy}"
vm_exec "$VM_LTS" "echo 'export https_proxy=${https_proxy}' > ~/.bashrc"
fi
if [ ! -z "${http_proxy-}" ]; then
echo "setup: configuring lxc profile http_proxy"
vm_exec "$VM_LTS" "lxc profile set default environment.http_proxy ${http_proxy}"
vm_exec "$VM_LTS" "echo 'export http_proxy=${http_proxy}' > ~/.bashrc"
fi
# Configure LXD networking
echo "setup: configuring LXD networking"
vm_exec "$VM_LTS" "sudo sed -i 's/LXD_IPV4_ADDR=\"\"/LXD_IPV4_ADDR=\"10.158.98.1\"/' /etc/default/lxd-bridge"
vm_exec "$VM_LTS" "sudo sed -i 's/LXD_IPV4_NETMASK=\"\"/LXD_IPV4_NETMASK=\"255.255.255.0\"/' /etc/default/lxd-bridge"
vm_exec "$VM_LTS" "sudo sed -i 's/LXD_IPV4_NETWORK=\"\"/LXD_IPV4_NETWORK=\"10.158.98.1\/24\"/' /etc/default/lxd-bridge"
vm_exec "$VM_LTS" "sudo sed -i 's/LXD_IPV4_DHCP_RANGE=\"\"/LXD_IPV4_DHCP_RANGE=\"10.158.98.2,10.158.98.254\"/' /etc/default/lxd-bridge"
vm_exec "$VM_LTS" "sudo sed -i 's/LXD_IPV4_DHCP_MAX=\"\"/LXD_IPV4_DHCP_MAX=\"252\"/' /etc/default/lxd-bridge"
vm_exec "$VM_LTS" "sudo lxd init --auto"
vm_exec "$VM_LTS" "sudo dpkg-reconfigure -fnoninteractive -p medium lxd"
# Configure Git
echo "setup: congiuring git user info"
vm_exec "$VM_LTS" "git config --global gitubuntu.lpuser usd-importer-bot"
vm_exec "$VM_LTS" "git config --global user.email \"test@ubuntu.com\""
vm_exec "$VM_LTS" "git config --global user.name \"Test User\""
# Install dependencies
echo "setup: installing dependnecies"
vm_exec "$VM_LTS" "sudo apt-get update"
vm_exec "$VM_LTS" "sudo apt-get install -y snapcraft"
echo "setup: installing core snap"
vm_exec "$VM_LTS" "sudo snap install core"
# Build, Install, & Test
echo "setup: cloning git-ubuntu branch"
vm_exec "$VM_LTS" "git clone -b $branch $url git-ubuntu"
echo "setup: building snap"
vm_exec "$VM_LTS" "cd git-ubuntu; snapcraft cleanbuild" ||
fail "Building snap failed!"
echo "setup: installing newly built snap"
vm_exec "$VM_LTS" "sudo snap install --dangerous --classic git-ubuntu/git-ubuntu_*_amd64.snap"
vm_exec "$VM_LTS" "snap list"
echo "setup: running integration test"
vm_exec "$VM_LTS" "bash -l -c ./git-ubuntu/tests/bin/integration-test"
vm_destroy "$VM_LTS"
return 0
}
main "$@"
# vi: ts=4 noexpandtab