Skip to content

Commit

Permalink
app/status: Display update driver info
Browse files Browse the repository at this point in the history
Read from `/run/rpm-ostree/update-driver.gv` and display the update
driver name (and systemd unit if verbose).
  • Loading branch information
kelvinfan001 committed Jan 21, 2021
1 parent bf02d33 commit 69a1bc8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "rpmostree-builtins.h"
#include "rpmostree-ex-builtins.h"
#include "rpmostree-libbuiltin.h"
#include "rpmostreed-transaction-types.h"
#include "rpmostree-dbus-helpers.h"
#include "rpmostree-util.h"
#include "rpmostree-core.h"
Expand Down Expand Up @@ -289,7 +290,20 @@ print_daemon_state (RPMOSTreeSysroot *sysroot_proxy,

rpmostreecxx::journal_print_staging_failure ();

if (g_str_equal (policy, "none"))
g_autofree char *update_driver_sd_unit = NULL;
g_autofree char *update_driver_name = NULL;
if (!get_driver_info (&update_driver_name, &update_driver_sd_unit, error))
return FALSE;

if (update_driver_name && update_driver_sd_unit)
{
if (opt_verbose)
g_print ("AutomaticUpdates: driven by %s (%s)\n",
update_driver_name, update_driver_sd_unit);
else
g_print ("AutomaticUpdates: driven by %s\n", update_driver_name);
}
else if (g_str_equal (policy, "none"))
{
/* https://github.com/coreos/fedora-coreos-tracker/issues/271
* https://github.com/coreos/rpm-ostree/issues/1747
Expand Down Expand Up @@ -1061,6 +1075,9 @@ rpmostree_builtin_status (int argc,
g_autoptr(GVariant) cached_update = NULL;
if (rpmostree_os_get_has_cached_update_rpm_diff (os_proxy))
cached_update = rpmostree_os_dup_cached_update (os_proxy);
g_autoptr(GVariant) driver_g_variant;
if (!get_driver_g_variant (&driver_g_variant, error))
return FALSE;

if (opt_json || opt_jsonpath)
{
Expand All @@ -1081,6 +1098,10 @@ rpmostree_builtin_status (int argc,
else
cached_update_node = json_node_new (JSON_NODE_NULL);
json_builder_add_value (builder, cached_update_node);
json_builder_set_member_name (builder, "update-driver");
JsonNode *update_driver_node =
driver_g_variant ? json_gvariant_serialize (driver_g_variant) : json_node_new (JSON_NODE_NULL);
json_builder_add_value (builder, update_driver_node);
json_builder_end_object (builder);

JsonNode *json_root = json_builder_get_root (builder);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/rpmostreed-transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gboolean rpmostreed_transaction_get_active (RpmostreedTransactio
OstreeSysroot * rpmostreed_transaction_get_sysroot (RpmostreedTransaction *transaction);
const char * rpmostreed_transaction_get_client (RpmostreedTransaction *transaction);
const char * rpmostreed_transaction_get_agent_id (RpmostreedTransaction *transaction);
const char * rpmostreed_transaction_get_sd_unit (RpmostreedTransaction *transaction);
const char * rpmostreed_transaction_get_sd_unit (RpmostreedTransaction *transaction);
GDBusMethodInvocation *
rpmostreed_transaction_get_invocation (RpmostreedTransaction *transaction);
const char * rpmostreed_transaction_get_client_address (RpmostreedTransaction *transaction);
Expand Down
13 changes: 11 additions & 2 deletions tests/vmcheck/test-misc-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ assert_streq "$(vm_get_booted_csum)" "${booted_csum}"
vm_assert_journal_has_content $cursor 'Not finalizing; found /run/ostree/staged-deployment-locked'
echo "ok locked rebase staging"

# This also now tests custom client IDs in the journal
# This also now tests custom client IDs in the journal and the `deploy --register-driver` option.
cursor=$(vm_get_journal_cursor)
vm_cmd env RPMOSTREE_CLIENT_ID=testing-agent-id rpm-ostree deploy revision="${commit}" --lock-finalization
vm_cmd env RPMOSTREE_CLIENT_ID=testing-agent-id \
rpm-ostree deploy revision="${commit}" \
--lock-finalization --register-driver TestDriver
vm_cmd test -f /run/rpm-ostree/update-driver.gv
vm_cmd test -f /run/ostree/staged-deployment-locked
if vm_rpmostree finalize-deployment; then
assert_not_reached "finalized without expected checksum"
Expand All @@ -57,6 +60,12 @@ vm_cmd journalctl --after-cursor "'$cursor'" -u rpm-ostreed -o json | jq -r '.AG
assert_file_has_content agent.txt testing-agent-id
vm_cmd journalctl --after-cursor "'$cursor'" -u rpm-ostreed -o json | jq -r '.AGENT_SD_UNIT//""' > agent_sd_unit.txt
assert_file_has_content agent_sd_unit.txt sshd.service
vm_cmd rpm-ostree status > status.txt
assert_file_has_content status.txt 'driven by TestDriver'
vm_cmd rpm-ostree status -v > verbose_status.txt
assert_file_has_content verbose_status.txt 'driven by TestDriver (sshd.service)'
vm_assert_status_jq ".\"update-driver\"[\"driver-name\"] == \"TestDriver\"" \
".\"update-driver\"[\"driver-sd-unit\"] == \"sshd.service\""
vm_reboot_cmd rpm-ostree finalize-deployment "${commit}"
assert_streq "$(vm_get_booted_csum)" "${commit}"
vm_assert_journal_has_content $cursor "Finalized deployment; rebooting into ${commit}"
Expand Down

0 comments on commit 69a1bc8

Please sign in to comment.