Skip to content

Commit

Permalink
test: run content tests on CVM images (#4881)
Browse files Browse the repository at this point in the history
Co-authored-by: Zachary Bailey <[email protected]>
  • Loading branch information
zachary-bailey and Zachary Bailey authored Aug 29, 2024
1 parent 42f9233 commit 84d50ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .pipelines/templates/.builder-release-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ steps:
OS_DISK_URI="$(cat packer-output | grep "OSDiskUri:" | cut -d " " -f 2)" && \
MANAGED_SIG_ID="$(cat packer-output | grep "ManagedImageSharedImageGalleryId:" | cut -d " " -f 2)" && \
PKR_RG_NAME="$(cat packer-output | grep "ResourceGroupName" | cut -d "'" -f 2 | head -1)" && \
SIG_GALLERY_NAME="$(cat vhdbuilder/packer/settings.json | grep "sig_gallery_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
CAPTURED_SIG_VERSION="$(cat vhdbuilder/packer/settings.json | grep "captured_sig_version" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
IMPORTED_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "imported_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
SIG_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "sig_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
Expand Down
39 changes: 23 additions & 16 deletions vhdbuilder/packer/test-scan-and-cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
#!/bin/bash

# TODO: assert required variables are set
required_env_vars=(
"SIG_IMAGE_NAME"
"AZURE_RESOURCE_GROUP_NAME"
"CAPTURED_SIG_VERSION"
"ENVIRONMENT"
"SIG_GALLERY_NAME"
"OS_VERSION"
"SIG_IMAGE_NAME"
)

for v in "${required_env_vars[@]}"; do
if [ -z "${!v}" ]; then
echo "$v was not set!"
exit 1
fi
done

retrycmd_if_failure() {
RETRIES=${1}; WAIT_SLEEP=${2}; CMD=${3}; TARGET=$(basename ${3} .sh)
Expand All @@ -22,33 +37,25 @@ retrycmd_if_failure() {
cat ${TARGET}-output.txt && rm ${TARGET}-output.txt
}

if [[ -z "$SIG_GALLERY_NAME" ]]; then
SIG_GALLERY_NAME="PackerSigGalleryEastUS"
fi

# Always run cleanup
SCRIPT_ARRAY+=("./vhdbuilder/packer/cleanup.sh")

# Check to ensure the build step succeeded
SIG_VERSION=$(az sig image-version show \
-e ${CAPTURED_SIG_VERSION} \
-i ${SIG_IMAGE_NAME} \
-r ${SIG_GALLERY_NAME} \
-g ${AZURE_RESOURCE_GROUP_NAME} \
--query id --output tsv)
-e ${CAPTURED_SIG_VERSION} \
-i ${SIG_IMAGE_NAME} \
-r ${SIG_GALLERY_NAME} \
-g ${AZURE_RESOURCE_GROUP_NAME} \
--query id --output tsv)

if [ -z "${SIG_VERSION}" ]; then
echo -e "\nBuild step did not produce an image version. Running cleanup and then exiting."
retrycmd_if_failure 2 3 "${SCRIPT_ARRAY[@]}"
exit $?
fi

# Setup tests
if [ "$IMG_SKU" != "20_04-lts-cvm" ]; then
SCRIPT_ARRAY+=("./vhdbuilder/packer/test/run-test.sh")
else
echo -e "\n\nSkipping tests for CVM 20.04"
fi
# Setup testing
SCRIPT_ARRAY+=("./vhdbuilder/packer/test/run-test.sh")

# Setup scanning
echo -e "\nENVIRONMENT is: ${ENVIRONMENT}, OS_VERSION is: ${OS_VERSION}"
Expand Down

0 comments on commit 84d50ff

Please sign in to comment.