Skip to content

Commit

Permalink
Update porter version and on error getting porter outputs return dict (
Browse files Browse the repository at this point in the history
…#3745)

* Update porter version and on error getting porter outputs return dict

* Update handling of failures.
  • Loading branch information
marrobi authored Oct 17, 2023
1 parent a7436dd commit 984c76e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RUN if [ "${INTERACTIVE}" = "true" ]; then \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* ; fi

ARG PORTER_HOME_V1=/home/$USERNAME/.porter/
ARG PORTER_VERSION=v1.0.11
ARG PORTER_VERSION=v1.0.15
ARG PORTER_TERRAFORM_MIXIN_VERSION=v1.0.2
ARG PORTER_AZ_MIXIN_VERSION=v1.0.1
ARG PORTER_AZURE_PLUGIN_VERSION=v1.2.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FEATURES:
ENHANCEMENTS:

BUG FIXES:
* Upgrade porter version to v1.0.15 and on error getting porter outputs return dict ([#3744](https://github.com/microsoft/AzureTRE/issues/3744))
* Fix notifications displaying workspace name rather than actual resource ([#3746](https://github.com/microsoft/AzureTRE/issues/3746))

COMPONENTS:
Expand Down
2 changes: 1 addition & 1 deletion resource_processor/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.5"
__version__ = "0.6.7"
2 changes: 1 addition & 1 deletion resource_processor/vmss_porter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ENV PORTER_HOME_V0 ${PORTER_HOME}
# can't be in a non default path
# ARG PORTER_HOME_V1=/home/$USERNAME/.porter-v1/
ARG PORTER_HOME_V1=/root/.porter/
ARG PORTER_VERSION=v1.0.11
ARG PORTER_VERSION=v1.0.15
ARG PORTER_TERRAFORM_MIXIN_VERSION=v1.0.2
ARG PORTER_AZ_MIXIN_VERSION=v1.0.1
ARG PORTER_AZURE_PLUGIN_VERSION=v1.2.0
Expand Down
33 changes: 20 additions & 13 deletions resource_processor/vmss_porter/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +165,47 @@ async def invoke_porter_action(msg_body: dict, sb_client: ServiceBusClient, mess
message_logger_adapter.debug("Starting to run porter execution command...")
returncode, _, err = await run_porter(porter_command, message_logger_adapter, config)
message_logger_adapter.debug("Finished running porter execution command.")
action_completed_without_error = True

# Handle command output
if returncode != 0:
error_message = "Error message: " + " ".join(err.split('\n')) + "; Command executed: " + " ".join(porter_command)
action_completed_without_error = False

pass_despite_error = False
if "uninstall" == action and "could not find installation" in err:
message_logger_adapter.warning("The installation doesn't exist. Treating as a successful action to allow the flow to proceed.")
pass_despite_error = True
action_completed_without_error = True
error_message = f"A success despite of underlying error. {error_message}"

if pass_despite_error:
if action_completed_without_error:
status_for_sb_message = statuses.pass_status_string_for[action]
else:
status_for_sb_message = statuses.failed_status_string_for[action]

resource_request_message = service_bus_message_generator(msg_body, status_for_sb_message, error_message)

# Post message on sb queue to notify receivers of action failure
await sb_sender.send_messages(ServiceBusMessage(body=resource_request_message, correlation_id=msg_body["id"], session_id=msg_body["operationId"]))
message_logger_adapter.info(f"{installation_id}: Porter action failed with error = {error_message}")
return pass_despite_error

else:
# Get the outputs
# TODO: decide if this should "fail" the deployment
_, outputs = await get_porter_outputs(msg_body, message_logger_adapter, config)
get_porter_outputs_successful, outputs = await get_porter_outputs(msg_body, message_logger_adapter, config)

success_message = f"{action} action completed successfully."
resource_request_message = service_bus_message_generator(msg_body, statuses.pass_status_string_for[action], success_message, outputs)
if get_porter_outputs_successful:
status_for_sb_message = statuses.pass_status_string_for[action]
status_message = f"{action} action completed successfully."
else:
action_completed_without_error = False
status_for_sb_message = statuses.failed_status_string_for[action]
status_message = f"{action} action completed successfully, but failed to get outputs."

resource_request_message = service_bus_message_generator(msg_body, status_for_sb_message, status_message, outputs)

await sb_sender.send_messages(ServiceBusMessage(body=resource_request_message, correlation_id=msg_body["id"], session_id=msg_body["operationId"]))
message_logger_adapter.info(f"Sent status message for {installation_id}: {status_for_sb_message}")

await sb_sender.send_messages(ServiceBusMessage(body=resource_request_message, correlation_id=msg_body["id"], session_id=msg_body["operationId"]))
message_logger_adapter.info(f"Sent status message for {installation_id}: {success_message}")
return True
# return true as want to continue processing the message
return action_completed_without_error


async def get_porter_outputs(msg_body: dict, message_logger_adapter: logging.LoggerAdapter, config: dict):
Expand All @@ -213,7 +220,7 @@ async def get_porter_outputs(msg_body: dict, message_logger_adapter: logging.Log
if returncode != 0:
error_message = "Error context message = " + " ".join(err.split('\n'))
message_logger_adapter.info(f"{get_installation_id(msg_body)}: Failed to get outputs with error = {error_message}")
return False, ""
return False, {}
else:
outputs_json = {}
try:
Expand Down

0 comments on commit 984c76e

Please sign in to comment.