Skip to content
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

status: Render ostree metadata source-title key #1069

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 19 additions & 0 deletions src/app/rpmostree-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
{
g_autoptr(GVariant) child = g_variant_iter_next_value (&iter);
g_autoptr(GVariantDict) dict = NULL;
g_autoptr(GVariantDict) commit_meta_dict = NULL;
g_autoptr(GVariantDict) layered_commit_meta_dict = NULL;
gboolean is_locally_assembled = FALSE;
g_autofree const gchar **origin_packages = NULL;
g_autofree const gchar **origin_requested_packages = NULL;
Expand Down Expand Up @@ -307,6 +309,23 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy,
if (base_checksum != NULL)
is_locally_assembled = TRUE;

/* Load the commit metadata into a dict */
{ g_autoptr(GVariant) commit_meta_v = NULL;
g_assert (g_variant_dict_lookup (dict, "base-commit-meta", "@a{sv}", &commit_meta_v));
commit_meta_dict = g_variant_dict_new (commit_meta_v);
}
if (is_locally_assembled)
{
g_autoptr(GVariant) layered_commit_meta_v = NULL;
g_assert (g_variant_dict_lookup (dict, "layered-commit-meta", "@a{sv}", &layered_commit_meta_v));
layered_commit_meta_dict = g_variant_dict_new (layered_commit_meta_v);
}

const gchar *source_title = NULL;
g_variant_dict_lookup (commit_meta_dict, OSTREE_COMMIT_META_KEY_SOURCE_TITLE, "&s", &source_title);
if (source_title)
g_print (" %s %s\n", libsd_special_glyph (TREE_RIGHT), source_title);

if (is_locally_assembled)
g_assert (g_variant_dict_lookup (dict, "base-timestamp", "t", &t));
else
Expand Down
22 changes: 15 additions & 7 deletions src/daemon/rpmostreed-deployment-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,36 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot,
&replaced_base_pkgs, error))
return NULL;

g_autoptr(GVariant) base_commit = NULL;
if (is_layered)
{
g_autoptr(GVariant) base_commit = NULL;

if (!ostree_repo_load_variant (repo,
OSTREE_OBJECT_TYPE_COMMIT,
base_checksum,
&base_commit,
error))
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
base_checksum, &base_commit, error))
return NULL;

g_variant_dict_insert (&dict, "base-checksum", "s", base_checksum);
variant_add_commit_details (&dict, "base-", base_commit);
/* for layered commits, check if their base commit has end of life attribute */
variant_add_metadata_attribute (&dict, OSTREE_COMMIT_META_KEY_ENDOFLIFE, "endoflife", base_commit);

/* See below for base commit metadata */
g_autoptr(GVariant) layered_metadata = g_variant_get_child_value (commit, 0);
g_variant_dict_insert (&dict, "layered-commit-meta", "@a{sv}", layered_metadata);
}
else
{
base_commit = g_variant_ref (commit);
base_checksum = g_strdup (csum);
variant_add_metadata_attribute (&dict, OSTREE_COMMIT_META_KEY_ENDOFLIFE, "endoflife", commit);
}

/* We used to bridge individual keys, but that was annoying; just pass through all
* of the commit metadata.
*/
{ g_autoptr(GVariant) base_meta = g_variant_get_child_value (commit, 0);
g_variant_dict_insert (&dict, "base-commit-meta", "@a{sv}", base_meta);
}

sigs = rpmostreed_deployment_gpg_results (repo, refspec, base_checksum, &gpg_enabled);
variant_add_commit_details (&dict, NULL, commit);

Expand Down
10 changes: 8 additions & 2 deletions tests/vmcheck/overlay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ set -x

# And then this code path in the VM

# get csum of current default deployment
# get csum and origin of current default deployment
commit=$(rpm-ostree status --json | \
python -c '
import sys, json;
deployment = json.load(sys.stdin)["deployments"][0]
print deployment["checksum"]
exit()')
origin=$(rpm-ostree status --json | \
python -c '
import sys, json;
deployment = json.load(sys.stdin)["deployments"][0]
print deployment["origin"]
exit()')

if [[ -z $commit ]] || ! ostree rev-parse $commit; then
echo "Error while determining current commit" >&2
Expand Down Expand Up @@ -59,6 +65,6 @@ fi
rm -vrf vmcheck/usr/etc/selinux/targeted/semanage.*.LOCK
# ✀✀✀ END tmp hack

ostree commit --parent=none -b vmcheck --link-checkout-speedup \
ostree commit --parent=none -b vmcheck --add-metadata-string=ostree.source-title="Dev overlay on ${origin}" --add-metadata-string=rpmostree.original-origin=${origin} --link-checkout-speedup \
--selinux-policy=vmcheck --tree=dir=vmcheck
ostree admin deploy vmcheck
6 changes: 4 additions & 2 deletions tests/vmcheck/test-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ vm_assert_status_jq \
'.deployments[0]["requested-packages"]' \
'.deployments[0]["requested-local-packages"]' \
'.deployments[0]["base-removals"]' \
'.deployments[0]["requested-base-removals"]'
echo "ok empty pkg arrays in status json"
'.deployments[0]["requested-base-removals"]' \
'.deployments[0]["base-commit-meta"]["ostree.source-title"]|contains("overlay")' \
'.deployments[0]["layered-commit-meta"]|not'
echo "ok empty pkg arrays, and commit meta correct in status json"

# Be sure an unprivileged user exists and that we can SSH into it. This is a bit
# underhanded, but we need a bona fide user session to verify non-priv status,
Expand Down
4 changes: 3 additions & 1 deletion tests/vmcheck/test-layering-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ echo "ok pkg-add foo"
vm_reboot
vm_assert_status_jq \
'.deployments[0]["base-checksum"]' \
'.deployments[0]["pending-base-checksum"]|not'
'.deployments[0]["pending-base-checksum"]|not' \
'.deployments[0]["base-commit-meta"]' \
'.deployments[0]["layered-commit-meta"]["rpmostree.clientlayer_version"] == 2'

vm_assert_layered_pkg foo-1.0 present
echo "ok pkg foo added"
Expand Down