From 799a809c2dd2a767a03d0984338b5b2fc1345bf5 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 6 Feb 2018 14:03:22 -0500 Subject: [PATCH] Add support for `deploy ` in `rojig://` mode This fleshes out an important piece of the story, showing that we can support history versioning the same way that we did with ostree. Also it's very useful for testing; I'm going to extend the suite after this to deploy the previous version, clean everything up, then upgrade and verify we only download changed RPMs. Closes: #1232 Approved by: jlebon --- src/daemon/rpmostree-sysroot-upgrader.c | 3 +- src/daemon/rpmostreed-transaction-types.c | 64 ++++++++++++++++------- src/libpriv/rpmostree-core.c | 2 + src/libpriv/rpmostree-origin.c | 12 +++++ src/libpriv/rpmostree-origin.h | 4 ++ tests/vmcheck/test-jigdo-client.sh | 13 ++++- 6 files changed, 76 insertions(+), 22 deletions(-) diff --git a/src/daemon/rpmostree-sysroot-upgrader.c b/src/daemon/rpmostree-sysroot-upgrader.c index 3ac4a33e..ef906d3e 100644 --- a/src/daemon/rpmostree-sysroot-upgrader.c +++ b/src/daemon/rpmostree-sysroot-upgrader.c @@ -439,7 +439,8 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self, case RPMOSTREE_REFSPEC_TYPE_ROJIG: { // Not implemented yet, though we could do a query for the provides - g_assert (!override_commit); + if (override_commit) + return glnx_throw (error, "Specifying commit overrides for rojig:// is not implemented yet"); g_autoptr(GKeyFile) tsk = g_key_file_new (); g_key_file_set_string (tsk, "tree", "jigdo", refspec); diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c index e8e070b0..a1c4ef77 100644 --- a/src/daemon/rpmostreed-transaction-types.c +++ b/src/daemon/rpmostreed-transaction-types.c @@ -122,6 +122,8 @@ change_origin_refspec (OstreeSysroot *sysroot, return TRUE; } +/* Handle `deploy` semantics of pinning to a version or checksum. See + * rpmostreed_parse_revision() for available syntax for @revision */ static gboolean apply_revision_override (RpmostreedTransaction *transaction, OstreeRepo *repo, @@ -131,41 +133,63 @@ apply_revision_override (RpmostreedTransaction *transaction, GCancellable *cancellable, GError **error) { + RpmOstreeRefspecType refspectype; + rpmostree_origin_classify_refspec (origin, &refspectype, NULL); + g_autofree char *checksum = NULL; g_autofree char *version = NULL; - - if (!rpmostreed_parse_revision (revision, - &checksum, - &version, - error)) + if (!rpmostreed_parse_revision (revision, &checksum, &version, error)) return FALSE; if (version != NULL) { - rpmostreed_transaction_emit_message_printf (transaction, - "Resolving version '%s'", - version); + switch (refspectype) + { + case RPMOSTREE_REFSPEC_TYPE_OSTREE: + { + /* Perhaps down the line we'll drive history traversal into libostree */ + rpmostreed_transaction_emit_message_printf (transaction, + "Resolving version '%s'", + version); - if (!rpmostreed_repo_lookup_version (repo, rpmostree_origin_get_refspec (origin), - version, progress, - cancellable, &checksum, error)) - return FALSE; + if (!rpmostreed_repo_lookup_version (repo, rpmostree_origin_get_refspec (origin), + version, progress, + cancellable, &checksum, error)) + return FALSE; + + rpmostree_origin_set_override_commit (origin, checksum, version); + } + break; + case RPMOSTREE_REFSPEC_TYPE_ROJIG: + /* This case we'll look up later */ + rpmostree_origin_set_jigdo_version (origin, version); + break; + } } else { g_assert (checksum != NULL); - rpmostreed_transaction_emit_message_printf (transaction, - "Validating checksum '%s'", - checksum); + switch (refspectype) + { + case RPMOSTREE_REFSPEC_TYPE_OSTREE: + rpmostreed_transaction_emit_message_printf (transaction, + "Validating checksum '%s'", + checksum); + if (!rpmostreed_repo_lookup_checksum (repo, rpmostree_origin_get_refspec (origin), + checksum, progress, cancellable, error)) + return FALSE; + break; + case RPMOSTREE_REFSPEC_TYPE_ROJIG: + /* For now we skip validation here, if there's an error we'll see it later + * on. + */ + break; + } - if (!rpmostreed_repo_lookup_checksum (repo, rpmostree_origin_get_refspec (origin), - checksum, progress, cancellable, error)) - return FALSE; + rpmostree_origin_set_override_commit (origin, checksum, version); } - rpmostree_origin_set_override_commit (origin, checksum, version); - return TRUE; } diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index bf35552c..385ebba4 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -250,7 +250,9 @@ rpmostree_treespec_new_from_keyfile (GKeyFile *keyfile, } BIND_STRING("jigdo"); + BIND_STRING("jigdo-version"); BIND_STRING("releasever"); +#undef BIND_STRING add_canonicalized_string_array (&builder, "packages", NULL, keyfile); add_canonicalized_string_array (&builder, "cached-packages", NULL, keyfile); diff --git a/src/libpriv/rpmostree-origin.c b/src/libpriv/rpmostree-origin.c index 764df615..cb67d4fc 100644 --- a/src/libpriv/rpmostree-origin.c +++ b/src/libpriv/rpmostree-origin.c @@ -388,6 +388,18 @@ rpmostree_origin_set_override_commit (RpmOstreeOrigin *origin, origin->cached_override_commit = g_strdup (checksum); } +void +rpmostree_origin_set_jigdo_version (RpmOstreeOrigin *origin, + const char *version) +{ + if (version) + g_key_file_set_string (origin->kf, "origin", "jigdo-version", version); + else + g_key_file_remove_key (origin->kf, "origin", "jigdo-version", NULL); + g_free (origin->cached_jigdo_version); + origin->cached_jigdo_version = g_strdup (version); +} + gboolean rpmostree_origin_set_rebase (RpmOstreeOrigin *origin, const char *new_refspec, diff --git a/src/libpriv/rpmostree-origin.h b/src/libpriv/rpmostree-origin.h index c09e3359..e39dd5b3 100644 --- a/src/libpriv/rpmostree-origin.h +++ b/src/libpriv/rpmostree-origin.h @@ -117,6 +117,10 @@ rpmostree_origin_set_override_commit (RpmOstreeOrigin *origin, const char *checksum, const char *version); +void +rpmostree_origin_set_jigdo_version (RpmOstreeOrigin *origin, + const char *version); + gboolean rpmostree_origin_set_rebase (RpmOstreeOrigin *origin, const char *new_refspec, diff --git a/tests/vmcheck/test-jigdo-client.sh b/tests/vmcheck/test-jigdo-client.sh index 02580b8a..db4ce7a0 100755 --- a/tests/vmcheck/test-jigdo-client.sh +++ b/tests/vmcheck/test-jigdo-client.sh @@ -41,4 +41,15 @@ vm_rpmostree rebase --experimental rojig://fahc:fedora-atomic-host vm_assert_status_jq '.deployments[0].origin|startswith("rojig://fahc:fedora-atomic-host")' vm_cmd ostree refs > refs.txt assert_file_has_content refs.txt '^rpmostree/jigdo/kernel-core/' -echo "ok jigdo client" +echo "ok jigdo client rebase " + +version=$(vm_get_deployment_info 0 version) +version_major=$(echo ${version} | cut -f 1 -d '.') +version_minor=$(echo ${version} | cut -f 2 -d '.') +prev_version=${version_major}.$((${version_minor} - 1)) +assert_not_streq "${version}" "${prev_version}" +vm_rpmostree deploy ${prev_version} +vm_assert_status_jq '.deployments[0].origin|startswith("rojig://fahc:fedora-atomic-host")' \ + '.deployments[0].version == "'${prev_version}'"' + +echo "ok jigdo client deploy"