From 8ef0cfe618974e0fb231569198299e95ab2a78ab Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 5 Nov 2021 14:33:45 +0100 Subject: [PATCH] test/cases: support weldr-client output structure Using get_build_info() function in all scripts where both composer-cli and weldr-client need to be supported for consistency. --- test/cases/aws.sh | 21 +++++++++--------- test/cases/azure.sh | 21 +++++++++--------- test/cases/filesystem.sh | 21 +++++++++--------- test/cases/ostree-ng.sh | 14 ++++++++++-- test/cases/ostree-raw-image.sh | 13 +++++++++-- test/cases/ostree-simplified-installer.sh | 13 +++++++++-- ...ression-composer-works-behind-satellite.sh | 21 +++++++++--------- test/cases/regression-excluded-dependency.sh | 21 +++++++++--------- .../regression-old-worker-new-composer.sh | 21 +++++++++--------- test/cases/vmware.sh | 22 ++++++++++--------- 10 files changed, 112 insertions(+), 76 deletions(-) diff --git a/test/cases/aws.sh b/test/cases/aws.sh index 466c881bd..7365e60cd 100755 --- a/test/cases/aws.sh +++ b/test/cases/aws.sh @@ -8,6 +8,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" @@ -164,21 +173,13 @@ trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to AWS. greenprint "🚀 Starting compose" sudo composer-cli --json compose start bash ami "$IMAGE_KEY" "$AWS_CONFIG" | tee "$COMPOSE_START" -if [ "$(is_weldr_client_installed)" == true ]; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") -else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") -fi +COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if [ "$(is_weldr_client_installed)" == true ]; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/azure.sh b/test/cases/azure.sh index 115c942a2..563bb35ef 100755 --- a/test/cases/azure.sh +++ b/test/cases/azure.sh @@ -12,6 +12,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + # Container image used for cloud provider CLI tools CONTAINER_IMAGE_CLOUD_TOOLS="quay.io/osbuild/cloud-tools:latest" @@ -184,21 +193,13 @@ trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to Azure. greenprint "🚀 Starting compose" sudo composer-cli --json compose start bash vhd "$IMAGE_KEY" "$AZURE_CONFIG" | tee "$COMPOSE_START" -if [ "$(is_weldr_client_installed)" == true ]; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") -else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") -fi +COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if [ "$(is_weldr_client_installed)" == true ]; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/filesystem.sh b/test/cases/filesystem.sh index 783976bf8..d404ed8ed 100644 --- a/test/cases/filesystem.sh +++ b/test/cases/filesystem.sh @@ -24,6 +24,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + TEST_UUID=$(uuidgen) IMAGE_KEY="osbuild-composer-test-${TEST_UUID}" @@ -81,22 +90,14 @@ build_image() { fi return else - if rpm -q --quiet weldr-client; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") - else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") - fi + COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") fi # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if rpm -q --quiet weldr-client; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/ostree-ng.sh b/test/cases/ostree-ng.sh index 3b40f2735..daf805b49 100755 --- a/test/cases/ostree-ng.sh +++ b/test/cases/ostree-ng.sh @@ -12,6 +12,16 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + + # Install openshift client greenprint "🔧 Installing oenshift client(oc)" curl https://osbuild-storage.s3.amazonaws.com/oc-4.9.0-linux.tar.gz | sudo tar -xz -C /usr/local/bin/ @@ -161,13 +171,13 @@ build_image() { else sudo composer-cli --json compose start-ostree --ref "$OSTREE_REF" "$blueprint_name" "$image_type" | tee "$COMPOSE_START" fi - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") + COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/ostree-raw-image.sh b/test/cases/ostree-raw-image.sh index 21bc17b9a..f6e9ec1f9 100755 --- a/test/cases/ostree-raw-image.sh +++ b/test/cases/ostree-raw-image.sh @@ -13,6 +13,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + # Start libvirtd and test it. greenprint "🚀 Starting libvirt daemon" sudo systemctl start libvirtd @@ -143,13 +152,13 @@ build_image() { else sudo composer-cli --json compose start-ostree --ref "$OSTREE_REF" "$blueprint_name" "$image_type" | tee "$COMPOSE_START" fi - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") + COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/ostree-simplified-installer.sh b/test/cases/ostree-simplified-installer.sh index 6429bb460..26925c704 100755 --- a/test/cases/ostree-simplified-installer.sh +++ b/test/cases/ostree-simplified-installer.sh @@ -13,6 +13,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + # Start firewalld sudo systemctl enable --now firewalld @@ -152,13 +161,13 @@ build_image() { else sudo composer-cli --json compose start-ostree --ref "$OSTREE_REF" "$blueprint_name" "$image_type" | tee "$COMPOSE_START" fi - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") + COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/regression-composer-works-behind-satellite.sh b/test/cases/regression-composer-works-behind-satellite.sh index 0b7a3778b..5c137e860 100644 --- a/test/cases/regression-composer-works-behind-satellite.sh +++ b/test/cases/regression-composer-works-behind-satellite.sh @@ -6,6 +6,15 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + function generate_certificates { # Generate CA root key sudo openssl genrsa -out ca.key @@ -311,21 +320,13 @@ function try_image_build { sudo journalctl -xe --unit osbuild-worker exit 1 fi - if rpm -q --quiet weldr-client; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") - else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") - fi + COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "${COMPOSE_INFO}" > /dev/null - if rpm -q --quiet weldr-client; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/regression-excluded-dependency.sh b/test/cases/regression-excluded-dependency.sh index 66a67e901..590c451f7 100644 --- a/test/cases/regression-excluded-dependency.sh +++ b/test/cases/regression-excluded-dependency.sh @@ -29,6 +29,15 @@ esac set -xeuo pipefail +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + # Provision the software under test. BLUEPRINT_FILE=/tmp/blueprint.toml COMPOSE_START=/tmp/compose-start.json @@ -50,20 +59,12 @@ EOF sudo composer-cli blueprints push "$BLUEPRINT_FILE" sudo composer-cli blueprints depsolve nss-devel sudo composer-cli --json compose start nss-devel qcow2 | tee "${COMPOSE_START}" -if rpm -q --quiet weldr-client; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") -else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") -fi +COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. echo "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if rpm -q --quiet weldr-client; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/regression-old-worker-new-composer.sh b/test/cases/regression-old-worker-new-composer.sh index a3ccab7d2..25bf75dd9 100644 --- a/test/cases/regression-old-worker-new-composer.sh +++ b/test/cases/regression-old-worker-new-composer.sh @@ -7,6 +7,15 @@ set -exuo pipefail +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + WORKER_VERSION=8f21f0b873420a38a261d78a7df130f28b8e2867 WORKER_RPM=osbuild-composer-worker-33-1.20210830git8f21f0b.el8.x86_64 @@ -92,21 +101,13 @@ EOF2 sudo composer-cli -s "$WELDR_SOCK" blueprints push "$BLUEPRINT_FILE" sudo composer-cli -s "$WELDR_SOCK" blueprints depsolve simple sudo composer-cli -s "$WELDR_SOCK" --json compose start simple qcow2 | tee "${COMPOSE_START}" -if rpm -q --quiet weldr-client; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") -else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") -fi +COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. echo "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli -s "$WELDR_SOCK" --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if rpm -q --quiet weldr-client; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then diff --git a/test/cases/vmware.sh b/test/cases/vmware.sh index 55e43586d..254412f6e 100755 --- a/test/cases/vmware.sh +++ b/test/cases/vmware.sh @@ -8,6 +8,16 @@ function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function get_build_info() { + key="$1" + fname="$2" + if rpm -q --quiet weldr-client; then + key=".body${key}" + fi + jq -r "${key}" "${fname}" +} + + if [ "$ID" != "rhel" ]; then greenprint "VMware test not supported on $ID" exit 0 @@ -139,21 +149,13 @@ trap 'sudo pkill -P ${WORKER_JOURNAL_PID}' EXIT # Start the compose and upload to VMWare. greenprint "🚀 Starting compose" sudo composer-cli --json compose start bash vmdk "$IMAGE_KEY" "$VMWARE_CONFIG" | tee "$COMPOSE_START" -if rpm -q --quiet weldr-client; then - COMPOSE_ID=$(jq -r '.body.build_id' "$COMPOSE_START") -else - COMPOSE_ID=$(jq -r '.build_id' "$COMPOSE_START") -fi +COMPOSE_ID=$(get_build_info ".build_id" "$COMPOSE_START") # Wait for the compose to finish. greenprint "⏱ Waiting for compose to finish: ${COMPOSE_ID}" while true; do sudo composer-cli --json compose info "${COMPOSE_ID}" | tee "$COMPOSE_INFO" > /dev/null - if rpm -q --quiet weldr-client; then - COMPOSE_STATUS=$(jq -r '.body.queue_status' "$COMPOSE_INFO") - else - COMPOSE_STATUS=$(jq -r '.queue_status' "$COMPOSE_INFO") - fi + COMPOSE_STATUS=$(get_build_info ".queue_status" "$COMPOSE_INFO") # Is the compose finished? if [[ $COMPOSE_STATUS != RUNNING ]] && [[ $COMPOSE_STATUS != WAITING ]]; then