mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-05 15:57:23 +01:00
Add Vagrant support for running automated tests
This commit is contained in:
3
tests/vagrant/.gitignore
vendored
Normal file
3
tests/vagrant/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.vagrant
|
||||
out
|
||||
*-console.log
|
||||
42
tests/vagrant/Vagrantfile
vendored
Normal file
42
tests/vagrant/Vagrantfile
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
|
||||
config.vm.synced_folder "../..", "/mailinabox", id: "mailinabox", automount: false
|
||||
config.vm.provision "file", source:"globals.sh", destination:"globals.sh"
|
||||
|
||||
# remote-nextcloud-docker
|
||||
|
||||
config.vm.define "remote-nextcloud-docker" do |m1|
|
||||
m1.vm.box = "ubuntu/bionic64"
|
||||
m1.vm.provision :shell, :inline => <<-SH
|
||||
source globals.sh || exit 1
|
||||
export PRIMARY_HOSTNAME=qa1.abc.com
|
||||
export FEATURE_MUNIN=false
|
||||
cd /mailinabox
|
||||
if tests/system-setup/remote-nextcloud-docker.sh upgrade basic
|
||||
then
|
||||
tests/runner.sh default remote-nextcloud upgrade-basic
|
||||
fi
|
||||
echo "EXITCODE: $?"
|
||||
SH
|
||||
end
|
||||
|
||||
|
||||
# upgrade-from-upstream
|
||||
|
||||
config.vm.define "upgrade-from-upstream" do |m2|
|
||||
m2.vm.box = "ubuntu/bionic64"
|
||||
m2.vm.provision :shell, :inline => <<-SH
|
||||
source globals.sh || exit 1
|
||||
export PRIMARY_HOSTNAME=qa2.abc.com
|
||||
export UPSTREAM_TAG=master
|
||||
cd /mailinabox
|
||||
if tests/system-setup/upgrade-from-upstream.sh basic
|
||||
then
|
||||
tests/runner.sh default upgrade-basic
|
||||
fi
|
||||
echo "EXITCODE: $?"
|
||||
SH
|
||||
end
|
||||
|
||||
end
|
||||
2
tests/vagrant/globals.sh
Normal file
2
tests/vagrant/globals.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
export MIAB_LDAP_PROJECT=true
|
||||
export LOCAL_MODS_DIR=/local
|
||||
71
tests/vagrant/parallel.sh
Executable file
71
tests/vagrant/parallel.sh
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Parallel provisioning for virtualbox because "The Vagrant VirtualBox
|
||||
# provider does not support parallel execution at this time"
|
||||
# (https://www.vagrantup.com/docs/providers/virtualbox/usage.html)
|
||||
#
|
||||
# Credit to:
|
||||
# https://dzone.com/articles/parallel-provisioning-speeding
|
||||
#
|
||||
|
||||
. "$(dirname "$0")/../lib/color-output.sh"
|
||||
. "$(dirname "$0")/../lib/misc.sh"
|
||||
|
||||
|
||||
OUTPUT_DIR=out
|
||||
rm -rf "$OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# set total parallel vms to (#cores minus 1)
|
||||
MAX_PROCS=$(cat /proc/cpuinfo | grep processor | wc -l)
|
||||
let MAX_PROCS-=1
|
||||
|
||||
|
||||
parallel_provision() {
|
||||
while read box; do
|
||||
outfile="$OUTPUT_DIR/$box.out.txt"
|
||||
echo "Provisioning '$box'. Output will be in: $outfile" 1>&2
|
||||
echo $box
|
||||
done | xargs -P $MAX_PROCS -I"BOXNAME" \
|
||||
sh -c 'vagrant provision BOXNAME >'"$OUTPUT_DIR/"'BOXNAME.out.txt 2>&1 || echo "Error Occurred: BOXNAME"'
|
||||
}
|
||||
|
||||
## -- main -- ##
|
||||
|
||||
start_time="$(date +%s)"
|
||||
|
||||
# start boxes sequentially to avoid vbox explosions
|
||||
vagrant up --no-provision
|
||||
|
||||
# but run provision tasks in parallel
|
||||
vagrant status | grep running | awk '{print $1}' | parallel_provision
|
||||
|
||||
|
||||
# output overall result - Vagrantfile script must output "EXITCODE: <num>"
|
||||
H1 "Results"
|
||||
|
||||
rc=0
|
||||
for file in "$OUTPUT_DIR"/*.out.txt; do
|
||||
box=$(basename $file | awk -F. '{print $1}')
|
||||
exitcode="$(tail "$file" | grep EXITCODE: | awk '{print $NF}')"
|
||||
echo -n "$box: "
|
||||
if [ -z "$exitcode" ]; then
|
||||
danger "NO EXITCODE!"
|
||||
[ $rc -eq 0 ] && rc=2
|
||||
elif [ "$exitcode" == "0" ]; then
|
||||
success "SUCCESS"
|
||||
else
|
||||
danger "FAILURE ($exitcode)"
|
||||
rc=1
|
||||
fi
|
||||
done
|
||||
|
||||
# output elapsed time
|
||||
end_time="$(date +%s)"
|
||||
echo ""
|
||||
echo "Elapsed time: $(elapsed_pretty $start_time $end_time)"
|
||||
|
||||
# exit
|
||||
echo ""
|
||||
echo "Guest VMs are running! Destroy them with 'vagrant destroy -f'"
|
||||
exit $rc
|
||||
Reference in New Issue
Block a user