diff --git a/.packit.yaml b/.packit.yaml index 4fe8e5bc2b..d31c23f319 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -123,10 +123,20 @@ _: tf_extra_params: environments: - tmt: - context: + context: &provision-context how: provision <<: *tmt-cloud-resources + # Image mode + - &image-mode + tf_extra_params: + environments: + - tmt: + context: + <<: *provision-context + image_mode: "yes" + <<: *tmt-cloud-resources + jobs: # Build released bits to stable - <<: *copr-under-teemtee @@ -176,6 +186,11 @@ jobs: identifier: provision-virtual tmt_plan: /plans/provision/virtual + - <<: *provision + <<: *image-mode + identifier: provision-virtual-image-mode + tmt_plan: /plans/provision/virtual + # Test internal plugins - <<: *test-base <<: *internal diff --git a/plans/provision/virtual.fmf b/plans/provision/virtual.fmf index ec835719ee..a792c4ecc9 100644 --- a/plans/provision/virtual.fmf +++ b/plans/provision/virtual.fmf @@ -60,9 +60,18 @@ adjust+: because: Disable IPv6 in CI to avoid IPv6 connections that are disabled in CI when: trigger == commit + - discover+: + filter: 'tag:provision-virtual & tag:image-mode' + environment+: + IMAGE_MODE: "yes" + when: image_mode == yes + /provision: discover+: test: "^/tests/provision" + adjust+: + - enabled: false + when: image_mode != yes /prepare: discover+: @@ -77,11 +86,20 @@ adjust+: discover+: test: "^/tests/execute" exclude: "^/tests/execute/upgrade" + adjust+: + - enabled: false + when: image_mode != yes /upgrade: discover+: test: "^/tests/execute/upgrade" + adjust+: + - enabled: false + when: image_mode != yes /the-rest: discover+: test: "^/tests/(?!provision|prepare|execute)" + adjust+: + - enabled: false + when: image_mode != yes diff --git a/tests/images.sh b/tests/images.sh index 6fb561fa17..5a6bd01bdc 100644 --- a/tests/images.sh +++ b/tests/images.sh @@ -51,6 +51,19 @@ fedora-coreos}" # combinations, just make sure the basic functionality works. TEST_VIRTUAL_IMAGES_SECONDARY="${TEST_VIRTUAL_IMAGES_SECONDARY:-fedora-42}" +# Base URL for image mode qcow2s +IMAGE_MODE_QCOW2_BASE_URL="https://artifacts.dev.testing-farm.io/images" + +# Image mode QCOW2 images, with mapping to compatible container image used for artifacts downloading +declare -A IMAGE_MODE_QCOW2_CONTAINER_MAP +IMAGE_MODE_QCOW2_CONTAINER_MAP=( + ["$IMAGE_MODE_QCOW2_BASE_URL/CentOS-Stream-10-image-mode-x86_64.qcow2"]="centos:stream10" + ["$IMAGE_MODE_QCOW2_BASE_URL/Fedora-44-image-mode-x86_64.qcow2"]="fedora:44" +) + +# Set of image mode virtual images to test on. +TEST_IMAGE_MODE_IMAGES="${TEST_IMAGE_MODE_IMAGES:-$(printf "%s\n" "${!IMAGE_MODE_QCOW2_CONTAINER_MAP[@]}")}" + # A couple of "is image this?" helpers, to simplify conditions. function is_fedora_rawhide () { [[ "$1" =~ ^.*fedora/rawhide[:/].* ]] && return 0 @@ -90,6 +103,7 @@ function is_centos_stream_9 () { function is_centos_stream_10 () { [[ "$1" =~ ^.*centos/stream10[:/].* ]] && return 0 [[ "$1" = "centos-stream-10" ]] && return 0 + [[ "$1" =~ CentOS-Stream-10 ]] && return 0 return 1 } @@ -130,11 +144,11 @@ function is_fedora_coreos () { } function is_fedora () { - [[ "$1" =~ ^.*fedora.* ]] && return 0 || return 1 + [[ "${1,,}" =~ ^.*fedora.* ]] && return 0 || return 1 } function is_centos () { - [[ "$1" =~ ^.*centos.* ]] && return 0 || return 1 + [[ "${1,,}" =~ ^.*centos.* ]] && return 0 || return 1 } function is_rhel () { @@ -153,6 +167,10 @@ function is_ubi_8 () { [[ "$1" =~ ^.*ubi/8.* ]] && return 0 || return 1 } +function is_image_mode () { + [[ "$1" =~ image-mode ]] +} + function test_phase_prefix () { if [ "$PROVISION_HOW" = "local" ]; then echo "[$PROVISION_HOW]" diff --git a/tests/prepare/bootc/data/.fmf/version b/tests/prepare/bootc/data/.fmf/version deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/prepare/bootc/data/.fmf/version +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/prepare/bootc/data/plans.fmf b/tests/prepare/bootc/data/plans.fmf deleted file mode 100644 index 309f3bc00e..0000000000 --- a/tests/prepare/bootc/data/plans.fmf +++ /dev/null @@ -1,26 +0,0 @@ -discover: - how: fmf - -provision: - how: virtual - -execute: - how: tmt - -/centos-stream-10: - provision+: - image: https://artifacts.dev.testing-farm.io/images/CentOS-Stream-10-image-mode-x86_64.qcow2 - - /prepare-shell: - summary: "Test prepare/shell on bootc guest - install tree package" - prepare: - how: shell - script: - - dnf -y install tree - - /prepare-install: - summary: "Test prepare/install on bootc guest - install tree package from local rpm" - prepare: - how: install - package: - - $TREE_RPM diff --git a/tests/prepare/bootc/data/test.fmf b/tests/prepare/bootc/data/test.fmf deleted file mode 100644 index 638837c843..0000000000 --- a/tests/prepare/bootc/data/test.fmf +++ /dev/null @@ -1,9 +0,0 @@ -summary: Check that tree package was installed via prepare/shell -description: | - Verify that the tree command is available after prepare/shell - executed 'dnf -y install tree' via the bootc Containerfile build. -test: | - # Verify tree is installed and working - tree --version - # Also verify the booted image shows we're running a modified image - bootc status --booted --format humanreadable diff --git a/tests/prepare/bootc/main.fmf b/tests/prepare/bootc/main.fmf deleted file mode 100644 index 92dd724ee9..0000000000 --- a/tests/prepare/bootc/main.fmf +++ /dev/null @@ -1,16 +0,0 @@ -summary: Test prepare/shell step on bootc guests -description: | - Verify that prepare/shell commands are collected and executed - via Containerfile build on bootc guests. Commands with - immediately=False are collected and applied via image rebuild - and reboot. -link: - - verifies: https://github.com/teemtee/tmt/issues/4495 -tag+: - - provision-only - - provision-virtual -require: - - centpkg - - koji - - tmt+provision-virtual -duration: 2h diff --git a/tests/prepare/bootc/test.sh b/tests/prepare/bootc/test.sh deleted file mode 100755 index 8ee3dc6c3e..0000000000 --- a/tests/prepare/bootc/test.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -. /usr/share/beakerlib/beakerlib.sh || exit 1 -. ../artifact/lib/common.sh || exit 1 - -rlJournalStart - rlPhaseStartSetup - rlRun "pushd data" - rlRun "run=\$(mktemp -d --tmpdir=/var/tmp/tmt)" 0 "Create run directory" - rlPhaseEnd - - # Test prepare/shell on bootc guest - should use Containerfile collection - rlPhaseStartTest "Prepare/shell on bootc guest - install tree package" - rlRun -s "tmt -dddvvv run --scratch -i $run plan --name /plans/centos-stream-10/prepare-shell" - - # Verify the prepare/shell command was collected .. - rlAssertGrep "Collected command for Containerfile" $rlRun_LOG - - # Verify the container image was built - rlAssertGrep "building container image from collected commands" $rlRun_LOG - - # Verify bootc switch was called - rlAssertGrep "switching to new image" $rlRun_LOG - - # Verify reboot happened - rlAssertGrep "rebooting to apply new image" $rlRun_LOG - - # Verify tree --version ran successfully in the test - rlAssertGrep "tree v" $rlRun_LOG - rlPhaseEnd - - # Test prepare/install on bootc guest - should install rpm via Containerfile - rlPhaseStartTest "Prepare/install on bootc guest - install tree package from rpm" - # Download tree RPM - get_koji_nvr "tree-pkg" "c10s-candidate" "stream" - rlRun "koji --profile stream download-build --arch=x86_64 $KOJI_NVR" 0 "Download tree RPM" - rlRun "TREE_RPM=$(ls tree-*.rpm)" - - # Run tmt - rlRun -s "tmt -dddvvv run -e TREE_RPM=$TREE_RPM --scratch -i $run plan --name /plans/centos-stream-10/prepare-install" - - # Verify the container image was built - rlAssertGrep "Trying to pull quay.io/testing-farm/centos-bootc:stream10" $rlRun_LOG - rlAssertGrep "package: building container image with dependencies" $rlRun_LOG - - # Verify bootc switch was called - rlAssertGrep "switching to new image" $rlRun_LOG - - # Verify reboot happened - rlAssertGrep "rebooting to apply new image" $rlRun_LOG - - # Verify tree --version ran successfully in the test - rlAssertGrep "tree v" $rlRun_LOG - rlPhaseEnd - - rlPhaseStartCleanup - rlRun "rm -rf $run" 0 "Remove run directory" - rlRun "rm -f tree-*.rpm" 0 "Remove tree rpm" - rlRun "popd" - rlPhaseEnd -rlJournalEnd diff --git a/tests/prepare/install/data/reboot-persistence.fmf b/tests/prepare/install/data/reboot-persistence.fmf new file mode 100644 index 0000000000..9feeda338e --- /dev/null +++ b/tests/prepare/install/data/reboot-persistence.fmf @@ -0,0 +1,20 @@ +summary: Verify installed packages persist after reboot +description: | + Install packages and verify they survive a reboot. + This is critical for image mode where changes are applied + via Containerfile rebuild and bootc switch. + +prepare: + - how: install + package: + - tree + - diffutils + +execute: + how: tmt + script: | + tree --version + diff --version + if [ "$TMT_REBOOT_COUNT" == "0" ]; then + tmt-reboot + fi diff --git a/tests/prepare/install/main.fmf b/tests/prepare/install/main.fmf index 2161f49b82..2f579d5d37 100644 --- a/tests/prepare/install/main.fmf +++ b/tests/prepare/install/main.fmf @@ -10,6 +10,7 @@ tag+: - provision-only - provision-container - provision-virtual + - image-mode # TODO: what test cases are safe enough to be executed against the localhost? # - provision-local diff --git a/tests/prepare/install/test.sh b/tests/prepare/install/test.sh index 26da198678..680f916615 100755 --- a/tests/prepare/install/test.sh +++ b/tests/prepare/install/test.sh @@ -3,11 +3,17 @@ . ../../images.sh || exit 1 function fetch_downloaded_packages () { + image="$1" in_subdirectory="$2" if [ ! -e $package_cache/tree.rpm ]; then + # Transform image mode qcow2 URL to a distro compatible container image for artifact download. + # We want artifacts to come from the same distribution, but using standard fedora container + # images is enough, they are smaller and rpm compatible with image mode based container images. + [ "$IMAGE_MODE" = "yes" ] && image=${IMAGE_MODE_QCOW2_CONTAINER_MAP["$image"]} + # For some reason, this command will get stuck in rlRun... - container_id="$(podman run -d $1 sleep 3600)" + container_id="$(podman run -d $image sleep 3600)" rlRun "podman exec $container_id bash -c \"set -x; \ dnf install -y 'dnf-command(download)' \ @@ -33,8 +39,13 @@ function fetch_downloaded_packages () { rlJournalStart rlPhaseStartSetup rlRun "PROVISION_HOW=${PROVISION_HOW:-container}" + rlRun "IMAGE_MODE=${IMAGE_MODE:-no}" + + if [ "$IMAGE_MODE" = "yes" ]; then + rlRun "IMAGES='$TEST_IMAGE_MODE_IMAGES'" + rlRun "SECONDARY_IMAGES=''" - if [ "$PROVISION_HOW" = "container" ]; then + elif [ "$PROVISION_HOW" = "container" ]; then rlRun "IMAGES='$TEST_CONTAINER_IMAGES'" rlRun "SECONDARY_IMAGES='$TEST_CONTAINER_IMAGES_SECONDARY'" @@ -123,6 +134,10 @@ rlJournalStart rlRun "distro=rhel-8" rlRun "package_manager=dnf" + elif is_fedora "$image"; then + rlRun "distro=fedora" + rlRun "package_manager=dnf5" + elif is_alpine "$image"; then rlRun "distro=alpine" rlRun "package_manager=apk" @@ -131,6 +146,10 @@ rlJournalStart rlFail "Cannot infer distro for image $image" fi + if is_image_mode "$image"; then + rlRun "package_manager=bootc" + fi + tmt_run="tmt -vvv -c distro=$distro run --id $run --scratch" tmt_steps="cleanup discover provision --how $PROVISION_HOW --image $image prepare" tmt="$tmt_run $tmt_steps" @@ -144,6 +163,12 @@ rlJournalStart rlAssertGrep "package manager: $package_manager$" $rlRun_LOG + if is_image_mode "$image"; then + rlAssertGrep "package: building container image with dependencies" $rlRun_LOG + rlAssertGrep "switching to new image" $rlRun_LOG + rlAssertGrep "rebooting to apply new image" $rlRun_LOG + fi + if is_ubuntu "$image" || is_debian "$image"; then # Runs 1 extra phase, to populate local caches. rlAssertGrep "summary: 3 preparations applied" $rlRun_LOG @@ -152,6 +177,23 @@ rlJournalStart fi rlPhaseEnd + # On image mode, verify packages persist after reboot + if is_image_mode "$image"; then + rlPhaseStartTest "$phase_prefix Reboot persistence" + rlRun -s "$tmt_run --all provision --how $PROVISION_HOW --image $image plan --name /reboot-persistence" + + rlAssertGrep "package: building container image with dependencies" $rlRun_LOG + rlAssertGrep "switching to new image" $rlRun_LOG + rlAssertGrep "rebooting to apply new image" $rlRun_LOG + + # should see the tree and diffutils version printed twice (before and after the test reboot) + rlAssertEquals "Verify tree available after reboot" $(grep "stdout: tree v" $rlRun_LOG | wc -l) 2 + rlAssertEquals "Verify diffutils available after reboot" $(grep "stdout: diff (GNU diffutils)" $rlRun_LOG | wc -l) 2 + + rlAssertGrep "total: 1 test passed" $rlRun_LOG + rlPhaseEnd + fi + # Here the basic functionality check ends for the secondary distros. if [[ "$SECONDARY_IMAGES" =~ "$image" ]]; then continue @@ -174,7 +216,10 @@ rlJournalStart fi rlPhaseEnd - if [ "$PROVISION_HOW" = "container" ] && rlIsFedora 43 && is_fedora_43 "$image"; then + # Limit these test cases to: + # * container provisioner - to save resources, they do not provide additional value with the virtual provisioner + # * image mode - the code handling is different from ^ and we need to make sure these cases work well + if ([ "$PROVISION_HOW" = "container" ] && rlIsFedora 43 && is_fedora_43 "$image") || is_image_mode "$image"; then rlPhaseStartTest "$phase_prefix Install downloaded packages from current directory (plan)" fetch_downloaded_packages "$image" @@ -244,6 +289,13 @@ rlJournalStart if is_centos_7 "$image"; then rlAssertGrep "stdout: no package provides tree-but-spelled-wrong" $rlRun_LOG + elif is_image_mode "$image"; then + if is_fedora "$image"; then + rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG + else + rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG + fi + elif is_ostree "$image"; then if [ "$PROVISION_HOW" = "virtual" ]; then rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG @@ -273,8 +325,8 @@ rlJournalStart rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG fi - rlAssertGrep "Other failed packages:" $rlRun_LOG - rlAssertGrep "tree-but-spelled-wrong" $rlRun_LOG + rlAssertGrep "Other failed packages:" $rlRun_LOG + rlAssertGrep "tree-but-spelled-wrong" $rlRun_LOG rlPhaseEnd rlPhaseStartTest "$phase_prefix Install existing and invalid packages (test)" @@ -285,6 +337,13 @@ rlJournalStart if is_centos_7 "$image"; then rlAssertGrep "stdout: no package provides tree-but-spelled-wrong" $rlRun_LOG + elif is_image_mode "$image"; then + if is_fedora "$image"; then + rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG + else + rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG + fi + elif is_ostree "$image"; then if [ "$PROVISION_HOW" = "virtual" ]; then rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG @@ -314,7 +373,7 @@ rlJournalStart rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG fi - rlAssertGrep "Required packages failed to install, aborting:" $rlRun_LOG + rlAssertGrep "Required packages failed to install, aborting:" $rlRun_LOG rlAssertGrep "tree-but-spelled-wrong: required by: /test-with-invalid-package" $rlRun_LOG rlPhaseEnd @@ -326,6 +385,13 @@ rlJournalStart if is_centos_7 "$image"; then rlAssertGrep "stdout: no package provides tree-but-spelled-wrong" $rlRun_LOG + elif is_image_mode "$image"; then + if is_fedora "$image"; then + rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG + else + rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG + fi + elif is_ostree "$image"; then if [ "$PROVISION_HOW" = "virtual" ]; then rlAssertGrep "stderr: No match for argument: tree-but-spelled-wrong" $rlRun_LOG @@ -354,8 +420,8 @@ rlJournalStart else rlAssertGrep "stderr: Error: Unable to find a match: tree-but-spelled-wrong" $rlRun_LOG fi - rlAssertGrep "Other failed packages:" $rlRun_LOG - rlAssertGrep "tree-but-spelled-wrong" $rlRun_LOG + rlAssertGrep "Other failed packages:" $rlRun_LOG + rlAssertGrep "tree-but-spelled-wrong" $rlRun_LOG rlPhaseEnd rlPhaseStartTest "$phase_prefix Empty prepare install with exclude" @@ -364,7 +430,8 @@ rlJournalStart # TODO: at least copr is RH-specific, but package name escaping and debuginfo should be # possible to extend to other distros. - if (is_fedora "$image" && ! is_fedora_coreos "$image") || is_centos "$image" || is_ubi "$image"; then + # TODO: image mode copr support depends on #4748 + if ! is_image_mode "$image" && ((is_fedora "$image" && ! is_fedora_coreos "$image") || is_centos "$image" || is_ubi "$image"); then if ! is_centos_7 "$image" && ! is_ubi_8 "$image"; then rlPhaseStartTest "$phase_prefix Just enable copr" rlRun "$tmt execute plan --name copr" diff --git a/tests/prepare/recommend/main.fmf b/tests/prepare/recommend/main.fmf index 69e1a9658e..926077ce1b 100644 --- a/tests/prepare/recommend/main.fmf +++ b/tests/prepare/recommend/main.fmf @@ -8,3 +8,4 @@ tag+: - provision-container - provision-local - provision-virtual + - image-mode diff --git a/tests/prepare/recommend/test.sh b/tests/prepare/recommend/test.sh index a0d8151705..7974ee5b2d 100755 --- a/tests/prepare/recommend/test.sh +++ b/tests/prepare/recommend/test.sh @@ -5,25 +5,31 @@ rlJournalStart rlPhaseStartSetup rlRun "PROVISION_HOW=${PROVISION_HOW:-container}" - rlRun "pushd data" + rlRun "IMAGE_MODE=${IMAGE_MODE:-no}" + + if [ "$PROVISION_HOW" = "container" ]; then + build_container_image "ubi/8/upstream\:latest" + build_container_image "centos/7/upstream\:latest" + build_container_image "fedora/latest/upstream\:latest" + fi - build_container_image "ubi/8/upstream\:latest" - build_container_image "centos/7/upstream\:latest" - build_container_image "fedora/latest/upstream\:latest" + rlRun "pushd data" rlPhaseEnd tmt="tmt run -vv --all --remove provision --how $PROVISION_HOW" basic="plan --name 'mixed|weird'" debuginfo="plan --name debuginfo" - # Verify against the default provision image - rlPhaseStartTest "Test the default image ($PROVISION_HOW)" - rlRun -s "$tmt $basic" - rlAssertGrep "Recommended packages failed to install, continuing regardless:" $rlRun_LOG - rlAssertGrep "forest: recommended by: /test/mixed" $rlRun_LOG - rlAssertGrep "weird-package: recommended by: /test/weird" $rlRun_LOG - rlAssertNotGrep "dconf: recommended by: /test/mixed" $rlRun_LOG - rlPhaseEnd + # Verify against the default provision image (skip for image mode, no default image) + if [[ "$IMAGE_MODE" != "yes" ]]; then + rlPhaseStartTest "Test the default image ($PROVISION_HOW)" + rlRun -s "$tmt $basic" + rlAssertGrep "Recommended packages failed to install, continuing regardless:" $rlRun_LOG + rlAssertGrep "forest: recommended by: /test/mixed" $rlRun_LOG + rlAssertGrep "weird-package: recommended by: /test/weird" $rlRun_LOG + rlAssertNotGrep "dconf: recommended by: /test/mixed" $rlRun_LOG + rlPhaseEnd + fi # Check CentOS images for container provision if [[ "$PROVISION_HOW" == "container" ]]; then @@ -50,8 +56,21 @@ rlJournalStart done fi - # Add one extra CoreOS run for virtual provision - if [[ "$PROVISION_HOW" == "virtual" ]]; then + # Run against image mode images + if [[ "$IMAGE_MODE" == "yes" ]]; then + while IFS= read -r image; do + rlPhaseStartTest "Test $image (image-mode)" + rlRun -s "$tmt --image $image $basic" + rlAssertGrep "Recommended packages failed to install, continuing regardless:" $rlRun_LOG + rlAssertGrep "forest: recommended by: /test/mixed" $rlRun_LOG + rlAssertGrep "weird-package: recommended by: /test/weird" $rlRun_LOG + rlAssertNotGrep "dconf: recommended by: /test/mixed" $rlRun_LOG + rlPhaseEnd + done <<< "$TEST_IMAGE_MODE_IMAGES" + fi + + # Add one extra CoreOS run for virtual provision (not image mode) + if [[ "$PROVISION_HOW" == "virtual" ]] && [[ "$IMAGE_MODE" != "yes" ]]; then rlPhaseStartTest "Test fedora-coreos ($PROVISION_HOW)" rlRun -s "$tmt --image fedora-coreos $basic" rlAssertGrep "Recommended packages failed to install, continuing regardless:" $rlRun_LOG diff --git a/tests/prepare/shell/data/multiple.fmf b/tests/prepare/shell/data/multiple.fmf index 6dbc49401f..33c3bad657 100644 --- a/tests/prepare/shell/data/multiple.fmf +++ b/tests/prepare/shell/data/multiple.fmf @@ -2,4 +2,4 @@ provision: how: container execute: how: tmt - script: test -e /tmp/first && test -e /tmp/second + script: test -e $FIRST && test -e $SECOND diff --git a/tests/prepare/shell/main.fmf b/tests/prepare/shell/main.fmf index 0ebcc88f17..1d7a171fde 100644 --- a/tests/prepare/shell/main.fmf +++ b/tests/prepare/shell/main.fmf @@ -5,6 +5,7 @@ tag+: - provision-container - provision-local - provision-virtual + - image-mode # TODO Disable for now under the mock provision plan because of # https://bugzilla.redhat.com/show_bug.cgi?id=2415701 diff --git a/tests/prepare/shell/test.sh b/tests/prepare/shell/test.sh index a10e5ea6b8..9e38ee152f 100755 --- a/tests/prepare/shell/test.sh +++ b/tests/prepare/shell/test.sh @@ -1,31 +1,59 @@ #!/bin/bash . /usr/share/beakerlib/beakerlib.sh || exit 1 +. ../../images.sh || exit 1 rlJournalStart rlPhaseStartSetup rlRun "PROVISION_HOW=${PROVISION_HOW:-local}" + rlRun "IMAGE_MODE=${IMAGE_MODE:-no}" + rlRun "FIRST=/tmp/first SECOND=/tmp/second" + if [ "$IMAGE_MODE" = "yes" ]; then + rlRun "IMAGES='$TEST_IMAGE_MODE_IMAGES'" + # In image mode use paths which survive a reboot + rlRun "FIRST=/first SECOND=/second" + fi rlRun "pushd data" rlPhaseEnd - rlPhaseStartTest "Custom Script" - rlRun "tmt run -arv provision --how=$PROVISION_HOW plan -n custom" 0 "Prepare using a custom script" - rlPhaseEnd + while IFS= read -r image; do + if [ -n "$image" ]; then + image_opt="--image=$image" + fi - rlPhaseStartTest "Commandline Script" - rlRun "tmt run -arv provision --how=$PROVISION_HOW plan -n custom \ - prepare -h shell -s './prepare.sh'" 0 "Prepare using a custom script from cmdline" - rlPhaseEnd + assert_image_mode() { + is_image_mode "$image" || return + rlAssertGrep "building container image from collected commands" $rlRun_LOG + rlAssertGrep "switching to new image" $rlRun_LOG + rlAssertGrep "rebooting to apply new image" $rlRun_LOG + } - rlPhaseStartTest "Multiple Commandline Scripts" - rlRun "tmt run -arv provision --how=$PROVISION_HOW plans -n multiple \ - prepare -h shell -s 'touch /tmp/first' -s 'touch /tmp/second'" - rlPhaseEnd + rlPhaseStartTest "Custom Script" + rlRun -s "tmt run -arv provision --how=$PROVISION_HOW $image_opt plan -n custom" 0 "Prepare using a custom script" + assert_image_mode + rlPhaseEnd - rlPhaseStartTest "Remote Script" - rlRun -s "tmt -vvv run provision --how=$PROVISION_HOW prepare finish cleanup plan -n url" 0 "Prepare using a remote script" - rlAssertGrep "Hello world" "$rlRun_LOG" #check for the prepare script - rlAssertGrep "third" "$rlRun_LOG" # check for the finish script - rlPhaseEnd + rlPhaseStartTest "Commandline Script" + rlRun "tmt run -arv provision --how=$PROVISION_HOW $image_opt plan -n custom \ + prepare -h shell -s './prepare.sh'" 0 "Prepare using a custom script from cmdline" + assert_image_mode + rlPhaseEnd + + rlPhaseStartTest "Multiple Commandline Scripts" + rlRun -s "tmt run -arv -e FIRST=$FIRST -e SECOND=$SECOND provision --how=$PROVISION_HOW $image_opt plans -n multiple \ + prepare -h shell -s 'touch $FIRST' -s 'touch $SECOND'" + assert_image_mode + rlPhaseEnd + + # TODO: #4785 Preparing from a remote script is broken in Image Mode + if [ "$IMAGE_MODE" != "yes" ]; then + rlPhaseStartTest "Remote Script" + rlRun -s "tmt -vvv run provision --how=$PROVISION_HOW $image_opt prepare finish cleanup plan -n url" 0 "Prepare using a remote script" + rlAssertGrep "Hello world" "$rlRun_LOG" #check for the prepare script + rlAssertGrep "third" "$rlRun_LOG" # check for the finish script + assert_image_mode + rlPhaseEnd + fi + done <<< "$IMAGES" rlPhaseStartCleanup rlRun "popd"