Something went wrong on our end
Select Git revision
sso_unittest.cc
test-driver 2.54 KiB
#!/bin/sh
# Find the absolute path to this script's directory
# (so that we can find the 'float' root dir).
bin_dir=$(dirname "$0")
bin_dir=${bin_dir:-.}
bin_dir=$(cd "${bin_dir}" && pwd)
float_dir="${bin_dir}"
log() {
echo " ***" >&2
echo " *** $*" >&2
echo " ***" >&2
}
die() {
echo "ERROR: $*" >&2
exit 1
}
start_vagrant() {
log Starting VMs
vagrant box update
vagrant up ${VAGRANT_PROVIDER:+--provider ${VAGRANT_PROVIDER}}
return $?
}
stop_vagrant() {
log Stopping VMs
vagrant destroy --force --parallel
}
wait_for_vms() {
log Waiting for VMs to become available
# Wait at most 30 seconds for the vms to become reachable.
local i=0
local ok=1
while [ $i -lt 10 ]; do
sleep 3
if ansible -v -i config.yml all -m ping; then
ok=0
break
fi
i=$(($i + 1))
done
return $ok
}
save_logs() {
local out_dir="$1"
ANSIBLE_STDOUT_CALLBACK=unixy \
${float_dir}/float run --extra-vars "out_dir=$out_dir" \
${float_dir}/test/save-logs.yml
}
run_init() {
start_vagrant \
|| die "could not start VMs"
wait_for_vms \
|| die "could not reach the VMs with Ansible"
log Running init-credentials playbook
${float_dir}/float run init-credentials.yml \
|| die "failed to run the init-credentials playbook"
log Running main playbook
${float_dir}/float run -vv site.yml \
|| die "failed to run the main playbook"
}
run_cleanup() {
stop_vagrant
}
usage() {
cat <<EOF
Usage: test-driver [COMMAND] [DIR]
Commands:
init Initialize the test environment (turn up VMs, set up
credentials, run the main float playbook)
cleanup Cleanup the test environment (turn down VMs, etc)
run Run the test suite, using the playbooks specified by
the remaining command-line arguments
If DIR is specified, chdir there before running anything.
EOF
exit 2
}
cmd="$1"
shift
if [ $# -gt 0 ]; then
cd "$1"
shift
fi
case "$cmd" in
init)
run_init
;;
cleanup)
save_logs logs
run_cleanup
;;
run)
# The 'yaml' output format has slightly more legible errors.
export ANSIBLE_STDOUT_CALLBACK=yaml
for playbook in "${float_dir}/test/integration-test-docker.yml" "$@"; do
log Running test playbook ${playbook}
${float_dir}/float run ${playbook} \
|| die "test playbook failed"
done
;;
*)
usage
;;
esac
exit 0