app/status: Print diff/advisories with pending deployment

Follow-up from #1344.

In the case where a cached update is created from an `upgrade` operation
(and soon, "stage" auto-update policy runs), we can just print the diff
and advisory info together with the pending deployment. This makes the
output look much more natural.

Closes: #1350
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-05-04 10:20:19 -04:00 committed by Atomic Bot
parent 33ea6fbc96
commit c1c78154b1
3 changed files with 65 additions and 5 deletions

View File

@ -391,6 +391,10 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
gboolean first,
gboolean have_any_live_overlay,
gboolean have_multiple_stateroots,
const char *booted_osname,
const char *cached_update_deployment_id,
GVariant *cached_update,
gboolean *out_printed_cached_update,
GError **error)
{
/* Add the long keys here */
@ -620,6 +624,24 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
if (gpg_enabled)
rpmostree_print_gpg_info (signatures, opt_verbose, max_key_len);
/* Print rpm diff and advisories summary if this is a pending deployment matching the
* deployment on which the cached update is based. */
if (first && !is_booted &&
g_strcmp0 (os_name, booted_osname) == 0 &&
g_strcmp0 (id, cached_update_deployment_id) == 0)
{
g_auto(GVariantDict) dict;
g_variant_dict_init (&dict, cached_update);
g_autoptr(GVariant) rpm_diff =
g_variant_dict_lookup_value (&dict, "rpm-diff", G_VARIANT_TYPE ("a{sv}"));
g_autoptr(GVariant) advisories =
g_variant_dict_lookup_value (&dict, "advisories", G_VARIANT_TYPE ("a(suuasa{sv})"));
if (!rpmostree_print_diff_advisories (rpm_diff, advisories,
opt_verbose, max_key_len, error))
return FALSE;
*out_printed_cached_update = TRUE;
}
/* print base overrides before overlays */
g_autoptr(GPtrArray) active_removals = g_ptr_array_new_with_free_func (g_free);
if (origin_base_removals)
@ -787,12 +809,15 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
static gboolean
print_deployments (RPMOSTreeSysroot *sysroot_proxy,
GVariant *deployments,
GVariant *cached_update,
gboolean *out_printed_cached_update,
GCancellable *cancellable,
GError **error)
{
GVariantIter iter;
/* First, gather global state */
const char *booted_osname = NULL;
gboolean have_any_live_overlay = FALSE;
gboolean have_multiple_stateroots = FALSE;
const char *last_osname = NULL;
@ -822,10 +847,26 @@ print_deployments (RPMOSTreeSysroot *sysroot_proxy,
last_osname = osname;
else if (!g_str_equal (osname, last_osname))
have_multiple_stateroots = TRUE;
gboolean is_booted;
if (!g_variant_dict_lookup (dict, "booted", "b", &is_booted))
is_booted = FALSE;
if (is_booted)
booted_osname = osname;
}
g_print ("Deployments:\n");
/* just unpack this so that each iteration doesn't have to dig for it */
const char *cached_update_deployment_id = NULL;
if (cached_update)
{
g_auto(GVariantDict) dict;
g_variant_dict_init (&dict, cached_update);
g_variant_dict_lookup (&dict, "deployment", "&s", &cached_update_deployment_id);
}
g_variant_iter_init (&iter, deployments);
gboolean first = TRUE;
@ -836,7 +877,9 @@ print_deployments (RPMOSTreeSysroot *sysroot_proxy,
break;
if (!print_one_deployment (sysroot_proxy, child, first, have_any_live_overlay,
have_multiple_stateroots, error))
have_multiple_stateroots, booted_osname,
cached_update_deployment_id, cached_update,
out_printed_cached_update, error))
return FALSE;
if (first)
first = FALSE;
@ -923,8 +966,8 @@ rpmostree_builtin_status (int argc,
}
json_node_free (json_root);
/* NB: watch out for the misleading API docs */
glnx_unref_object GOutputStream *stdout_gio = g_unix_output_stream_new (1, FALSE);
/* NB: watch out for the misleading API docs */
if (json_generator_to_stream (generator, stdout_gio, NULL, error) <= 0
|| (error != NULL && *error != NULL))
return FALSE;
@ -934,12 +977,14 @@ rpmostree_builtin_status (int argc,
if (!print_daemon_state (sysroot_proxy, bus_type, cancellable, error))
return FALSE;
if (!print_deployments (sysroot_proxy, deployments, cancellable, error))
gboolean printed_cached_update = FALSE;
if (!print_deployments (sysroot_proxy, deployments, cached_update,
&printed_cached_update, cancellable, error))
return FALSE;
const char *policy = rpmostree_sysroot_get_automatic_update_policy (sysroot_proxy);
gboolean auto_updates_enabled = (!g_str_equal (policy, "none"));
if (cached_update && auto_updates_enabled)
if (cached_update && !printed_cached_update && auto_updates_enabled)
{
g_print ("\n");
if (!rpmostree_print_cached_update (cached_update, opt_verbose,

View File

@ -1116,7 +1116,11 @@ rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment,
g_variant_dict_insert (&dict, "advisories", "@a(suuasa{sv})", advisories);
}
g_variant_dict_insert (&dict, "staged", "b", staged_deployment != NULL);
if (staged_deployment)
{
g_autofree char *id = rpmostreed_deployment_generate_id (staged_deployment);
g_variant_dict_insert (&dict, "deployment", "s", id);
}
/* but if there are no updates, then just ditch the whole thing and return NULL */
if (is_new_checksum || rpmmd_modified_new)

View File

@ -136,6 +136,9 @@ assert_output() {
"SecAdvisories: VMCHECK-SEC-NONE Unknown layered-sec-none-2.0-1.x86_64" \
" VMCHECK-SEC-LOW Low layered-sec-low-2.0-1.x86_64" \
" VMCHECK-SEC-CRIT Critical layered-sec-crit-2.0-1.x86_64"
# make sure any future call doesn't forget to create fresh ones
rm -f out.txt out-verbose.txt
}
# now add all of them
@ -201,6 +204,9 @@ assert_output2() {
'Downgraded: base-pkg-bar 1.0-1 -> 0.9-3' \
'Removed: base-pkg-baz-1.1-1.x86_64' \
'Added: base-pkg-boo-3.7-2.11.x86_64'
# make sure any future call doesn't forget to create fresh ones
rm -f out.txt out-verbose.txt
}
vm_rpmostree status > out.txt
@ -238,6 +244,11 @@ assert_default_deployment_is_update() {
vm_rpmostree cleanup -m
vm_cmd systemctl stop rpm-ostreed
vm_rpmostree upgrade
vm_rpmostree status > out.txt
vm_rpmostree status -v > out-verbose.txt
# we should have printed as part of the pending deployment
assert_not_file_has_content out.txt "Available update"
assert_not_file_has_content out-verbose.txt "Available update"
assert_output2
assert_default_deployment_is_update
echo "ok upgrade"