Skip to content

Commit

Permalink
app: support full offline operations with --cache-only
Browse files Browse the repository at this point in the history
As @cgwalters mentioned in coreos#1035, the new `--cache-only` implemented
only the rpmmd half of the story. Here we complete that story by also
ensuring that when in cache-only mode, we don't download new ostree data
nor new packages. We try to complete the requested operation with what
we have.

To do this, we add support for the same `SYNTHETIC` pull that was added
in ostree[1] so that we don't actually pull, but still perform timestamp
checking.

On the pkgcache side, we disable all remote repos and instead insert all
our cached RPMs into the `DnfSack`. Care is taken to still perform
SHA256 verification for local pkg installs/replacements.

[1] ostreedev/ostree#642
  • Loading branch information
jlebon committed Oct 10, 2017
1 parent 4c53fd8 commit 885af7c
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 37 deletions.
23 changes: 23 additions & 0 deletions man/rpm-ostree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ Boston, MA 02111-1307, USA.
inspect the RPM diff, but do not actually create a new
deployment.
</para>

<para>
<option>--cache-only</option> to perform the operation
without trying to download the target tree from the remote
nor the latest packages.
</para>
</listitem>
</varlistentry>

Expand All @@ -206,6 +212,11 @@ Boston, MA 02111-1307, USA.
exit after printing the transaction rather than downloading
the packages and creating a new deployment.
</para>

<para>
<option>--cache-only</option> to perform the operation
without trying to download the latest packages.
</para>
</listitem>
</varlistentry>

Expand Down Expand Up @@ -265,6 +276,12 @@ Boston, MA 02111-1307, USA.
to pick a remote name.
</para>

<para>
<option>--cache-only</option> to perform the rebase without
trying to download the target tree from the remote nor the
latest packages.
</para>

</listitem>
</varlistentry>

Expand Down Expand Up @@ -350,6 +367,12 @@ Boston, MA 02111-1307, USA.
available, without downloading it or performing a
package-level diff.
</para>

<para>
<option>--cache-only</option> to perform the upgrade without
trying to download the latest tree from the remote nor the
latest packages.
</para>
</listitem>
</varlistentry>

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static GOptionEntry option_entries[] = {
* A --preview option would work for both commands if we wanted to
* 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 update repo metadata cache", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and rpmmd data", NULL },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static GOptionEntry option_entries[] = {
{ "remote", 'm', 0, G_OPTION_ARG_STRING, &opt_remote, "Rebase to current branch name using REMOTE; may also be combined with --branch", "REMOTE" },
{ "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 update repo metadata cache", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and rpmmd data", NULL },
{ NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static GOptionEntry option_entries[] = {
{ "check-diff", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_preview, "Check for upgrades and print package diff only", NULL },
{ "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 update repo metadata cache", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and rpmmd data", 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
2 changes: 1 addition & 1 deletion src/app/rpmostree-dbus-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ rpmostree_get_options_variant (gboolean reboot,
g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "reboot", "b", reboot);
g_variant_dict_insert (&dict, "allow-downgrade", "b", allow_downgrade);
g_variant_dict_insert (&dict, "rpmmd-cache-only", "b", cache_only);
g_variant_dict_insert (&dict, "cache-only", "b", cache_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
2 changes: 1 addition & 1 deletion src/app/rpmostree-pkg-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 update repo metadata cache", NULL },
{ "cache-only", 'C', 0, G_OPTION_ARG_NONE, &opt_cache_only, "Do not download latest ostree and rpmmd data", NULL },
{ NULL }
};

Expand Down
9 changes: 5 additions & 4 deletions src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,14 @@
Do not pull a base layer from the remote. Not valid if
either "set-refspec" or "set-revision" is specified.
"dry-run" (type 'b')
Stop short of deploying the new tree. If
layering packages, the pkg diff is printed.
Stop short of deploying the new tree. If layering packages,
the pkg diff is printed but packages are not downloaded or
imported.
"no-overrides" (type 'b')
Remove all active overrides. Not valid if any override
modifiers are specified.
"rpmmd-cache-only" (type 'b')
Do not update rpmmd repo metadata cache.
"cache-only" (type 'b')
Do not update rpmmd repo metadata cache or ostree refspec.
-->
<method name="UpdateDeployment">
<arg type="a{sv}" name="modifiers" direction="in"/>
Expand Down
17 changes: 8 additions & 9 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,13 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self,

const gboolean allow_older =
(self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_ALLOW_OLDER) > 0;
const gboolean synthetic =
(self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_SYNTHETIC_PULL) > 0;

const char *override_commit = rpmostree_origin_get_override_commit (self->origin);

g_assert (self->origin_merge_deployment);
if (origin_remote)
if (origin_remote && !synthetic)
{
g_autoptr(GVariantBuilder) optbuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
if (dir_to_pull && *dir_to_pull)
Expand Down Expand Up @@ -428,8 +430,8 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self,
gboolean changed = !g_str_equal (new_base_rev, self->base_revision);
if (changed)
{
/* check timestamps here too in case the commit was already pulled (or the
* refspec is local) */
/* check timestamps here too in case the commit was already pulled, or the pull was
* synthetic, or the refspec is local */
if (!allow_older)
{
if (!ostree_sysroot_upgrader_check_timestamps (self->repo, self->base_revision,
Expand Down Expand Up @@ -548,6 +550,9 @@ generate_treespec (RpmOstreeSysrootUpgrader *self)
self->override_remove_packages->len);
}

if (self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_PKGCACHE_ONLY)
g_key_file_set_boolean (treespec, "tree", "cache-only", TRUE);

return rpmostree_treespec_new_from_keyfile (treespec, NULL);
}

Expand Down Expand Up @@ -814,12 +819,6 @@ prep_local_assembly (RpmOstreeSysrootUpgrader *self,
cancellable, error))
return FALSE;

if (self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_RPMMD_CACHE_ONLY)
{
DnfContext *hifctx = rpmostree_context_get_hif (self->ctx);
dnf_context_set_cache_age (hifctx, G_MAXUINT);
}

g_autoptr(OstreeRepo) pkgcache_repo = NULL;
if (!rpmostree_get_pkgcache_repo (self->repo, &pkgcache_repo, cancellable, error))
return FALSE;
Expand Down
6 changes: 4 additions & 2 deletions src/daemon/rpmostree-sysroot-upgrader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (RpmOstreeSysrootUpgrader, g_object_unref)
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED: Do not error if the origin has an unconfigured-state key
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_ALLOW_OLDER: Do not error if the new deployment was composed earlier than the current deployment
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_DRY_RUN: Don't deploy new base. If layering packages, only print the transaction
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_DRY_RUN: Don't update rpmmd cache.
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_PKGCACHE_ONLY: Don't try to update cached packages.
* @RPMOSTREE_SYSROOT_UPGRADER_FLAGS_SYNTHETIC_PULL: Don't actually pull, just resolve ref and timstamp check
*
* Flags controlling operation of an #RpmOstreeSysrootUpgrader.
*/
Expand All @@ -50,7 +51,8 @@ typedef enum {
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED = (1 << 1),
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_ALLOW_OLDER = (1 << 2),
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_DRY_RUN = (1 << 3),
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_RPMMD_CACHE_ONLY = (1 << 4)
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_PKGCACHE_ONLY = (1 << 4),
RPMOSTREE_SYSROOT_UPGRADER_FLAGS_SYNTHETIC_PULL = (1 << 5),
} RpmOstreeSysrootUpgraderFlags;

/* _NONE means we're doing pure ostree, no client-side computation.
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/rpmostreed-os.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ deploy_flags_from_options (GVariant *options,
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DRY_RUN;
if (vardict_lookup_bool (&dict, "no-overrides", FALSE))
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_OVERRIDES;
if (vardict_lookup_bool (&dict, "rpmmd-cache-only", FALSE))
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_RPMMD_CACHE_ONLY;
if (vardict_lookup_bool (&dict, "cache-only", FALSE))
ret |= RPMOSTREE_TRANSACTION_DEPLOY_FLAG_CACHE_ONLY;
return ret;
}

Expand Down
18 changes: 15 additions & 3 deletions src/daemon/rpmostreed-transaction-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,20 @@ deploy_transaction_execute (RpmostreedTransaction *transaction,
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_ALLOW_OLDER;
if (self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DRY_RUN)
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_DRY_RUN;
if (self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_RPMMD_CACHE_ONLY)
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_RPMMD_CACHE_ONLY;
const gboolean no_overrides =
((self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_OVERRIDES) > 0);

if (self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_CACHE_ONLY)
{
/* practically, we could unite those two into a single flag, though it's nice to be
* able to keep them separate as well */

/* don't pull, just resolve ref locally and timestamp check */
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_SYNTHETIC_PULL;
/* turn on rpmmd cache only in the upgrader */
upgrader_flags |= RPMOSTREE_SYSROOT_UPGRADER_FLAGS_PKGCACHE_ONLY;
}

/* this should have been checked already */
if (no_overrides)
{
Expand Down Expand Up @@ -803,7 +812,10 @@ deploy_transaction_execute (RpmostreedTransaction *transaction,
rpmostree_sysroot_upgrader_set_origin (upgrader, origin);

/* Mainly for the `install` and `override` commands */
if (!(self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_PULL_BASE))
const gboolean no_pull_base =
((self->flags & RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_PULL_BASE) > 0);

if (!no_pull_base)
{
gboolean base_changed;

Expand Down
2 changes: 1 addition & 1 deletion src/daemon/rpmostreed-transaction-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum {
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_PULL_BASE = (1 << 4),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_DRY_RUN = (1 << 5),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_NO_OVERRIDES = (1 << 6),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_RPMMD_CACHE_ONLY = (1 << 7),
RPMOSTREE_TRANSACTION_DEPLOY_FLAG_CACHE_ONLY = (1 << 7),
} RpmOstreeTransactionDeployFlags;


Expand Down
Loading

0 comments on commit 885af7c

Please sign in to comment.