test/koji.sh: refactor and extend testing of build metadata
Refactor koji.sh: - Store Koji hub URL in a variable and use it instead of a literal. - Do not inspect builinfo output and don't parse it using grep and sed, but instead directly call Koji XMLRPC functions (using `koji call`) with JSON output. In addition, test that the image archive extra metadata are the same as those stored in the build extra metadata, stored under the image filename. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
347239838c
commit
a610bc3843
1 changed files with 48 additions and 27 deletions
|
|
@ -35,6 +35,9 @@ TEST_TYPE_CLOUD_UPLOAD="cloud-upload"
|
||||||
# test Koji compose via cloudapi without upload to cloud by default
|
# test Koji compose via cloudapi without upload to cloud by default
|
||||||
TEST_TYPE="${1:-$TEST_TYPE_CLOUDAPI}"
|
TEST_TYPE="${1:-$TEST_TYPE_CLOUDAPI}"
|
||||||
|
|
||||||
|
# Koji hub URL to use for testing
|
||||||
|
KOJI_HUB_URL="http://localhost:8080/kojihub"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cloud upload - check environment and prepare it
|
# Cloud upload - check environment and prepare it
|
||||||
#
|
#
|
||||||
|
|
@ -114,12 +117,12 @@ trap cleanups EXIT
|
||||||
|
|
||||||
# Verify that all the expected information is present in the buildinfo
|
# Verify that all the expected information is present in the buildinfo
|
||||||
function verify_buildinfo() {
|
function verify_buildinfo() {
|
||||||
local buildinfo="${1}"
|
local buildid="${1}"
|
||||||
local target_cloud="${2:-none}"
|
local target_cloud="${2:-none}"
|
||||||
|
|
||||||
local extra_build_metadata
|
local extra_build_metadata
|
||||||
# extract the extra build metadata JSON from the output
|
# extract the extra build metadata JSON from the output
|
||||||
extra_build_metadata="$(echo "${buildinfo}" | grep -oP '(?<=Extra: ).*' | tr "'" '"')"
|
extra_build_metadata="$(koji -s "${KOJI_HUB_URL}" --noauth call --json getBuild "${buildid}" | jq -r '.extra')"
|
||||||
|
|
||||||
# sanity check the extra build metadata
|
# sanity check the extra build metadata
|
||||||
if [ -z "${extra_build_metadata}" ]; then
|
if [ -z "${extra_build_metadata}" ]; then
|
||||||
|
|
@ -129,53 +132,66 @@ function verify_buildinfo() {
|
||||||
|
|
||||||
# extract the image archives paths from the output and keep only the filenames
|
# extract the image archives paths from the output and keep only the filenames
|
||||||
local outputs_images
|
local outputs_images
|
||||||
outputs_images="$(echo "${buildinfo}" |
|
outputs_images="$(koji -s "${KOJI_HUB_URL}" --noauth call --json listArchives "${buildid}" | jq -r 'map(select(.btype == "image"))')"
|
||||||
sed -zE 's/.*Image archives:\n((\S+\n){1,})([\w\s]+:){0,}.*/\1/g' |
|
|
||||||
sed -E 's/.*\/(.*)/\1/g')"
|
|
||||||
|
|
||||||
# we build one image for cloud test case and two for non-cloud test case
|
# we build one image for cloud test case and two for non-cloud test case
|
||||||
|
local outputs_images_count
|
||||||
|
outputs_images_count="$(echo "${outputs_images}" | jq 'length')"
|
||||||
if [ "${target_cloud}" == "none" ]; then
|
if [ "${target_cloud}" == "none" ]; then
|
||||||
if [[ $(echo "${outputs_images}" | wc -l) -ne 2 ]]; then
|
if [ "${outputs_images_count}" -ne 2 ]; then
|
||||||
echo "Unexpected number of images in the buildinfo"
|
echo "Unexpected number of images in the buildinfo. Want 2, got ${outputs_images_count}."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ $(echo "${outputs_images}" | wc -l) -ne 1 ]]; then
|
if [ "${outputs_images_count}" -ne 1 ]; then
|
||||||
echo "Unexpected number of images in the buildinfo"
|
echo "Unexpected number of images in the buildinfo. Want 1, got ${outputs_images_count}."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local images_metadata
|
local build_extra_md_image
|
||||||
images_metadata="$(echo "${extra_build_metadata}" | jq -r '.typeinfo.image')"
|
build_extra_md_image="$(echo "${extra_build_metadata}" | jq -r '.typeinfo.image')"
|
||||||
|
|
||||||
for image in $outputs_images; do
|
for image_idx in $(seq 0 $((outputs_images_count - 1))); do
|
||||||
local image_metadata
|
local image
|
||||||
image_metadata="$(echo "${images_metadata}" | jq -r ".\"${image}\"")"
|
image="$(echo "${outputs_images}" | jq -r ".[${image_idx}]")"
|
||||||
if [ "${image_metadata}" == "null" ]; then
|
|
||||||
echo "Image metadata for '${image}' is missing"
|
local image_filename
|
||||||
|
image_filename="$(echo "${image}" | jq -r '.filename')"
|
||||||
|
|
||||||
|
local image_metadata_build
|
||||||
|
image_metadata_build="$(echo "${build_extra_md_image}" | jq -r ".\"${image_filename}\"")"
|
||||||
|
if [ "${image_metadata_build}" == "null" ]; then
|
||||||
|
echo "Image metadata for '${image_filename}' is missing"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local image_arch
|
local image_arch
|
||||||
image_arch="$(echo "${image_metadata}" | jq -r '.arch')"
|
image_arch="$(echo "${image_metadata_build}" | jq -r '.arch')"
|
||||||
if [ "${image_arch}" != "${ARCH}" ]; then
|
if [ "${image_arch}" != "${ARCH}" ]; then
|
||||||
echo "Unexpected arch for '${image}'. Expected '${ARCH}', but got '${image_arch}'"
|
echo "Unexpected arch for '${image_filename}'. Expected '${ARCH}', but got '${image_arch}'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local image_boot_mode
|
local image_boot_mode
|
||||||
image_boot_mode="$(echo "${image_metadata}" | jq -r '.boot_mode')"
|
image_boot_mode="$(echo "${image_metadata_build}" | jq -r '.boot_mode')"
|
||||||
# for now, check just that the boot mode is a valid value
|
# for now, check just that the boot mode is a valid value
|
||||||
case "${image_boot_mode}" in
|
case "${image_boot_mode}" in
|
||||||
"uefi"|"legacy"|"hybrid")
|
"uefi"|"legacy"|"hybrid")
|
||||||
;;
|
;;
|
||||||
"none"|*)
|
"none"|*)
|
||||||
# for now, we don't upload any images that have 'none' as boot mode, although it is a valid value
|
# for now, we don't upload any images that have 'none' as boot mode, although it is a valid value
|
||||||
echo "Unexpected boot mode for '${image}'. Expected 'uefi', 'legacy' or 'hybrid', but got '${image_boot_mode}'"
|
echo "Unexpected boot mode for '${image_filename}'. Expected 'uefi', 'legacy' or 'hybrid', but got '${image_boot_mode}'"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
local image_metadata_archive
|
||||||
|
image_metadata_archive="$(echo "${image}" | jq -r '.extra.image')"
|
||||||
|
if [ "${image_metadata_build}" != "${image_metadata_archive}" ]; then
|
||||||
|
echo "Image extra metadata for '${image_filename}' in the build metadata and in the archive metadata differ"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,10 +216,10 @@ sudo cp \
|
||||||
sudo update-ca-trust
|
sudo update-ca-trust
|
||||||
|
|
||||||
greenprint "Testing Koji"
|
greenprint "Testing Koji"
|
||||||
koji --server=http://localhost:8080/kojihub --user=osbuild --password=osbuildpass --authtype=password hello
|
koji --server="${KOJI_HUB_URL}" --user=osbuild --password=osbuildpass --authtype=password hello
|
||||||
|
|
||||||
greenprint "Creating Koji task"
|
greenprint "Creating Koji task"
|
||||||
koji --server=http://localhost:8080/kojihub --user kojiadmin --password kojipass --authtype=password make-task image
|
koji --server="${KOJI_HUB_URL}" --user kojiadmin --password kojipass --authtype=password make-task image
|
||||||
|
|
||||||
# Always build the latest RHEL - that suits the koji API usecase the most.
|
# Always build the latest RHEL - that suits the koji API usecase the most.
|
||||||
if [[ "$DISTRO_CODE" == rhel-8* ]]; then
|
if [[ "$DISTRO_CODE" == rhel-8* ]]; then
|
||||||
|
|
@ -270,14 +286,19 @@ if [[ "$TEST_TYPE" == "$TEST_TYPE_CLOUD_UPLOAD" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
greenprint "Show Koji task"
|
greenprint "Show Koji task"
|
||||||
koji --server=http://localhost:8080/kojihub taskinfo 1
|
koji --server="${KOJI_HUB_URL}" taskinfo 1
|
||||||
|
|
||||||
greenprint "Show Koji buildinfo"
|
greenprint "Show Koji buildinfo"
|
||||||
BUILDINFO_OUTPUT="$(koji --server=http://localhost:8080/kojihub buildinfo 1)"
|
koji --server="${KOJI_HUB_URL}" buildinfo 1
|
||||||
echo "${BUILDINFO_OUTPUT}"
|
|
||||||
|
|
||||||
greenprint "Verify the buildinfo output"
|
greenprint "Show Koji raw buildinfo"
|
||||||
verify_buildinfo "${BUILDINFO_OUTPUT}" "${CLOUD_PROVIDER}"
|
koji --server="${KOJI_HUB_URL}" --noauth call --json getBuild 1
|
||||||
|
|
||||||
|
greenprint "Show Koji build archives"
|
||||||
|
koji --server="${KOJI_HUB_URL}" --noauth call --json listArchives 1
|
||||||
|
|
||||||
|
greenprint "Verify the Koji build info and metadata"
|
||||||
|
verify_buildinfo 1 "${CLOUD_PROVIDER}"
|
||||||
|
|
||||||
greenprint "Run the integration test"
|
greenprint "Run the integration test"
|
||||||
sudo /usr/libexec/osbuild-composer-test/osbuild-koji-tests
|
sudo /usr/libexec/osbuild-composer-test/osbuild-koji-tests
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue