From 984c76e9320cee85806721048a448a0422d70fc1 Mon Sep 17 00:00:00 2001 From: Marcus Robinson Date: Tue, 17 Oct 2023 16:58:45 +0100 Subject: [PATCH] Update porter version and on error getting porter outputs return dict (#3745) * Update porter version and on error getting porter outputs return dict * Update handling of failures. --- .devcontainer/Dockerfile | 2 +- CHANGELOG.md | 1 + resource_processor/_version.py | 2 +- resource_processor/vmss_porter/Dockerfile | 2 +- resource_processor/vmss_porter/runner.py | 33 ++++++++++++++--------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index e7fa47e17..7c083e9c8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 72e08b6da..96d2231b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/resource_processor/_version.py b/resource_processor/_version.py index 7bbb2ef5c..f6104e0c2 100644 --- a/resource_processor/_version.py +++ b/resource_processor/_version.py @@ -1 +1 @@ -__version__ = "0.6.5" +__version__ = "0.6.7" diff --git a/resource_processor/vmss_porter/Dockerfile b/resource_processor/vmss_porter/Dockerfile index d77c077d0..1724e5c1e 100644 --- a/resource_processor/vmss_porter/Dockerfile +++ b/resource_processor/vmss_porter/Dockerfile @@ -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 diff --git a/resource_processor/vmss_porter/runner.py b/resource_processor/vmss_porter/runner.py index 56989a0e8..118eafe8d 100644 --- a/resource_processor/vmss_porter/runner.py +++ b/resource_processor/vmss_porter/runner.py @@ -165,18 +165,19 @@ 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] @@ -184,21 +185,27 @@ async def invoke_porter_action(msg_body: dict, sb_client: ServiceBusClient, mess 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." - 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 + 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}") + + # 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): @@ -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: