Skip to content

Commit

Permalink
fix: fail deployment when it's aborted
Browse files Browse the repository at this point in the history
Changelog: Title
Ticket: MEN-7693

Signed-off-by: Daniel Skinstad Drabitzius <[email protected]>
  • Loading branch information
danielskinstad committed Nov 11, 2024
1 parent 7efe17e commit 9703d03
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/src/mender-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ mender_api_publish_deployment_status(const char *id, mender_deployment_status_t
if (204 == status) {
/* No response expected */
ret = MENDER_OK;
} else if (409 == status) {
/* Deployment aborted */
mender_api_print_response_error(response, status);
ret = MENDER_ABORTED;
} else {
mender_api_print_response_error(response, status);
ret = MENDER_FAIL;
Expand Down
18 changes: 12 additions & 6 deletions core/src/mender-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,11 @@ mender_client_update_work_function(void) {
mender_log_info("Downloading artifact with id '%s', name '%s', uri '%s'", deployment->id, deployment->artifact_name, deployment->uri);
}
#endif
mender_client_publish_deployment_status(deployment->id, MENDER_DEPLOYMENT_STATUS_DOWNLOADING);

/* Set deployment_id */
deployment_id = deployment->id;

if (MENDER_OK == (ret = mender_download_artifact(deployment->uri, mender_client_deployment_data, &mender_update_module))) {
if ((MENDER_ABORTED != mender_client_publish_deployment_status(deployment->id, MENDER_DEPLOYMENT_STATUS_DOWNLOADING))
&& MENDER_OK == (ret = mender_download_artifact(deployment->uri, mender_client_deployment_data, &mender_update_module))) {
assert(NULL != mender_update_module);

/* Get artifact context if artifact download succeeded */
Expand Down Expand Up @@ -990,8 +989,10 @@ mender_client_update_work_function(void) {

case MENDER_UPDATE_STATE_INSTALL:
mender_log_info("Download done, installing artifact");
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_INSTALLING);
if (NULL != mender_update_module->callbacks[update_state]) {
if (MENDER_ABORTED == mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_INSTALLING)) {
ret = MENDER_FAIL;
}
if ((MENDER_OK == ret) && NULL != mender_update_module->callbacks[update_state]) {
ret = mender_update_module->callbacks[update_state](update_state, (mender_update_state_data_t)NULL);
}
if ((MENDER_OK == ret) && !mender_update_module->requires_reboot) {
Expand All @@ -1007,7 +1008,11 @@ mender_client_update_work_function(void) {
case MENDER_UPDATE_STATE_REBOOT:
assert(mender_update_module->requires_reboot);
mender_log_info("Artifact installation done, rebooting");
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_REBOOTING);
if (MENDER_ABORTED == mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_REBOOTING)) {
update_state = MENDER_UPDATE_STATE_FAILURE;
set_and_store_state(update_state);
continue;
}
if ((MENDER_OK == ret) && (NULL != mender_update_module->callbacks[update_state])) {
/* Save the next state before running the reboot callback --
* if there is an interrupt (power, crash,...) right after,
Expand Down Expand Up @@ -1052,6 +1057,7 @@ mender_client_update_work_function(void) {
ret = mender_update_module->callbacks[update_state](update_state, (mender_update_state_data_t)NULL);
}
if (MENDER_OK == ret) {
/* We don't check for MENDER_ABORTED, as it's too late if it has reached this far */
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_SUCCESS);
}
NEXT_STATE;
Expand Down
1 change: 1 addition & 0 deletions include/mender-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef enum {
MENDER_NOT_FOUND = -2, /**< Not found */
MENDER_NOT_IMPLEMENTED = -3, /**< Not implemented */
MENDER_LOOP_DETECTED = -4, /**< Loop detected */
MENDER_ABORTED = -5, /**< Aborted */
} mender_err_t;

/**
Expand Down
3 changes: 3 additions & 0 deletions platform/tls/generic/mbedtls/src/mender-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ mender_tls_init_authentication_keys(mender_err_t (*get_user_provided_keys)(char
case MENDER_LOOP_DETECTED:
assert(false && "Unexpected return value");
/* fallthrough */
case MENDER_ABORTED:
assert(false && "Unexpected return value");
/* fallthrough */
case MENDER_FAIL:
mender_log_error("Unable to get authentication keys from store");
return MENDER_FAIL;
Expand Down

0 comments on commit 9703d03

Please sign in to comment.