Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ jobs:
needs: build-c9s
runs-on: ubuntu-24.04
steps:
- name: Reclaim disk space
run: |
set -euxo pipefail
rm -rf "/run/host/usr/local/lib/android"
# https://github.com/containers/podman/discussions/17362
- name: Get a newer podman for heredoc support (from debian testing)
run: |
Expand Down
76 changes: 72 additions & 4 deletions tests/kolainst/destructive/container-update-check
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ EOF
systemctl mask --now zincati
ostree container encapsulate --repo=/ostree/repo ${checksum} "${image}" --label ostree.bootable=TRUE

echo "Preparing an update"
skopeo copy $image containers-storage:localhost/fcos
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
FROM localhost/fcos
RUN rpm-ostree install man
LABEL org.opencontainers.image.version 2
Expand All @@ -106,13 +107,27 @@ EOF
rm -vf /etc/resolv.conf
fi

echo "Test that updates are properly found"
rpm-ostree upgrade --check > out.txt
assert_file_has_content_literal out.txt 'AvailableUpdate:'
assert_file_has_content_literal out.txt 'Total layers:'
assert_file_has_content_literal out.txt 'Size:'
assert_file_has_content_literal out.txt 'Removed layers:'
assert_file_has_content_literal out.txt 'Added layers:'

echo "Test that updates are properly cached"
rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
assert_file_has_content_literal out.txt '"removed-size":'
assert_file_has_content_literal out.txt '"total-size":'
assert_file_has_content_literal out.txt '"total":'
assert_file_has_content_literal out.txt '"added-size":'
assert_file_has_content_literal out.txt '"version": "2"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

echo "Test that staged updates are properly reported"
rpm-ostree upgrade
rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
Expand All @@ -123,4 +138,57 @@ EOF
assert_file_has_content_literal out.txt '"version": "2"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

echo "Prepare a second update"
rm "${image_dir}" -rf
td=$(mktemp -d)
cd ${td}
cat > Containerfile << EOF
FROM localhost/fcos
RUN touch /usr/foo
LABEL org.opencontainers.image.version 3
EOF

touched_resolv_conf=0
if test '!' -f /etc/resolv.conf; then
podmanv=$(podman --version)
case "${podmanv#podman version }" in
3.*) touched_resolv_conf=1; touch /etc/resolv.conf;;
esac
fi
podman build --net=host -t localhost/fcos-derived --squash .
if test "${touched_resolv_conf}" -eq 1; then
rm -vf /etc/resolv.conf
fi
Comment on lines +143 to +161
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code for building a derived container image is duplicated multiple times in this file (see lines 52-69 and 89-107). To improve maintainability and reduce redundancy, consider extracting this logic into a reusable shell function. The function could take the Containerfile contents as an argument.

For example:

build_derived_image() {
    local containerfile_content=$1
    # It's safer to run this in a subshell to avoid `cd` affecting
    # the rest of the script, and to handle cleanup of the temp dir.
    (
        td=$(mktemp -d)
        trap 'rm -rf -- "$td"' EXIT
        cd "$td"
        cat > Containerfile << EOF
${containerfile_content}
EOF

        local touched_resolv_conf=0
        if test '!' -f /etc/resolv.conf; then
            podmanv=$(podman --version)
            case "${podmanv#podman version }" in
                3.*) touched_resolv_conf=1; touch /etc/resolv.conf;;
            esac
        fi
        podman build --net=host -t localhost/fcos-derived --squash .
        if test "${touched_resolv_conf}" -eq 1; then
            rm -vf /etc/resolv.conf
        fi
    )
}

Then you could call it like this:

build_derived_image "FROM localhost/fcos
RUN touch /usr/foo
LABEL org.opencontainers.image.version 3"


echo "Test that a further update is properly found if there is already a staged update"
rpm-ostree upgrade --check > out.txt
assert_file_has_content_literal out.txt 'AvailableUpdate:'
assert_file_has_content_literal out.txt 'Total layers:'
assert_file_has_content_literal out.txt 'Size:'
assert_file_has_content_literal out.txt 'Removed layers:'
assert_file_has_content_literal out.txt 'Added layers:'

echo "Test that a further update is properly cached if there is already a staged update"
rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
assert_file_has_content_literal out.txt '"removed-size":'
assert_file_has_content_literal out.txt '"total-size":'
assert_file_has_content_literal out.txt '"total":'
assert_file_has_content_literal out.txt '"added-size":'
assert_file_has_content_literal out.txt '"version": "3"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'
Comment on lines +173 to +180
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This set of assertions is very similar to the one in lines 131-138. The only difference is the version number being checked. To avoid code duplication and improve readability, you could extract these assertions into a helper function that takes the version number as a parameter.

For example:

assert_cached_update_status() {
    local version=$1
    assert_file_has_content_literal out.txt '"n-added":'
    assert_file_has_content_literal out.txt '"n-removed":'
    assert_file_has_content_literal out.txt '"removed-size":'
    assert_file_has_content_literal out.txt '"total-size":'
    assert_file_has_content_literal out.txt '"total":'
    assert_file_has_content_literal out.txt '"added-size":'
    assert_file_has_content_literal out.txt "'"version"': '"${version}"'"
    assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'
}

Then you could call it with assert_cached_update_status 3.


echo "Test that staged updates versions are properly reported accross rpm-ostreed daemon restarts"
sudo systemctl restart rpm-ostreed.service
rpm-ostree status --json | jq '."cached-update"' > out.txt
assert_file_has_content_literal out.txt '"n-added":'
assert_file_has_content_literal out.txt '"n-removed":'
assert_file_has_content_literal out.txt '"removed-size":'
assert_file_has_content_literal out.txt '"total-size":'
assert_file_has_content_literal out.txt '"total":'
assert_file_has_content_literal out.txt '"added-size":'
assert_file_has_content_literal out.txt '"version": "3"'
assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"'

esac
Loading