From 0d8bb78f073d999a2c65d323a819e85737bf3298 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 1 Jun 2021 22:51:10 +0000 Subject: [PATCH] tests: Fix kernel builder tests Some kernels are only build for some architectures. The test assumed that all kernels were build for all architectures. Now, get a list of architectures for which we have a given kernel image and then make sure the builder images pointed to by the label and the builder image tagged by convention exist and point to the same thing. Signed-off-by: Rolf Neugebauer --- test/cases/020_kernel/tags.sh | 53 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/test/cases/020_kernel/tags.sh b/test/cases/020_kernel/tags.sh index 1c04fbdfc..123f6ab52 100644 --- a/test/cases/020_kernel/tags.sh +++ b/test/cases/020_kernel/tags.sh @@ -14,15 +14,15 @@ set -e . "${RT_PROJECT_ROOT}/_lib/lib.sh" if [ -z "${KERNEL}" ]; then - echo "KERNEL env var must be set" - exit 1 + echo "KERNEL env var must be set" + exit 1 fi NAME=tags clean_up() { - docker rm ${ctrid} - /bin/rm -f ${BUILDERFILE} + docker rm ${ctrid} + /bin/rm -f ${BUILDERFILE} } trap clean_up EXIT @@ -39,28 +39,47 @@ ctrid=$(docker create $KERNEL /bin/sh) docker cp ${ctrid}:/kernel-builder ${BUILDERFILE} FILECONTENTS=$(cat ${BUILDERFILE}) -# get the manifests for the referenced tag and for the referenced builder. -# these are not guaranated to be identical, since the orders can change. So we need to account for that. -sumtag=$(docker manifest inspect ${BUILDER} | jq -c '.manifests | sort_by(.digest)' | sha256sum | awk '{print $1}') -sumlabel=$(docker manifest inspect ${BUILDERLABEL} | jq -c '.manifests | sort_by(.digest)' | sha256sum | awk '{print $1}') +# Get a list of architectures for which we have this kernel +KERNEL_ARCHES=$(docker manifest inspect ${KERNEL} | jq -r -c '.manifests[].platform.architecture') + +# Get builder manifest +BUILDER_MANIFEST=$(docker manifest inspect ${BUILDER} | jq -c '.manifests') + +# Get the manifest of the builder pointed to by the label +BUILDER_LABEL_MANIFEST=$(docker manifest inspect ${BUILDERLABEL} | jq -c '.manifests') + # these two files should be identical echo "builder label: ${BUILDERLABEL}" echo "builder file: ${FILECONTENTS}" echo "builder tag: ${BUILDER}" -echo "builder tag sha256: ${sumtag}" -echo "builder label sha256: ${sumlabel}" # check that the label and file contents match if [ "${BUILDERLABEL}" != "${FILECONTENTS}" ]; then - echo "label vs file contents mismatch" - exit 1 -fi -# check that the tag actually points to the manifest -if [ "${sumtag}" != "${sumlabel}" ]; then - echo "tag ${BUILDER} and label ${BUILDERLABEL} have mismatched contents" - exit 1 + echo "label vs file contents mismatch" + exit 1 fi +# Check that for each architecture we have the kernel for builder and the builder label points to the same thing +for ARCH in ${KERNEL_ARCHES}; do + BUILDER_ARCH_DIGEST=$(echo ${BUILDER_MANIFEST} | jq -r --arg ARCH "$ARCH" '.[] | select (.platform.architecture == $ARCH) | .digest') + BUILDER_LABEL_ARCH_DIGEST=$(echo ${BUILDER_LABEL_MANIFEST} | jq -r --arg ARCH "$ARCH" '.[] | select (.platform.architecture == $ARCH) | .digest') + + if [ -z "${BUILDER_ARCH_DIGEST}" ]; then + echo "No Builder for ${ARCH} in manifest ${BUILDER}" + exit 1 + fi + if [ -z "${BUILDER_LABEL_ARCH_DIGEST}" ]; then + echo "No Builder for ${ARCH} in manifest ${BUILDERLABEL}" + exit 1 + fi + + if [ "${BUILDER_ARCH_DIGEST}" != "${BUILDER_LABEL_ARCH_DIGEST}" ]; then + echo "Builder digests for kernel ${KERNEL} arch ${ARCH} do not match ${BUILDER_ARCH_DIGEST} != ${BUILDER_LABEL_ARCH_DIGEST}" + exit 1 + fi + + echo "Builder tags/labels for kernel ${KERNEL} arch ${ARCH} match: ${BUILDER_ARCH_DIGEST} == ${BUILDER_LABEL_ARCH_DIGEST}" +done exit 0