-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app: smarter deployment change detection #984
Changes from 3 commits
97aaf72
54ceb6f
1c52fbe
789305b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,21 +42,47 @@ rpmostree_usage_error (GOptionContext *context, | |
(void) glnx_throw (error, "usage error: %s", message); | ||
} | ||
|
||
static char* | ||
get_id_from_deployment_variant (GVariant *deployment) | ||
{ | ||
g_autoptr(GVariantDict) dict = g_variant_dict_new (deployment); | ||
g_autofree char *id; | ||
g_assert (g_variant_dict_lookup (dict, "id", "s", &id)); | ||
return g_steal_pointer (&id); | ||
} | ||
|
||
static | ||
G_DEFINE_QUARK (rpmostree-original-id, rpmostree_original_id) | ||
#define RPMOSTREE_ORIGINAL_ID rpmostree_original_id_quark() | ||
|
||
static void | ||
default_deployment_change_cb (GObject *object, | ||
GParamSpec *pspec, | ||
GVariant **value) | ||
gboolean *changed) | ||
{ | ||
g_object_get (object, pspec->name, value, NULL); | ||
GVariant *new_default_deployment; | ||
g_object_get (object, pspec->name, &new_default_deployment, NULL); | ||
g_autofree char *new_id = get_id_from_deployment_variant (new_default_deployment); | ||
|
||
const char *original_id = g_object_get_qdata (object, RPMOSTREE_ORIGINAL_ID); | ||
if (!g_str_equal (original_id, new_id)) | ||
*changed = TRUE; | ||
} | ||
|
||
void | ||
rpmostree_monitor_default_deployment_change (RPMOSTreeOS *os_proxy, | ||
GVariant **deployment) | ||
gboolean *changed) | ||
{ | ||
/* This will set the GVariant if the default deployment changes. */ | ||
g_autoptr(GVariant) default_deployment = rpmostree_os_dup_default_deployment (os_proxy); | ||
g_autofree char *original_id = get_id_from_deployment_variant (default_deployment); | ||
|
||
/* we use a quark here so original_id automatically gets freed with os_proxy (but also as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to view gobject data as a hack - it is a practical tool but the problem comes when you start using it a lot. Which we aren't at all, this would be the first. I'm OK keeping this but would be happier with a struct. Though hum I forget now...is there some reason we can't just query the deployment property before and after? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason, just wanted to make it easy for callers to use it without much prep. :) |
||
* an easy way to pass data to the cb without a struct and worrying about its lifetime) */ | ||
g_object_set_qdata_full (G_OBJECT (os_proxy), RPMOSTREE_ORIGINAL_ID, | ||
g_steal_pointer (&original_id), (GDestroyNotify)g_free); | ||
|
||
g_signal_connect (os_proxy, "notify::default-deployment", | ||
G_CALLBACK (default_deployment_change_cb), deployment); | ||
G_CALLBACK (default_deployment_change_cb), changed); | ||
} | ||
|
||
/* Print the diff between the booted and pending deployments */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,21 @@ fi | |
assert_not_file_has_content err.txt "Writing rpmdb" | ||
assert_file_has_content err.txt "File exists" | ||
echo "ok detecting file name conflicts before writing rpmdb" | ||
|
||
# check that the way we detect deployment changes is not dependent on pending-* | ||
# https://github.com/projectatomic/rpm-ostree/issues/981 | ||
vm_rpmostree cleanup -rp | ||
csum=$(vm_cmd ostree commit -b vmcheck --tree=ref=vmcheck) | ||
# restart to make daemon see the pending cheksum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
vm_cmd systemctl restart rpm-ostreed | ||
vm_assert_status_jq '.deployments[0]["pending-base-checksum"]' | ||
# hard reset to booted csum (simulates what deploy does to remote refspecs) | ||
vm_cmd ostree reset vmcheck $(vm_get_booted_csum) | ||
rc=0 | ||
vm_rpmostree deploy $(vm_get_booted_csum) > out.txt || rc=$? | ||
if [ $rc != 77 ]; then | ||
assert_not_reached "trying to re-deploy same commit didn't exit 77" | ||
fi | ||
assert_file_has_content out.txt 'No change.' | ||
vm_assert_status_jq '.deployments[0]["pending-base-checksum"]|not' | ||
echo "ok changes to deployment variant don't affect deploy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just
g_variant_lookup(deployment, "id", "&s", &id)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had it return a new string because we weren't keeping a reference to the associated
GVariant
. In the new approach, we do.