Skip to content
Snippets Groups Projects
Commit 439f5ef0 authored by Frederic Danis's avatar Frederic Danis
Browse files

Start update after download finished


Call ApplyStaticDelta method of Apertis Update Manager Dbus object to
apply ostree delta.
Send feedback to update manager based on AUM's SystemUpgradeState state
change:
- 100: update applied, will now reboot
- 200: system already up to date
- 0: unknown state, update failed

Signed-off-by: default avatarFrédéric Danis <frederic.danis@collabora.com>
parent 3a833008
No related branches found
No related tags found
1 merge request!1Initial support for Apertis hawkBit agent
......@@ -140,7 +140,7 @@ aha_hawkbit_deployment_base_class_init (AhaHawkbitDeploymentBaseClass * cls)
props);
}
void
gboolean
aha_hawkbit_deployment_base_update (AhaHawkbitDeploymentBase *self)
{
g_autoptr (SoupMessage) msg;
......@@ -162,9 +162,13 @@ aha_hawkbit_deployment_base_update (AhaHawkbitDeploymentBase *self)
status = soup_session_send_message (
aha_hawkbit_session_get_soup_session (self->session),
msg);
if (status < 200 || status > 299)
{
g_debug ("%s: status=%d message='%s'", __func__, status,
msg->response_body->data);
return FALSE;
}
g_print("=> %d\n", status);
g_print("=> %s\n", msg->response_body->data);
self->parser = json_parser_new();
json_parser_load_from_data (self->parser,
......@@ -209,6 +213,8 @@ aha_hawkbit_deployment_base_update (AhaHawkbitDeploymentBase *self)
node = json_object_get_member (obj, "href");
self->update_uri = json_node_dup_string (node);
return TRUE;
}
gchar *
......@@ -279,6 +285,9 @@ aha_hawkbit_deployment_base_send_feedback (AhaHawkbitDeploymentBase *self,
status = soup_session_send_message (
aha_hawkbit_session_get_soup_session (self->session),
msg);
g_print("=> %d\n", status);
g_print("=> %s\n", msg->response_body->data);
if (status < 200 || status > 299)
{
g_debug ("%s: status=%d message='%s'", __func__, status,
msg->response_body->data);
}
}
......@@ -37,7 +37,7 @@ G_DECLARE_FINAL_TYPE (AhaHawkbitDeploymentBase,
#define AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_REJECTED "rejected"
#define AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_RESUMED "resumed"
void
gboolean
aha_hawkbit_deployment_base_update (AhaHawkbitDeploymentBase *self);
gchar *
......
#include <stdio.h>
#include <gio/gio.h>
#include "hawkbit-session.h"
#include "hawkbit-base.h"
......@@ -8,8 +9,11 @@
#define DEFAULT_POLL_TIMEOUT 10
typedef struct {
GDBusProxy *proxy;
AhaHawkbitSession *hb_session;
AhaHawkbitBase *base;
AhaHawkbitDeploymentBase *d_base;
int poll_timeout;
int poll_id;
......@@ -30,11 +34,11 @@ download_got_chunk (SoupMessage *message,
}
static void
download_uri (AhaHawkbitSession *hb_session, const char *uri, const gchar *filename)
download_uri (UpgradeAgent *agent, const char *uri, const gchar *filename)
{
guint status;
g_autoptr (SoupMessage) msg = aha_hawkbit_session_create_message_for_uri (
hb_session,
agent->hb_session,
SOUP_METHOD_GET,
uri);
g_autoptr (GFile) f = g_file_new_for_path (filename);
......@@ -51,7 +55,7 @@ download_uri (AhaHawkbitSession *hb_session, const char *uri, const gchar *filen
out);
status = soup_session_send_message (
aha_hawkbit_session_get_soup_session (hb_session),
aha_hawkbit_session_get_soup_session (agent->hb_session),
msg);
if (status < 200 || status > 299)
{
......@@ -61,37 +65,138 @@ download_uri (AhaHawkbitSession *hb_session, const char *uri, const gchar *filen
g_output_stream_close (out, NULL, NULL);
}
static void aumCB(
GDBusProxy * proxy,
GVariant * changed_properties,
GStrv invalidated_properties,
gpointer user_data)
{
UpgradeAgent *agent = (UpgradeAgent *)user_data;
(void) invalidated_properties;
if (agent->d_base == NULL)
{
// No update in progress.
return;
}
if (g_variant_n_children(changed_properties) < 1)
{
// No changed properties, only invalidated ones which we don't care about.
return;
}
/* Retrieve the org.apertis.ApertisUpdateManager property from the
changed_properties dictionary parameter (index 1).
*/
GVariant * const variant =
g_variant_lookup_value(changed_properties, "SystemUpgradeState", NULL);
if (variant != NULL)
{
int state;
g_variant_get(variant, "u", &state);
g_variant_unref(variant);
g_debug ("SystemUpgradeState %d\n", state);
if (state == 0)
{
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_FAILURE,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_CLOSED,
NULL);
g_object_unref(agent->d_base);
agent->d_base = NULL;
}
else if (state == 100)
{
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_NONE,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_PROCEEDING,
"Rebooting");
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_SUCCESS,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_CLOSED,
NULL);
g_object_unref(agent->d_base);
agent->d_base = NULL;
}
else if (state == 200)
{
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_NONE,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_PROCEEDING,
"System already up to date");
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_SUCCESS,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_CLOSED,
NULL);
g_object_unref(agent->d_base);
agent->d_base = NULL;
}
}
}
static gboolean
static_delta_upgrade(UpgradeAgent *agent, const gchar *filename)
{
g_autoptr(GError) error = NULL;
g_dbus_proxy_call_sync (agent->proxy, "ApplyStaticDelta",
g_variant_new ("(s)", filename),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
g_assert_no_error (error);
return TRUE;
}
static void
deployment_base_mgmt(UpgradeAgent *agent, gchar *uri)
{
AhaHawkbitDeploymentBase *d_base = g_object_new (AHA_TYPE_HAWKBIT_DEPLOYMENT_BASE,
"session", agent->hb_session,
"uri", uri,
NULL);
g_autofree gchar *u_uri = NULL;
g_autofree gchar *u_filename = NULL;
aha_hawkbit_deployment_base_update (d_base);
u_uri = aha_hawkbit_deployment_base_get_update_uri (d_base);
u_filename = aha_hawkbit_deployment_base_get_update_filename (d_base);
if (agent->d_base != NULL)
{
g_message ("Update already in progress");
return;
}
agent->d_base = g_object_new (AHA_TYPE_HAWKBIT_DEPLOYMENT_BASE,
"session", agent->hb_session,
"uri", uri, NULL);
if (aha_hawkbit_deployment_base_update (agent->d_base) == FALSE)
goto end;
u_uri = aha_hawkbit_deployment_base_get_update_uri (agent->d_base);
u_filename = g_strdup_printf("/tmp/%s",
aha_hawkbit_deployment_base_get_update_filename (agent->d_base));
if (u_uri == NULL)
goto end;
aha_hawkbit_deployment_base_send_feedback(d_base,
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_NONE,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_PROCEEDING,
"Downloading");
download_uri (agent->hb_session, u_uri, u_filename);
download_uri (agent, u_uri, u_filename);
// TODO: Check md5sum
aha_hawkbit_deployment_base_send_feedback(agent->d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_NONE,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_PROCEEDING,
"Upgrading");
aha_hawkbit_deployment_base_send_feedback(d_base,
AHA_DEPLOYMENT_BASE_FEEDBACK_FINISHED_SUCCESS,
AHA_DEPLOYMENT_BASE_FEEDBACK_EXECUTION_CLOSED,
NULL);
static_delta_upgrade (agent, u_filename);
return;
end:
g_object_unref(d_base);
g_object_unref(agent->d_base);
agent->d_base = NULL;
}
static void
......@@ -174,6 +279,8 @@ main(int argc, char **argv) {
{
// Fall back to a default value.
tenant = g_strdup ("DEFAULT");
g_error_free(error);
error = NULL;
}
g_autofree gchar *controller_id = g_key_file_get_string (key_file, "server",
......@@ -199,6 +306,17 @@ main(int argc, char **argv) {
return 1;
}
// Create AUM DBus proxy
agent->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.apertis.ApertisUpdateManager",
"/",
"org.apertis.ApertisUpdateManager",
NULL, &error);
g_assert_no_error (error);
g_signal_connect(agent->proxy, "g-properties-changed", G_CALLBACK(aumCB), agent);
agent->hb_session = g_object_new (AHA_TYPE_HAWKBIT_SESSION,
"base-uri", base_uri,
"tenant", tenant,
......@@ -215,5 +333,7 @@ main(int argc, char **argv) {
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_object_unref (agent->proxy);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment