Skip to content

Commit

Permalink
daemon/upgrader: Consistently remove transient state
Browse files Browse the repository at this point in the history
With the new support for pinning deployments, we need to also update
rpm-ostree to clean up the transient state as is now done in the ostree
sysroot upgrader.

This addresses that issue as well as tries to be a little cleaner in how
we clean up other transient state. Notably, we add a new helper function
to `RpmOstreeOrigin` to do this for us and use it in the upgrader. In
other cases, we do want this transient information since it allows us to
describe the deployment.

Closes: ostreedev/ostree#1595

Closes: #1372
Approved by: cgwalters
  • Loading branch information
jlebon authored and rh-atomic-bot committed May 23, 2018
1 parent 592d605 commit bff3a54
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ parse_origin_deployment (RpmOstreeSysrootUpgrader *self,
self->origin = rpmostree_origin_parse_deployment (deployment, error);
if (!self->origin)
return FALSE;
rpmostree_origin_remove_transient_state (self->origin);

if (rpmostree_origin_get_unconfigured_state (self->origin) &&
!(self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED))
Expand All @@ -119,11 +120,6 @@ parse_origin_deployment (RpmOstreeSysrootUpgrader *self,
return FALSE;
}

/* A bit hacky; here we clean out the live state which is deployment specific.
* We don't expect users of the upgrader to want the live state.
*/
rpmostree_origin_set_live_state (self->origin, NULL, NULL);

return TRUE;
}

Expand Down
19 changes: 16 additions & 3 deletions src/libpriv/rpmostree-origin.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ rpmostree_origin_parse_keyfile (GKeyFile *origin,
ret->cached_overrides_remove =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

/* NOTE hack here - see https://github.com/ostreedev/ostree/pull/343 */
g_key_file_remove_key (ret->kf, "origin", "unlocked", NULL);

ret->cached_unconfigured_state = g_key_file_get_string (ret->kf, "origin", "unconfigured-state", NULL);

g_autofree char *refspec = g_key_file_get_string (ret->kf, "origin", "refspec", NULL);
Expand Down Expand Up @@ -177,6 +174,22 @@ rpmostree_origin_dup (RpmOstreeOrigin *origin)
return ret;
}

/* This is useful if the origin is meant to be used to generate a *new* deployment, as
* opposed to simply gathering information about an existing one. In such cases, there are
* some things that we do not generally want to apply to a new deployment. */
void
rpmostree_origin_remove_transient_state (RpmOstreeOrigin *origin)
{
/* first libostree-known things */
ostree_deployment_origin_remove_transient_state (origin->kf);

/* this is already covered by the above, but the below also updates the cached value */
rpmostree_origin_set_override_commit (origin, NULL, NULL);

/* then rpm-ostree specific things */
rpmostree_origin_set_live_state (origin, NULL, NULL);
}

const char *
rpmostree_origin_get_refspec (RpmOstreeOrigin *origin)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libpriv/rpmostree-origin.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ rpmostree_origin_parse_deployment (OstreeDeployment *deployment,
RpmOstreeOrigin *
rpmostree_origin_dup (RpmOstreeOrigin *origin);

void
rpmostree_origin_remove_transient_state (RpmOstreeOrigin *origin);

const char *
rpmostree_origin_get_refspec (RpmOstreeOrigin *origin);

Expand Down
18 changes: 17 additions & 1 deletion tests/vmcheck/test-misc-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,29 @@ vm_rpmostree status > status.txt
assert_not_file_has_content status.txt "Pinned: yes"
echo "ok pinning"

# trying to clean up a pinned pending deployment should be a no-op
vm_cmd ostree admin pin 0
vm_assert_status_jq ".deployments|length == 2" \
".deployments[0][\"pinned\"] == true"
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 2"
echo "ok pinned pending"

vm_build_rpm bar
vm_rpmostree install bar
vm_assert_status_jq ".deployments|length == 3"
# but that new one shouldn't be pinned
vm_assert_status_jq ".deployments[0][\"pinned\"] == false"
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 2"
echo "ok pinning not carried over"

# and now check that we can unpin and cleanup
vm_cmd ostree admin pin -u 0
vm_assert_status_jq ".deployments[0][\"pinned\"] == false"
vm_rpmostree cleanup -p
vm_assert_status_jq ".deployments|length == 1"
echo "ok pinned retained"
echo "ok unpin"

# https://github.com/ostreedev/ostree/pull/1055
vm_cmd ostree commit -b vmcheck --tree=ref=vmcheck --timestamp=\"October 25 1985\"
Expand Down

0 comments on commit bff3a54

Please sign in to comment.