diff --git a/tests/README.md b/tests/README.md index a2c05a66..96586942 100644 --- a/tests/README.md +++ b/tests/README.md @@ -6,7 +6,7 @@ Tests are divided into two groups: - Tests in the `vmcheck` directory are destructive and installed. They are run inside a VM. Use `make vmcheck` to - run these. + run these (see also `HACKING.md` in the top directory). The `common` directory contains files used by multiple tests. The `utils` directory contains helper utilities diff --git a/tests/common/libvm.sh b/tests/common/libvm.sh index a314af4b..5abb43e1 100644 --- a/tests/common/libvm.sh +++ b/tests/common/libvm.sh @@ -33,18 +33,25 @@ vm_send() { } # wait until ssh is available on the vm +# - $1 timeout in second (optional) vm_ssh_wait() { - # XXX: add timeout - while ! vm_cmd true &> /dev/null; do + timeout=${1:-0} + while [ $timeout -gt 0 ]; do + if vm_cmd true &> /dev/null; then + return 0 + fi + timeout=$((timeout - 1)) sleep 1 done + # final check at the timeout mark + vm_cmd true &> /dev/null } # reboot the vm vm_reboot() { vm_cmd systemctl reboot || : sleep 2 # give time for port to go down - vm_ssh_wait + vm_ssh_wait 10 } # check that the given files exist on the VM diff --git a/tests/vmcheck/test.sh b/tests/vmcheck/test.sh index 9896114a..21f3754a 100644 --- a/tests/vmcheck/test.sh +++ b/tests/vmcheck/test.sh @@ -9,8 +9,10 @@ echo " ControlPersist yes" >> ssh-config export SSH="ssh -F $PWD/ssh-config vmcheck" export SCP="scp -F $PWD/ssh-config" +. ${commondir}/libvm.sh + # stand up ssh connection and sanity check that it all works -if ! $SSH true &> /dev/null; then +if ! vm_ssh_wait 10; then echo "ERROR: A running VM is required for 'make vmcheck'." exit 1 fi