diff --git a/src/daemon/rpmostreed-deployment-utils.cxx b/src/daemon/rpmostreed-deployment-utils.cxx index 43229bc89b..0f552db360 100644 --- a/src/daemon/rpmostreed-deployment-utils.cxx +++ b/src/daemon/rpmostreed-deployment-utils.cxx @@ -740,6 +740,25 @@ rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment, g_autoptr (GPtrArray) rpmmd_modified_new = NULL; bool container_changed = false; + if (refspectype == rpmostreecxx::RefspecType::Container) + { + // Make this an operation we allow to fail, see the other call + try + { + auto state = rpmostreecxx::query_container_image_commit (*repo, current_checksum); + container_changed + = rpmostreecxx::deployment_add_manifest_diff (*dict, state->cached_update_diff); + if (state->cached_update_diff.version.size () > 0) + g_variant_dict_insert (dict, "version", "s", + state->cached_update_diff.version.c_str ()); + g_debug ("container changed: %d", container_changed); + } + catch (std::exception &e) + { + sd_journal_print (LOG_ERR, "failed to query container image base metadata: %s", + e.what ()); + } + } if (staged_deployment) { @@ -778,25 +797,6 @@ rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment, if (!ostree_parse_refspec (r.refspec.c_str (), &origin_remote, &origin_ref, error)) return FALSE; } - else - { - // Make this an operation we allow to fail, see the other call - try - { - auto state = rpmostreecxx::query_container_image_commit (*repo, current_checksum); - container_changed - = rpmostreecxx::deployment_add_manifest_diff (*dict, state->cached_update_diff); - if (state->cached_update_diff.version.size () > 0) - g_variant_dict_insert (dict, "version", "s", - state->cached_update_diff.version.c_str ()); - g_debug ("container changed: %d", container_changed); - } - catch (std::exception &e) - { - sd_journal_print (LOG_ERR, "failed to query container image base metadata: %s", - e.what ()); - } - } /* check that it's actually layered (i.e. the requests are not all just dormant) */ if (sack && is_new_layered && rpmostree_origin_has_packages (origin)) diff --git a/tests/kolainst/destructive/container-update-check b/tests/kolainst/destructive/container-update-check index 745c44077a..d5d3393d38 100755 --- a/tests/kolainst/destructive/container-update-check +++ b/tests/kolainst/destructive/container-update-check @@ -85,10 +85,10 @@ EOF ostree container encapsulate --repo=/ostree/repo ${checksum} "${image}" --label ostree.bootable=TRUE 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,6 +106,7 @@ EOF rm -vf /etc/resolv.conf fi + # This tests that updates are properly found and cached rpm-ostree upgrade --check > out.txt assert_file_has_content_literal out.txt 'AvailableUpdate:' assert_file_has_content_literal out.txt 'Total layers:' @@ -123,4 +124,56 @@ 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"' + # This tests that staged updates versions are properly reported + rpm-ostree upgrade + 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": "2"' + assert_file_has_content_literal out.txt '"origin": "ostree-unverified-image:containers-storage:localhost/fcos-derived"' + + # This tests that a further update is properly reported if there is already a staged 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 + + 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:' + + 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