From beff4f696785618e0dc51670bb52532067a6b2a6 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 23 Jul 2019 09:42:41 -0700 Subject: [PATCH] tests: Use a loop to wait for VM and sshd to start --- tests/cli/lib/lib.sh | 22 ++++++++++++++++++++++ tests/cli/test_compose_live-iso.sh | 12 +++--------- tests/cli/test_compose_qcow2.sh | 8 ++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/cli/lib/lib.sh b/tests/cli/lib/lib.sh index e22494e8..62a5fb26 100755 --- a/tests/cli/lib/lib.sh +++ b/tests/cli/lib/lib.sh @@ -16,6 +16,28 @@ if [ "$COMPOSER_TEST_FAIL_FAST" == "1" ]; then } fi +export QEMU_BIN="/usr/bin/qemu-system-$(uname -m)" +export QEMU="$QEMU_BIN -machine accel=kvm:tcg" +export SSH_PORT=2222 + +boot_image() { + QEMU_BOOT=$1 + TIMEOUT=$2 + rlRun -t -c "$QEMU -m 2048 $QEMU_BOOT -nographic -monitor none \ + -net user,id=nic0,hostfwd=tcp::$SSH_PORT-:22 -net nic &" + # wait for ssh to become ready (yes, http is the wrong protocol, but it returns the header) + tries=0 + until curl -sS -m 15 "http://localhost:$SSH_PORT/" | grep 'OpenSSH'; do + tries=$((tries + 1)) + if [ $tries -gt $TIMEOUT ]; then + exit 1 + fi + sleep 1 + echo "DEBUG: Waiting for ssh become ready before testing ..." + done; +} + + # a generic helper function unifying the specific checks executed on a running # image instance verify_image() { diff --git a/tests/cli/test_compose_live-iso.sh b/tests/cli/test_compose_live-iso.sh index 3d143748..dbedd6d3 100755 --- a/tests/cli/test_compose_live-iso.sh +++ b/tests/cli/test_compose_live-iso.sh @@ -13,8 +13,6 @@ set -e . $(dirname $0)/lib/lib.sh CLI="${CLI:-./src/bin/composer-cli}" -QEMU_BIN="/usr/bin/qemu-system-$(uname -m)" -QEMU="$QEMU_BIN -machine accel=kvm:tcg" rlJournalStart rlPhaseStartSetup @@ -47,16 +45,12 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "Start VM instance" - rlRun -t -c "$QEMU -m 2048 -boot d -cdrom $IMAGE -nographic -monitor none \ - -net user,id=nic0,hostfwd=tcp::2222-:22 -net nic &" - # 60 seconds timeout at boot menu screen - # then media check + boot ~ 30 seconds - sleep 120 + boot_image "-boot d -cdrom $IMAGE" 120 rlPhaseEnd rlPhaseStartTest "Verify VM instance" - # run generic tests to verify the instance, log in a liveuser with no password - ROOT_ACCOUNT_LOCKED=0 verify_image liveuser localhost "-p 2222" + # run generic tests to verify the instance + ROOT_ACCOUNT_LOCKED=0 verify_image liveuser localhost "-p $SSH_PORT" rlPhaseEnd rlPhaseStartCleanup diff --git a/tests/cli/test_compose_qcow2.sh b/tests/cli/test_compose_qcow2.sh index dd23f709..7c935cb1 100755 --- a/tests/cli/test_compose_qcow2.sh +++ b/tests/cli/test_compose_qcow2.sh @@ -13,8 +13,6 @@ set -e . $(dirname $0)/lib/lib.sh CLI="${CLI:-./src/bin/composer-cli}" -QEMU_BIN="/usr/bin/qemu-system-$(uname -m)" -QEMU="$QEMU_BIN -machine accel=kvm:tcg" rlJournalStart rlPhaseStartSetup @@ -75,14 +73,12 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "Start VM instance" - rlRun -t -c "$QEMU -m 2048 -boot c -hda $IMAGE -nographic -monitor none \ - -net user,id=nic0,hostfwd=tcp::2222-:22 -net nic &" - sleep 60 + boot_image "-boot c -hda $IMAGE" 60 rlPhaseEnd rlPhaseStartTest "Verify VM instance" # run generic tests to verify the instance - verify_image root localhost "-i $SSH_KEY_DIR/id_rsa -p 2222" + verify_image root localhost "-i $SSH_KEY_DIR/id_rsa -p $SSH_PORT" rlPhaseEnd rlPhaseStartCleanup