Skip to content

Commit

Permalink
container: Fix version for staged container updates
Browse files Browse the repository at this point in the history
  • Loading branch information
travier committed May 9, 2024
1 parent 5be2ecf commit d0e07fa
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 23 deletions.
38 changes: 19 additions & 19 deletions src/daemon/rpmostreed-deployment-utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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))
Expand Down
61 changes: 57 additions & 4 deletions tests/kolainst/destructive/container-update-check
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:'
Expand All @@ -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

0 comments on commit d0e07fa

Please sign in to comment.