From a8d7841bc123409795e5ed23b8b94d2124f28a21 Mon Sep 17 00:00:00 2001 From: Jiri Kortus Date: Fri, 6 Sep 2019 18:56:19 +0200 Subject: [PATCH] [tests] Use a function to wait for compose to finish The function is meant to replace the duplicate pieces of code used in various tests, the polling interval is unified to 20 seconds. Cherry-picked from 836f0ddf Related: rhbz#1770193 --- tests/cli/lib/lib.sh | 23 ++++++++++++++++++++ tests/cli/test_build_and_deploy_aws.sh | 9 +------- tests/cli/test_build_and_deploy_azure.sh | 9 +------- tests/cli/test_build_and_deploy_openstack.sh | 9 +------- tests/cli/test_build_and_deploy_vmware.sh | 9 +------- tests/cli/test_compose_ext4-filesystem.sh | 9 +------- tests/cli/test_compose_live-iso.sh | 9 +------- tests/cli/test_compose_partitioned-disk.sh | 9 +------- tests/cli/test_compose_qcow2.sh | 10 +-------- tests/cli/test_compose_sanity.sh | 8 ++----- tests/cli/test_compose_tar.sh | 9 +------- 11 files changed, 34 insertions(+), 79 deletions(-) diff --git a/tests/cli/lib/lib.sh b/tests/cli/lib/lib.sh index cdf46ba8..cdc074b9 100755 --- a/tests/cli/lib/lib.sh +++ b/tests/cli/lib/lib.sh @@ -143,3 +143,26 @@ check_kernel_cmdline() { rlRun -t -c "ssh $SSH_OPTS ${SSH_USER}@${SSH_MACHINE} 'grep custom_cmdline_arg /proc/cmdline'" 0 \ "System booted from the image contains specified parameter on kernel command line" } + +# Fail if the compose failed, only call after checking for FINISHED|FAILED +check_compose_status() { + UUID="$1" + if "$CLI" compose details "$UUID" | grep FAILED; then + rlFail "compose $UUID FAILED" + return 1 + fi +} + +# Wait until the compose is done (finished or failed) +wait_for_compose() { + local UUID=$1 + if [ -n "$UUID" ]; then + until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do + sleep 20 + rlLogInfo "Waiting for compose to finish ..." + done; + check_compose_status "$UUID" + else + rlFail "Compose UUID is empty!" + fi +} diff --git a/tests/cli/test_build_and_deploy_aws.sh b/tests/cli/test_build_and_deploy_aws.sh index 38e508cc..04b1419a 100755 --- a/tests/cli/test_build_and_deploy_aws.sh +++ b/tests/cli/test_build_and_deploy_aws.sh @@ -88,14 +88,7 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - rlLogInfo "Waiting for compose to finish ..." - sleep 30 - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartTest "Import AMI image in AWS" diff --git a/tests/cli/test_build_and_deploy_azure.sh b/tests/cli/test_build_and_deploy_azure.sh index b0077046..7eae471c 100755 --- a/tests/cli/test_build_and_deploy_azure.sh +++ b/tests/cli/test_build_and_deploy_azure.sh @@ -75,14 +75,7 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - rlLogInfo "Waiting for compose to finish ..." - sleep 30 - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartTest "Upload image to Azure" diff --git a/tests/cli/test_build_and_deploy_openstack.sh b/tests/cli/test_build_and_deploy_openstack.sh index c9064ce2..e0efff78 100755 --- a/tests/cli/test_build_and_deploy_openstack.sh +++ b/tests/cli/test_build_and_deploy_openstack.sh @@ -83,14 +83,7 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - rlLogInfo "Waiting for compose to finish ..." - sleep 30 - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartTest "Upload QCOW2 image to OpenStack" diff --git a/tests/cli/test_build_and_deploy_vmware.sh b/tests/cli/test_build_and_deploy_vmware.sh index b55f2efe..aa38d33f 100755 --- a/tests/cli/test_build_and_deploy_vmware.sh +++ b/tests/cli/test_build_and_deploy_vmware.sh @@ -104,14 +104,7 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - rlLogInfo "Waiting for compose to finish ..." - sleep 30 - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartTest "Upload VMDK image in vCenter" diff --git a/tests/cli/test_compose_ext4-filesystem.sh b/tests/cli/test_compose_ext4-filesystem.sh index 92192199..7440f65e 100755 --- a/tests/cli/test_compose_ext4-filesystem.sh +++ b/tests/cli/test_compose_ext4-filesystem.sh @@ -27,14 +27,7 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 60 - rlLogInfo "Waiting for compose to finish ..." - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartCleanup diff --git a/tests/cli/test_compose_live-iso.sh b/tests/cli/test_compose_live-iso.sh index f6c84900..0d7019df 100755 --- a/tests/cli/test_compose_live-iso.sh +++ b/tests/cli/test_compose_live-iso.sh @@ -44,14 +44,7 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 20 - rlLogInfo "Waiting for compose to finish ..." - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlRun -t -c "$CLI compose image $UUID" IMAGE="$UUID-live.iso" diff --git a/tests/cli/test_compose_partitioned-disk.sh b/tests/cli/test_compose_partitioned-disk.sh index 2edd084d..b2fa5dfe 100755 --- a/tests/cli/test_compose_partitioned-disk.sh +++ b/tests/cli/test_compose_partitioned-disk.sh @@ -27,14 +27,7 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 60 - rlLogInfo "Waiting for compose to finish ..." - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID rlPhaseEnd rlPhaseStartCleanup diff --git a/tests/cli/test_compose_qcow2.sh b/tests/cli/test_compose_qcow2.sh index 59852453..ec37f932 100755 --- a/tests/cli/test_compose_qcow2.sh +++ b/tests/cli/test_compose_qcow2.sh @@ -58,15 +58,7 @@ __EOF__ rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 20 - rlLogInfo "Waiting for compose to finish ..." - done; - else - rlFail "Compose UUID is empty!" - fi - + wait_for_compose $UUID rlRun -t -c "$CLI compose image $UUID" IMAGE="$UUID-disk.qcow2" rlPhaseEnd diff --git a/tests/cli/test_compose_sanity.sh b/tests/cli/test_compose_sanity.sh index e94ffc8e..bab94de6 100755 --- a/tests/cli/test_compose_sanity.sh +++ b/tests/cli/test_compose_sanity.sh @@ -31,11 +31,9 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "compose image" + wait_for_compose $UUID if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 60 - rlLogInfo "Waiting for compose to finish ..." - done; + check_compose_status "$UUID" rlRun -t -c "$CLI compose image $UUID" rlAssertExists "$UUID-root.tar.xz" @@ -44,8 +42,6 @@ rlJournalStart rlAssertExists "/var/lib/lorax/composer/results/$UUID/" rlAssertExists "/var/lib/lorax/composer/results/$UUID/root.tar.xz" rlAssertNotDiffer "/var/lib/lorax/composer/results/$UUID/root.tar.xz" "$UUID-root.tar.xz" - else - rlFail "Compose UUID is empty!" fi rlPhaseEnd diff --git a/tests/cli/test_compose_tar.sh b/tests/cli/test_compose_tar.sh index cf1f300a..c14b49e2 100755 --- a/tests/cli/test_compose_tar.sh +++ b/tests/cli/test_compose_tar.sh @@ -30,14 +30,7 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest "compose finished" - if [ -n "$UUID" ]; then - until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do - sleep 10 - rlLogInfo "Waiting for compose to finish ..." - done; - else - rlFail "Compose UUID is empty!" - fi + wait_for_compose $UUID # Running a compose can lead to a different selinux policy in the # kernel, which may break docker. Reload the policy from the host and