Skip to content

Commit

Permalink
app: add --download-only option
Browse files Browse the repository at this point in the history
To complement the new `--cache-only` option, add a `--download-only`
option. This does exactly what it says: we download the ostree, download
and import packages, but don't actually commit & deploy. This can be
used to effectively prime a follow-up `--cache-only` operation that can
be done during a more convenient/safer maintenance window.

I debated naming the two options `--pull-only` and `--deploy-only` like
the ostree equivalents. Though "pull" felt like the wrong word given
that it's associated more with ostree pulling but rpm-ostree also
downloads & imports RPMs. As for `--deploy-only` vs `--cache-only`, it
seems like `--cache-only` is a more accurate description of the
functionality (i.e. rather than describing an action, it describes a
mode). I also considered `--no-download` to make the synergy with
`--download-only` more obvious. Maybe that's better? Naming is hard...

Closes: #713

Closes: #1049
Approved by: cgwalters
  • Loading branch information
jlebon authored and rh-atomic-bot committed Oct 16, 2017
1 parent 24c184a commit e49f7cd
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 10 deletions.
32 changes: 32 additions & 0 deletions man/rpm-ostree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ Boston, MA 02111-1307, USA.
perform the operation without trying to download the target
tree from the remote nor the latest packages.
</para>

<para>
<option>--download-only</option> to only download the target
ostree and layered RPMs without actually performing the
deployment. This can be used with a subsequent
<option>--cache-only</option> invocation to perform the
operation completely offline.
</para>
</listitem>
</varlistentry>

Expand Down Expand Up @@ -218,6 +226,14 @@ Boston, MA 02111-1307, USA.
perform the operation without trying to download the latest
packages.
</para>

<para>
<option>--download-only</option> to only download the target
layered RPMs without actually performing the deployment.
This can be used with a subsequent
<option>--cache-only</option> invocation to perform the
operation completely offline.
</para>
</listitem>
</varlistentry>

Expand Down Expand Up @@ -283,6 +299,14 @@ Boston, MA 02111-1307, USA.
tree from the remote nor the latest packages.
</para>

<para>
<option>--download-only</option> to only download the target
ostree and layered RPMs without actually performing the
deployment. This can be used with a subsequent
<option>--cache-only</option> invocation to perform the
operation completely offline.
</para>

</listitem>
</varlistentry>

Expand Down Expand Up @@ -374,6 +398,14 @@ Boston, MA 02111-1307, USA.
perform the upgrade without trying to download the latest
tree from the remote nor the latest packages.
</para>

<para>
<option>--download-only</option> to only download the target
ostree and layered RPMs without actually performing the
deployment. This can be used with a subsequent
<option>--cache-only</option> invocation to perform the
operation completely offline.
</para>
</listitem>
</varlistentry>

Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static char *opt_osname;
static gboolean opt_reboot;
static gboolean opt_preview;
static gboolean opt_cache_only;
static gboolean opt_download_only;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -41,6 +42,7 @@ static GOptionEntry option_entries[] = {
* deprecate --check-diff. */
{ "preview", 0, 0, G_OPTION_ARG_NONE, &opt_preview, "Just preview package differences", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and RPM data", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Just download latest ostree and RPM data, don't deploy", NULL },
{ NULL }
};

Expand Down Expand Up @@ -112,6 +114,7 @@ rpmostree_builtin_deploy (int argc,
rpmostree_get_options_variant (opt_reboot,
TRUE, /* allow-downgrade */
opt_cache_only,
opt_download_only,
FALSE, /* skip-purge */
FALSE, /* no-pull-base */
FALSE, /* dry-run */
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 @@ -36,6 +36,7 @@ static gboolean opt_skip_purge;
static char * opt_branch;
static char * opt_remote;
static gboolean opt_cache_only;
static gboolean opt_download_only;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -44,6 +45,7 @@ static GOptionEntry option_entries[] = {
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after rebase is finished", NULL },
{ "skip-purge", 0, 0, G_OPTION_ARG_NONE, &opt_skip_purge, "Keep previous refspec after rebase", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and RPM data", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Just download latest ostree and RPM data, don't deploy", NULL },
{ NULL }
};

Expand Down Expand Up @@ -117,6 +119,7 @@ rpmostree_builtin_rebase (int argc,
rpmostree_get_options_variant (opt_reboot,
TRUE, /* allow-downgrade */
opt_cache_only,
opt_download_only,
opt_skip_purge,
FALSE, /* no-pull-base */
FALSE, /* dry-run */
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-builtin-rollback.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ rpmostree_builtin_rollback (int argc,
rpmostree_get_options_variant (opt_reboot,
FALSE, /* allow-downgrade */
FALSE, /* cache-only */
FALSE, /* download-only */
FALSE, /* skip-purge */
FALSE, /* no-pull-base */
FALSE, /* dry-run */
Expand Down
3 changes: 3 additions & 0 deletions src/app/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static gboolean opt_preview;
static gboolean opt_check;
static gboolean opt_upgrade_unchanged_exit_77;
static gboolean opt_cache_only;
static gboolean opt_download_only;

/* "check-diff" is deprecated, replaced by "preview" */
static GOptionEntry option_entries[] = {
Expand All @@ -48,6 +49,7 @@ static GOptionEntry option_entries[] = {
{ "preview", 0, 0, G_OPTION_ARG_NONE, &opt_preview, "Just preview package differences", NULL },
{ "check", 0, 0, G_OPTION_ARG_NONE, &opt_check, "Just check if an upgrade is available", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and RPM data", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Just download latest ostree and RPM data, don't deploy", NULL },
{ "upgrade-unchanged-exit-77", 0, 0, G_OPTION_ARG_NONE, &opt_upgrade_unchanged_exit_77, "If no upgrade is available, exit 77", NULL },
{ NULL }
};
Expand Down Expand Up @@ -124,6 +126,7 @@ rpmostree_builtin_upgrade (int argc,
rpmostree_get_options_variant (opt_reboot,
opt_allow_downgrade,
opt_cache_only,
opt_download_only,
FALSE, /* skip-purge */
FALSE, /* no-pull-base */
FALSE, /* dry-run */
Expand Down
2 changes: 2 additions & 0 deletions src/app/rpmostree-dbus-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ GVariant*
rpmostree_get_options_variant (gboolean reboot,
gboolean allow_downgrade,
gboolean cache_only,
gboolean download_only,
gboolean skip_purge,
gboolean no_pull_base,
gboolean dry_run,
Expand All @@ -1076,6 +1077,7 @@ rpmostree_get_options_variant (gboolean reboot,
g_variant_dict_insert (&dict, "reboot", "b", reboot);
g_variant_dict_insert (&dict, "allow-downgrade", "b", allow_downgrade);
g_variant_dict_insert (&dict, "cache-only", "b", cache_only);
g_variant_dict_insert (&dict, "download-only", "b", download_only);
g_variant_dict_insert (&dict, "skip-purge", "b", skip_purge);
g_variant_dict_insert (&dict, "no-pull-base", "b", no_pull_base);
g_variant_dict_insert (&dict, "dry-run", "b", dry_run);
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-dbus-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ GVariant*
rpmostree_get_options_variant (gboolean reboot,
gboolean allow_downgrade,
gboolean cache_only,
gboolean download_only,
gboolean skip_purge,
gboolean no_pull_base,
gboolean dry_run,
Expand Down
1 change: 1 addition & 0 deletions src/app/rpmostree-override-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy,
rpmostree_get_options_variant (opt_reboot,
FALSE, /* allow-downgrade */
cache_only,
FALSE, /* download-only */
FALSE, /* skip-purge */
TRUE, /* no-pull-base */
opt_dry_run,
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 @@ -35,6 +35,7 @@ static gboolean opt_dry_run;
static gchar **opt_install;
static gchar **opt_uninstall;
static gboolean opt_cache_only;
static gboolean opt_download_only;

static GOptionEntry option_entries[] = {
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
Expand All @@ -51,6 +52,7 @@ static GOptionEntry uninstall_option_entry[] = {
static GOptionEntry install_option_entry[] = {
{ "uninstall", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_uninstall, "Uninstall a package", "PKG" },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and RPM data", NULL },
{ "download-only", 0, 0, G_OPTION_ARG_NONE, &opt_download_only, "Just download latest ostree and RPM data, don't deploy", NULL },
{ NULL }
};

Expand Down Expand Up @@ -78,6 +80,7 @@ pkg_change (RPMOSTreeSysroot *sysroot_proxy,
rpmostree_get_options_variant (opt_reboot,
FALSE, /* allow-downgrade */
opt_cache_only,
opt_download_only,
FALSE, /* skip-purge */
TRUE, /* no-pull-base */
opt_dry_run,
Expand Down
6 changes: 6 additions & 0 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@
modifiers are specified.
"cache-only" (type 'b')
Do not update rpmmd repo metadata cache or ostree refspec.
Not valid if "download-only" is specified.
"download-only" (type 'b')
Update rpmmd repo metadata cache and ostree refspec. Do not
perform any deployments. This is like "dry-run" except that
the latter does not download and import packages. Not valid
if "cache-only" is specified.
-->
<method name="UpdateDeployment">
<arg type="a{sv}" name="modifiers" direction="in"/>
Expand Down
42 changes: 36 additions & 6 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct RpmOstreeSysrootUpgrader {
gboolean layering_initialized; /* Whether layering_type is known */
RpmOstreeSysrootUpgraderLayeringType layering_type;
gboolean layering_changed; /* Whether changes to layering should result in a new commit */
gboolean pkgs_imported; /* Whether pkgs to be layered have been downloaded & imported */
char *base_revision; /* Non-layered replicated commit */
char *final_revision; /* Computed by layering; if NULL, only using base_revision */
};
Expand Down Expand Up @@ -877,22 +878,21 @@ prep_local_assembly (RpmOstreeSysrootUpgrader *self,
return TRUE;
}

/* Download packages, overlay, run scripts, and commit final rootfs to ostree */
/* Overlay pkgs, run scripts, and commit final rootfs to ostree */
static gboolean
perform_local_assembly (RpmOstreeSysrootUpgrader *self,
GCancellable *cancellable,
GError **error)
{
g_assert (self->layering_initialized);
g_assert (self->pkgs_imported);

/* If we computed no layering is required, we're done */
if (self->layering_type == RPMOSTREE_SYSROOT_UPGRADER_LAYERING_NONE)
return TRUE;

if (self->layering_type == RPMOSTREE_SYSROOT_UPGRADER_LAYERING_RPMMD_REPOS)
{
if (!rpmostree_context_download (self->ctx, cancellable, error))
return FALSE;
if (!rpmostree_context_import (self->ctx, cancellable, error))
return FALSE;
if (!rpmostree_context_relabel (self->ctx, cancellable, error))
return FALSE;

Expand Down Expand Up @@ -1029,6 +1029,30 @@ rpmostree_sysroot_upgrader_prep_layering (RpmOstreeSysrootUpgrader *self,
return TRUE;
}

gboolean
rpmostree_sysroot_upgrader_import_pkgs (RpmOstreeSysrootUpgrader *self,
GCancellable *cancellable,
GError **error)
{
g_assert (self->layering_initialized);
g_assert (!self->pkgs_imported);
self->pkgs_imported = TRUE;

/* any layering actually required? */
if (self->layering_type == RPMOSTREE_SYSROOT_UPGRADER_LAYERING_NONE)
return TRUE;

if (self->layering_type == RPMOSTREE_SYSROOT_UPGRADER_LAYERING_RPMMD_REPOS)
{
if (!rpmostree_context_download (self->ctx, cancellable, error))
return FALSE;
if (!rpmostree_context_import (self->ctx, cancellable, error))
return FALSE;
}

return TRUE;
}

/**
* rpmostree_sysroot_upgrader_deploy:
* @self: Self
Expand Down Expand Up @@ -1058,7 +1082,13 @@ rpmostree_sysroot_upgrader_deploy (RpmOstreeSysrootUpgrader *self,
cancellable, error))
return FALSE;
}
g_assert (self->layering_initialized);

if (!self->pkgs_imported)
{
if (!rpmostree_sysroot_upgrader_import_pkgs (self, cancellable, error))
return FALSE;
}

/* Generate the final ostree commit */
if (!perform_local_assembly (self, cancellable, error))
return FALSE;
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/rpmostree-sysroot-upgrader.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ rpmostree_sysroot_upgrader_prep_layering (RpmOstreeSysrootUpgrader *self,
GCancellable *cancellable,
GError **error);

gboolean
rpmostree_sysroot_upgrader_import_pkgs (RpmOstreeSysrootUpgrader *self,
GCancellable *cancellable,
GError **error);

gboolean
rpmostree_sysroot_upgrader_pull_repos (RpmOstreeSysrootUpgrader *self,
const char *dir_to_pull,
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ deploy_flags_from_options (GVariant *options,
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_OVERRIDES;
if (vardict_lookup_bool (&dict, "cache-only", FALSE))
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_CACHE_ONLY;
if (vardict_lookup_bool (&dict, "download-only", FALSE))
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DOWNLOAD_ONLY;
return ret;
}

Expand Down Expand Up @@ -648,6 +650,9 @@ start_deployment_txn (GDBusMethodInvocation *invocation,
vardict_lookup_bool (&options_dict, "no-pull-base", FALSE))
return glnx_null_throw (error, "Can't specify no-pull-base if setting a "
"new refspec or revision");
if (vardict_lookup_bool (&options_dict, "cache-only", FALSE) &&
vardict_lookup_bool (&options_dict, "download-only", FALSE))
return glnx_null_throw (error, "Can't specify cache-only and download-only");
if (override_replace_pkgs)
return glnx_null_throw (error, "Non-local replacement overrides not implemented yet");

Expand Down
15 changes: 15 additions & 0 deletions src/daemon/rpmostreed-transaction-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,26 @@ deploy_transaction_execute (RpmostreedTransaction *transaction,
return FALSE;
changed = changed || layering_changed;

if (layering_changed)
{
if (!rpmostree_sysroot_upgrader_import_pkgs (upgrader, cancellable, error))
return FALSE;
}

/* XXX: check if this is needed */
rpmostree_transaction_emit_progress_end (RPMOSTREE_TRANSACTION (transaction));

/* TODO - better logic for "changed" based on deployments */
if (changed || self->refspec)
{
/* Note early return; we stop short of actually writing the deployment */
if (self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DOWNLOAD_ONLY)
{
/* XXX: improve msg here; e.g. cache will be blown on next operation? */
rpmostreed_transaction_emit_message_printf (transaction, "Downloaded.");
return TRUE;
}

if (!rpmostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
return FALSE;

Expand Down
1 change: 1 addition & 0 deletions src/daemon/rpmostreed-transaction-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef enum {
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DRY_RUN = (1 << 5),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_OVERRIDES = (1 << 6),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_CACHE_ONLY = (1 << 7),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DOWNLOAD_ONLY = (1 << 8),
} RpmOstreeTransactionDeployFlags;


Expand Down
Loading

0 comments on commit e49f7cd

Please sign in to comment.