Skip to content

Commit b1b2be2

Browse files
committed
feat: allow disabling closing action after a successful update
1 parent 76f5a1d commit b1b2be2

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

config.conf.example

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ low_speed_rate = 0
4444
# reboot after a successful update
4545
post_update_reboot = false
4646

47+
48+
# close(finish) update action after a successful update
49+
post_update_close = true
50+
4751
# debug, info, message, critical, error, fatal
4852
log_level = message
4953

docs/reference.rst

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ Optional options:
140140
manager and without terminating any processes or unmounting any file systems.
141141
This may result in data loss.
142142

143+
``post_update_close=<boolean>``
144+
Whether to close/finish update action after a successful update.
145+
Disabling allows an external program to determine if update is finish.
146+
Defaults to ``true``.
147+
143148
``log_level=<level>``
144149
Log level to print, where ``level`` is a string of
145150

include/config-file.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef struct Config_ {
1616
gboolean ssl; /**< use https or http */
1717
gboolean ssl_verify; /**< verify https certificate */
1818
gboolean post_update_reboot; /**< reboot system after successful update */
19+
gboolean post_update_close; /**< close(finish) update action after a successful update */
1920
gboolean resume_downloads; /**< resume downloads or not */
2021
gboolean stream_bundle; /**< streaming installation or not */
2122
gchar* auth_token; /**< hawkBit target security token */

src/config-file.c

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static const gint DEFAULT_RETRY_WAIT = 5 * 60; // 5 min.
1818
static const gboolean DEFAULT_SSL = TRUE;
1919
static const gboolean DEFAULT_SSL_VERIFY = TRUE;
2020
static const gboolean DEFAULT_REBOOT = FALSE;
21+
static const gboolean DEFAULT_CLOSE = TRUE;
2122
static const gchar* DEFAULT_LOG_LEVEL = "message";
2223

2324
/**
@@ -309,6 +310,9 @@ Config* load_config_file(const gchar *config_file, GError **error)
309310

310311
if (!get_key_bool(ini_file, "client", "post_update_reboot", &config->post_update_reboot, DEFAULT_REBOOT, error))
311312
return NULL;
313+
if (!get_key_bool(ini_file, "client", "post_update_close",
314+
&config->post_update_close, DEFAULT_CLOSE, error))
315+
return NULL;
312316

313317
if (config->timeout > 0 && config->connect_timeout > 0 &&
314318
config->timeout < config->connect_timeout) {

src/hawkbit-client.c

+16-11
Original file line numberDiff line numberDiff line change
@@ -798,17 +798,22 @@ gboolean install_complete_cb(gpointer ptr)
798798

799799
g_mutex_lock(&active_action->mutex);
800800

801-
active_action->state = result->install_success ? ACTION_STATE_SUCCESS : ACTION_STATE_ERROR;
802-
feedback_url = build_api_url("deploymentBase/%s/feedback", active_action->id);
803-
res = feedback(
804-
feedback_url, active_action->id,
805-
result->install_success ? "Software bundle installed successfully."
806-
: "Failed to install software bundle.",
807-
result->install_success ? "success" : "failure",
808-
"closed", &error);
809-
810-
if (!res)
811-
g_warning("%s", error->message);
801+
if (hawkbit_config->post_update_close || !result->install_success) {
802+
active_action->state = result->install_success ? ACTION_STATE_SUCCESS : ACTION_STATE_ERROR;
803+
feedback_url = build_api_url("deploymentBase/%s/feedback", active_action->id);
804+
res = feedback(
805+
feedback_url, active_action->id,
806+
result->install_success ? "Software bundle installed successfully."
807+
: "Failed to install software bundle.",
808+
result->install_success ? "success" : "failure",
809+
"closed", &error);
810+
811+
if (!res)
812+
g_warning("%s", error->message);
813+
}
814+
else {
815+
g_message("%s", "Software bundle installed successfully.");
816+
}
812817

813818
process_deployment_cleanup();
814819
g_mutex_unlock(&active_action->mutex);

test/test_install.py

+28
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ def test_install_success(hawkbit, install_config, bundle_assigned, rauc_dbus_ins
6969
status = hawkbit.get_action_status()
7070
assert status[0]['type'] == 'finished'
7171

72+
@pytest.mark.parametrize('mode', ('download', 'streaming'))
73+
def test_install_success_without_close(hawkbit, adjust_config, bundle_assigned, rauc_dbus_install_success, mode):
74+
"""
75+
Assign bundle to target and test successful download and installation. Make sure installation
76+
result is received correctly by hawkBit.
77+
"""
78+
79+
if mode == "streaming":
80+
config = adjust_config(
81+
{'client': {'stream_bundle': 'true', 'post_update_close': "false"}},
82+
remove={'client': 'bundle_download_location'},
83+
)
84+
else:
85+
config = adjust_config({'client': {'post_update_close': "false"}})
86+
out, err, exitcode = run(f'rauc-hawkbit-updater -c "{config}" -r')
87+
88+
assert 'New software ready for download' in out
89+
90+
if mode == 'download':
91+
assert 'Download complete' in out
92+
93+
assert 'Software bundle installed successfully.' in out
94+
assert err == ''
95+
assert exitcode == 0
96+
97+
status = hawkbit.get_action_status()
98+
assert status[0]['type'] == 'running'
99+
72100
@pytest.mark.parametrize('mode', ('download', 'streaming'))
73101
def test_install_failure(hawkbit, install_config, bundle_assigned, rauc_dbus_install_failure, mode):
74102
"""

0 commit comments

Comments
 (0)