From c71ae8f4554f549c52e6c31a6f9867083129b3c2 Mon Sep 17 00:00:00 2001 From: Xiaofeng Wang Date: Fri, 22 Jul 2022 17:40:43 +0800 Subject: [PATCH] test: Update tests to support embeded container image feature Container image can only be embeded on commit Use fedora image instead of ubi8 and only run embeded image checking on RHEL 8.7, 9.1, CS8 and CS9. --- internal/container/client_test.go | 2 -- test/cases/ostree-ng.sh | 26 +++++++++++++++++++++-- test/cases/ostree.sh | 27 ++++++++++++++++++++++- test/data/ansible/check_ostree.yaml | 33 ++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/internal/container/client_test.go b/internal/container/client_test.go index c089120be..7133fad04 100644 --- a/internal/container/client_test.go +++ b/internal/container/client_test.go @@ -2,7 +2,6 @@ package container_test import ( "context" - "fmt" "io/ioutil" "os" "testing" @@ -95,7 +94,6 @@ func TestClientAuthFilePath(t *testing.T) { os.Unsetenv("XDG_RUNTIME_DIR") authFilePath := container.GetDefaultAuthFile() - fmt.Printf("auth file path: %s", authFilePath) assert.NotEmpty(t, authFilePath) _, err = ioutil.ReadFile(authFilePath) assert.True(t, err == nil || os.IsNotExist(err)) diff --git a/test/cases/ostree-ng.sh b/test/cases/ostree-ng.sh index bc0419944..7c894a4d5 100755 --- a/test/cases/ostree-ng.sh +++ b/test/cases/ostree-ng.sh @@ -113,6 +113,7 @@ case "${ID}-${VERSION_ID}" in OSTREE_REF="fedora/35/${ARCH}/iot" OSTREE_OSNAME=fedora OS_VARIANT="fedora35" + EMBEDED_CONTAINER="false" ;; "fedora-36") CONTAINER_TYPE=fedora-iot-container @@ -120,22 +121,27 @@ case "${ID}-${VERSION_ID}" in OSTREE_REF="fedora/36/${ARCH}/iot" OSTREE_OSNAME=fedora OS_VARIANT="fedora36" + EMBEDED_CONTAINER="false" ;; "rhel-8.7") OSTREE_REF="test/rhel/8/${ARCH}/edge" OS_VARIANT="rhel8-unknown" + EMBEDED_CONTAINER="true" ;; "rhel-9.1") OSTREE_REF="test/rhel/9/${ARCH}/edge" OS_VARIANT="rhel9-unknown" + EMBEDED_CONTAINER="true" ;; "centos-8") OSTREE_REF="test/centos/8/${ARCH}/edge" OS_VARIANT="centos8" + EMBEDED_CONTAINER="true" ;; "centos-9") OSTREE_REF="test/centos/9/${ARCH}/edge" OS_VARIANT="centos-stream9" + EMBEDED_CONTAINER="true" ;; *) echo "unsupported distro: ${ID}-${VERSION_ID}" @@ -389,6 +395,14 @@ home = "/home/admin/" groups = ["wheel"] EOF +# RHEL 8.7 and 9.1 later support embeded container in commit +if [[ "${EMBEDED_CONTAINER}" == "true" ]]; then + tee -a "$BLUEPRINT_FILE" > /dev/null << EOF +[[containers]] +source = "quay.io/fedora/fedora:latest" +EOF +fi + greenprint "📄 container blueprint" cat "$BLUEPRINT_FILE" @@ -560,7 +574,7 @@ EOF # Test IoT/Edge OS greenprint "📼 Run Edge tests on BIOS VM" -sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type="$OSTREE_OSNAME" -e ostree_commit="${INSTALL_HASH}" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 +sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type="$OSTREE_OSNAME" -e ostree_commit="${INSTALL_HASH}" -e embeded_container="true" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 check_result # Clean up BIOS VM @@ -645,6 +659,14 @@ name = "kernel-rt" EOF fi +# RHEL 8.7 and 9.1 later support embeded container in commit +if [[ "${EMBEDED_CONTAINER}" == "true" ]]; then + tee -a "$BLUEPRINT_FILE" > /dev/null << EOF +[[containers]] +source = "quay.io/fedora/fedora:latest" +EOF +fi + greenprint "📄 upgrade blueprint" cat "$BLUEPRINT_FILE" @@ -739,7 +761,7 @@ ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/ EOF # Test IoT/Edge OS -sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type="$OSTREE_OSNAME" -e ostree_commit="${UPGRADE_HASH}" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 +sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type="$OSTREE_OSNAME" -e ostree_commit="${UPGRADE_HASH}" -e embeded_container="true" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 check_result # Final success clean up diff --git a/test/cases/ostree.sh b/test/cases/ostree.sh index a3efb4af4..25e8d2ee6 100755 --- a/test/cases/ostree.sh +++ b/test/cases/ostree.sh @@ -20,6 +20,7 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="fedora35" USER_IN_COMMIT="false" BOOT_LOCATION="https://mirrors.rit.edu/fedora/fedora/linux/releases/35/Everything/x86_64/os/" + EMBEDED_CONTAINER="false" ;; "fedora-36") IMAGE_TYPE=fedora-iot-commit @@ -27,6 +28,7 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="fedora36" USER_IN_COMMIT="false" BOOT_LOCATION="https://mirrors.rit.edu/fedora/fedora/linux/releases/36/Everything/x86_64/os/" + EMBEDED_CONTAINER="false" ;; "rhel-8.4") IMAGE_TYPE=edge-commit @@ -34,6 +36,7 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="rhel8.4" USER_IN_COMMIT="true" BOOT_LOCATION="http://download.devel.redhat.com/released/rhel-8/RHEL-8/8.4.0/BaseOS/x86_64/os/" + EMBEDED_CONTAINER="false" ;; "rhel-8.6") IMAGE_TYPE=edge-commit @@ -41,12 +44,14 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="rhel8-unknown" USER_IN_COMMIT="true" BOOT_LOCATION="http://download.devel.redhat.com/released/rhel-8/RHEL-8/8.6.0/BaseOS/x86_64/os/" + EMBEDED_CONTAINER="false" ;; "rhel-8.7") IMAGE_TYPE=edge-commit OSTREE_REF="rhel/8/${ARCH}/edge" OS_VARIANT="rhel8-unknown" USER_IN_COMMIT="true" + EMBEDED_CONTAINER="true" # Use a stable installer image unless it's the nightly pipeline BOOT_LOCATION="http://download.devel.redhat.com/released/rhel-8/RHEL-8/8.6.0/BaseOS/x86_64/os/" @@ -60,12 +65,14 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="rhel9.0" USER_IN_COMMIT="true" BOOT_LOCATION="http://download.devel.redhat.com/released/rhel-9/RHEL-9/9.0.0/BaseOS/x86_64/os/" + EMBEDED_CONTAINER="false" ;; "rhel-9.1") IMAGE_TYPE=edge-commit OSTREE_REF="rhel/9/${ARCH}/edge" OS_VARIANT="rhel9-unknown" USER_IN_COMMIT="true" + EMBEDED_CONTAINER="true" # Use a stable installer image unless it's the nightly pipeline BOOT_LOCATION="http://download.devel.redhat.com/released/rhel-9/RHEL-9/9.0.0/BaseOS/x86_64/os/" @@ -79,6 +86,7 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="centos8" USER_IN_COMMIT="true" BOOT_LOCATION="http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/" + EMBEDED_CONTAINER="true" ;; "centos-9") IMAGE_TYPE=edge-commit @@ -86,6 +94,7 @@ case "${ID}-${VERSION_ID}" in OS_VARIANT="centos-stream9" USER_IN_COMMIT="true" BOOT_LOCATION="https://odcs.stream.centos.org/production/latest-CentOS-Stream/compose/BaseOS/x86_64/os/" + EMBEDED_CONTAINER="true" ;; *) echo "unsupported distro: ${ID}-${VERSION_ID}" @@ -335,6 +344,14 @@ groups = ["wheel"] EOF fi +# RHEL 8.7 and 9.1 later support embeded container in commit +if [[ "${EMBEDED_CONTAINER}" == "true" ]]; then + tee -a "$BLUEPRINT_FILE" > /dev/null << EOF +[[containers]] +source = "quay.io/fedora/fedora:latest" +EOF +fi + # Build installation image. build_image "$BLUEPRINT_FILE" ostree @@ -504,6 +521,14 @@ groups = ["wheel"] EOF fi +# RHEL 8.7 and 9.1 later support embeded container in commit +if [[ "${EMBEDED_CONTAINER}" == "true" ]]; then + tee -a "$BLUEPRINT_FILE" > /dev/null << EOF +[[containers]] +source = "quay.io/fedora/fedora:latest" +EOF +fi + # Build upgrade image. build_image "$BLUEPRINT_FILE" upgrade @@ -570,7 +595,7 @@ ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/ EOF # Test IoT/Edge OS -sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type=${IMAGE_TYPE} -e ostree_commit="${UPGRADE_HASH}" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 +sudo ansible-playbook -v -i "${TEMPDIR}"/inventory -e image_type=${IMAGE_TYPE} -e ostree_commit="${UPGRADE_HASH}" -e embeded_container="true" /usr/share/tests/osbuild-composer/ansible/check_ostree.yaml || RESULTS=0 check_result # Final success clean up diff --git a/test/data/ansible/check_ostree.yaml b/test/data/ansible/check_ostree.yaml index e0327bb04..80538e445 100644 --- a/test/data/ansible/check_ostree.yaml +++ b/test/data/ansible/check_ostree.yaml @@ -5,6 +5,7 @@ workspace: "{{ lookup('env', 'WORKSPACE') }}" skip_rollback_test: "false" fdo_credential: "false" + embeded_container: "false" total_counter: "0" failed_counter: "0" @@ -150,7 +151,7 @@ - name: check if it is simplified-installer or raw-image command: findmnt -r -o SOURCE -n /sysroot register: result_encrypted - + - set_fact: device_name: "{{ result_encrypted.stdout }}" when: "'/dev/mapper/luks-' in result_encrypted.stdout" @@ -342,6 +343,36 @@ shell: dmesg --notime | grep -i "error\|fail" || true register: result_dmesg_error + - name: check embeded container image with podman + command: podman images + become: yes + register: result_podman_images + when: + - embeded_container == "true" + - (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('9.0', '>')) or + (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('8.6', '>') and ansible_facts ['distribution_version'] is version('9.0', '!=')) or + (ansible_facts['distribution'] == 'CentOS') + + - name: embded container should be listed by podman images + block: + - assert: + that: + - "'quay.io/fedora/fedora' in result_podman_images.stdout" + fail_msg: "fedora image is not built in image" + success_msg: "fedora image is built in image" + always: + - set_fact: + total_counter: "{{ total_counter | int + 1 }}" + rescue: + - name: failed count + 1 + set_fact: + failed_counter: "{{ failed_counter | int + 1 }}" + when: + - embeded_container == "true" + - (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('9.0', '>')) or + (ansible_facts['distribution'] == 'RedHat' and ansible_facts ['distribution_version'] is version('8.6', '>') and ansible_facts ['distribution_version'] is version('9.0', '!=')) or + (ansible_facts['distribution'] == 'CentOS') + # case: check running container with podman - name: run ubi8 image command: podman run registry.access.redhat.com/ubi8/ubi-minimal:latest cat /etc/redhat-release