Skip to content

Commit

Permalink
app: Add --lock-finalization switch to other commands
Browse files Browse the repository at this point in the history
Both `upgrade` and `deploy` already support this. There's no reason why
all the remaining "deployment-creating" commands shouldn't. Prompted by
openshift/machine-config-operator#1897 which
will need this specifically for `rebase`.
  • Loading branch information
jlebon authored and openshift-merge-robot committed Jul 8, 2020
1 parent d29627c commit f608eb0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ static gboolean opt_enable;
static gboolean opt_disable;
static char **opt_add_arg;
static gboolean opt_reboot;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "enable", 0, 0, G_OPTION_ARG_NONE, &opt_enable, "Enable regenerating initramfs locally", NULL },
{ "arg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_add_arg, "Append ARG to the dracut arguments", "ARG" },
{ "disable", 0, 0, G_OPTION_ARG_NONE, &opt_disable, "Disable regenerating initramfs locally", NULL },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after operation is complete", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -136,6 +138,7 @@ rpmostree_builtin_initramfs (int argc,
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

g_autofree char *transaction_address = NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-kargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static char **opt_kernel_append_strings;
static char **opt_kernel_replace_strings;
static char *opt_osname;
static char *opt_deploy_index;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operation on provided OSNAME", "OSNAME" },
Expand All @@ -45,6 +46,7 @@ static GOptionEntry option_entries[] = {
{ "delete", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_delete_strings, "Delete a specific kernel argument key/val pair or an entire argument with a single key/value pair", "KEY=VALUE"},
{ "import-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_import_proc_cmdline, "Instead of modifying old kernel arguments, we modify args from current /proc/cmdline (the booted deployment)", NULL },
{ "editor", 0, 0, G_OPTION_ARG_NONE, &opt_editor, "Use an editor to modify the kernel arguments", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -265,6 +267,7 @@ rpmostree_builtin_kargs (int argc,
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", opt_reboot);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

if (opt_editor)
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static gboolean opt_cache_only;
static gboolean opt_download_only;
static gboolean opt_experimental;
static gboolean opt_disallow_downgrade;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -55,6 +56,7 @@ static GOptionEntry option_entries[] = {
{ "custom-origin-url", 0, 0, G_OPTION_ARG_STRING, &opt_custom_origin_url, "Machine-readable description of custom origin", NULL },
{ "experimental", 0, 0, G_OPTION_ARG_NONE, &opt_experimental, "Enable experimental features", NULL },
{ "disallow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_disallow_downgrade, "Forbid deployment of chronologically older trees", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -168,6 +170,7 @@ rpmostree_builtin_rebase (int argc,
g_variant_dict_insert (&dict, "download-only", "b", opt_download_only);
g_variant_dict_insert (&dict, "skip-purge", "b", opt_skip_purge);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
if (opt_custom_origin_url)
{
if (!opt_custom_origin_description)
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ static gboolean opt_reboot;
static gboolean opt_overlays;
static gboolean opt_overrides;
static gboolean opt_initramfs;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after transaction is complete", NULL },
{ "overlays", 'l', 0, G_OPTION_ARG_NONE, &opt_overlays, "Remove all overlayed packages", NULL },
{ "overrides", 'o', 0, G_OPTION_ARG_NONE, &opt_overrides, "Remove all overrides", NULL },
{ "initramfs", 'i', 0, G_OPTION_ARG_NONE, &opt_initramfs, "Stop regenerating initramfs", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -101,6 +103,7 @@ rpmostree_builtin_reset (int argc,
g_variant_dict_insert (&dict, "no-initramfs", "b", opt_initramfs);
g_variant_dict_insert (&dict, "cache-only", "b", cache_only);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

if (!rpmostree_update_deployment (os_proxy, NULL, NULL, install_pkgs, uninstall_pkgs,
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-override-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ static const char *const *opt_remove_pkgs;
static const char *const *opt_replace_pkgs;
static const char *const *install_pkgs;
static const char *const *uninstall_pkgs;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after operation is complete", NULL },
{ "dry-run", 'n', 0, G_OPTION_ARG_NONE, &opt_dry_run, "Exit after printing the transaction", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -83,6 +85,7 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
g_variant_dict_insert (&dict, "dry-run", "b", opt_dry_run);
g_variant_dict_insert (&dict, "no-overrides", "b", opt_reset_all);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy);
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-pkg-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static gboolean opt_download_only;
static gboolean opt_allow_inactive;
static gboolean opt_uninstall_all;
static gboolean opt_unchanged_exit_77;
static gboolean opt_lock_finalization;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -48,6 +49,7 @@ static GOptionEntry option_entries[] = {
{ "allow-inactive", 0, 0, G_OPTION_ARG_NONE, &opt_allow_inactive, "Allow inactive package requests", NULL },
{ "idempotent", 0, 0, G_OPTION_ARG_NONE, &opt_idempotent, "Do nothing if package already (un)installed", NULL },
{ "unchanged-exit-77", 0, 0, G_OPTION_ARG_NONE, &opt_unchanged_exit_77, "If no overlays were changed, exit 77", NULL },
{ "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL },
{ NULL }
};

Expand Down Expand Up @@ -97,6 +99,7 @@ pkg_change (RpmOstreeCommandInvocation *invocation,
g_variant_dict_insert (&dict, "no-layering", "b", opt_uninstall_all);
g_variant_dict_insert (&dict, "idempotent-layering", "b", opt_idempotent);
g_variant_dict_insert (&dict, "initiating-command-line", "s", invocation->command_line);
g_variant_dict_insert (&dict, "lock-finalization", "b", opt_lock_finalization);
g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_dict_end (&dict));

gboolean met_local_pkg = FALSE;
Expand Down
8 changes: 7 additions & 1 deletion src/daemon/rpmostreed-transaction-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,8 +1735,12 @@ initramfs_state_transaction_execute (RpmostreedTransaction *transaction,

rpmostree_transaction_set_title ((RPMOSTreeTransaction*)self, command_line ?: "initramfs");

RpmOstreeSysrootUpgraderFlags upgrader_flags = 0;
if (vardict_lookup_bool (self->options, "lock-finalization", FALSE))
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_LOCK_FINALIZATION;

g_autoptr(RpmOstreeSysrootUpgrader) upgrader =
rpmostree_sysroot_upgrader_new (sysroot, self->osname, 0, cancellable, error);
rpmostree_sysroot_upgrader_new (sysroot, self->osname, upgrader_flags, cancellable, error);
if (upgrader == NULL)
return FALSE;

Expand Down Expand Up @@ -2426,6 +2430,8 @@ kernel_arg_transaction_execute (RpmostreedTransaction *transaction,
/* don't want to pull new content for this */
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_SYNTHETIC_PULL;
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_PKGCACHE_ONLY;
if (vardict_lookup_bool (self->options, "lock-finalization", FALSE))
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_LOCK_FINALIZATION;

rpmostree_transaction_set_title ((RPMOSTreeTransaction*)self, command_line ?: "kargs");

Expand Down
9 changes: 8 additions & 1 deletion tests/vmcheck/test-misc-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ cursor=$(vm_get_journal_cursor)
vm_reboot
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 staging"
echo "ok locked deploy staging"
vm_rpmostree rebase :"${commit}" --lock-finalization --skip-purge
vm_cmd test -f /run/ostree/staged-deployment-locked
cursor=$(vm_get_journal_cursor)
vm_reboot
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"

vm_rpmostree deploy revision="${commit}" --lock-finalization
vm_cmd test -f /run/ostree/staged-deployment-locked
Expand Down

0 comments on commit f608eb0

Please sign in to comment.