-
Notifications
You must be signed in to change notification settings - Fork 216
test/container: Extend staged update version check #5499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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":' | ||
|
|
@@ -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 | ||
|
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
|
|
||
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Containerfilecontents as an argument.For example:
Then you could call it like this: