Skip to content
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

Allow disabling close action after sucessfull update #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ low_speed_rate = 0
# reboot after a successful update
post_update_reboot = false


# close(finish) update action after a successful update
post_update_close = true

# debug, info, message, critical, error, fatal
log_level = message

Expand Down
5 changes: 5 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ Optional options:
manager and without terminating any processes or unmounting any file systems.
This may result in data loss.

``post_update_close=<boolean>``
Whether to close/finish update action after a successful update.
Disabling allows an external program to determine if update is finish.
Defaults to ``true``.

``log_level=<level>``
Log level to print, where ``level`` is a string of

Expand Down
1 change: 1 addition & 0 deletions include/config-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct Config_ {
gboolean ssl; /**< use https or http */
gboolean ssl_verify; /**< verify https certificate */
gboolean post_update_reboot; /**< reboot system after successful update */
gboolean post_update_close; /**< close(finish) update action after a successful update */
gboolean resume_downloads; /**< resume downloads or not */
gboolean stream_bundle; /**< streaming installation or not */
gchar* auth_token; /**< hawkBit target security token */
Expand Down
4 changes: 4 additions & 0 deletions src/config-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const gint DEFAULT_RETRY_WAIT = 5 * 60; // 5 min.
static const gboolean DEFAULT_SSL = TRUE;
static const gboolean DEFAULT_SSL_VERIFY = TRUE;
static const gboolean DEFAULT_REBOOT = FALSE;
static const gboolean DEFAULT_CLOSE = TRUE;
static const gchar* DEFAULT_LOG_LEVEL = "message";

/**
Expand Down Expand Up @@ -309,6 +310,9 @@ Config* load_config_file(const gchar *config_file, GError **error)

if (!get_key_bool(ini_file, "client", "post_update_reboot", &config->post_update_reboot, DEFAULT_REBOOT, error))
return NULL;
if (!get_key_bool(ini_file, "client", "post_update_close",
&config->post_update_close, DEFAULT_CLOSE, error))
return NULL;

if (config->timeout > 0 && config->connect_timeout > 0 &&
config->timeout < config->connect_timeout) {
Expand Down
27 changes: 16 additions & 11 deletions src/hawkbit-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,17 +798,22 @@ gboolean install_complete_cb(gpointer ptr)

g_mutex_lock(&active_action->mutex);

active_action->state = result->install_success ? ACTION_STATE_SUCCESS : ACTION_STATE_ERROR;
feedback_url = build_api_url("deploymentBase/%s/feedback", active_action->id);
res = feedback(
feedback_url, active_action->id,
result->install_success ? "Software bundle installed successfully."
: "Failed to install software bundle.",
result->install_success ? "success" : "failure",
"closed", &error);

if (!res)
g_warning("%s", error->message);
if (hawkbit_config->post_update_close || !result->install_success) {
active_action->state = result->install_success ? ACTION_STATE_SUCCESS : ACTION_STATE_ERROR;
feedback_url = build_api_url("deploymentBase/%s/feedback", active_action->id);
res = feedback(
feedback_url, active_action->id,
result->install_success ? "Software bundle installed successfully."
: "Failed to install software bundle.",
result->install_success ? "success" : "failure",
"closed", &error);

if (!res)
g_warning("%s", error->message);
}
else {
g_message("%s", "Software bundle installed successfully.");
}

process_deployment_cleanup();
g_mutex_unlock(&active_action->mutex);
Expand Down
28 changes: 28 additions & 0 deletions test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ def test_install_success(hawkbit, install_config, bundle_assigned, rauc_dbus_ins
status = hawkbit.get_action_status()
assert status[0]['type'] == 'finished'

@pytest.mark.parametrize('mode', ('download', 'streaming'))
def test_install_success_without_close(hawkbit, adjust_config, bundle_assigned, rauc_dbus_install_success, mode):
"""
Assign bundle to target and test successful download and installation. Make sure installation
result is received correctly by hawkBit.
"""

if mode == "streaming":
config = adjust_config(
{'client': {'stream_bundle': 'true', 'post_update_close': "false"}},
remove={'client': 'bundle_download_location'},
)
else:
config = adjust_config({'client': {'post_update_close': "false"}})
out, err, exitcode = run(f'rauc-hawkbit-updater -c "{config}" -r')

assert 'New software ready for download' in out

if mode == 'download':
assert 'Download complete' in out

assert 'Software bundle installed successfully.' in out
assert err == ''
assert exitcode == 0

status = hawkbit.get_action_status()
assert status[0]['type'] == 'running'

@pytest.mark.parametrize('mode', ('download', 'streaming'))
def test_install_failure(hawkbit, install_config, bundle_assigned, rauc_dbus_install_failure, mode):
"""
Expand Down