From f1e9ea76bb0510fb50e34ad0a8a0b2da256f9909 Mon Sep 17 00:00:00 2001 From: Tom Wiseman Date: Tue, 31 Oct 2023 16:02:10 -0400 Subject: [PATCH] improve bash script and fix test --- .../TesAsyncBackendJobExecutionActor.scala | 36 +++++++++++++++++-- .../impl/tes/TesRuntimeAttributesSpec.scala | 4 +-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/supportedBackends/tes/src/main/scala/cromwell/backend/impl/tes/TesAsyncBackendJobExecutionActor.scala b/supportedBackends/tes/src/main/scala/cromwell/backend/impl/tes/TesAsyncBackendJobExecutionActor.scala index 7d823101e02..cdb729a3d2a 100644 --- a/supportedBackends/tes/src/main/scala/cromwell/backend/impl/tes/TesAsyncBackendJobExecutionActor.scala +++ b/supportedBackends/tes/src/main/scala/cromwell/backend/impl/tes/TesAsyncBackendJobExecutionActor.scala @@ -67,9 +67,39 @@ object TesAsyncBackendJobExecutionActor { s""" |### BEGIN ACQUIRE LOCAL SAS TOKEN ### |# Install dependencies - |apt-get -y update - |apt-get -y install curl - |apt-get -y install jq + | + |# Function to check if a command exists + |command_exists() { + | command -v "$$1" > /dev/null 2>&1 + |} + | + |# Check if curl exists; install if not + |if ! command_exists curl; then + | if command_exists apt-get; then + | apt-get -y update && apt-get -y install curl + | if [ $$? -ne 0 ]; then + | echo "Error: Failed to install curl via apt-get." + | exit 1 + | fi + | else + | echo "Error: apt-get is not available, and curl is not installed." + | exit 1 + | fi + |fi + | + |# Check if jq exists; install if not + |if ! command_exists jq; then + | if command_exists apt-get; then + | apt-get -y update && apt-get -y install jq + | if [ $$? -ne 0 ]; then + | echo "Error: Failed to install jq via apt-get." + | exit 1 + | fi + | else + | echo "Error: apt-get is not available, and jq is not installed." + | exit 1 + | fi + |fi | |# Acquire bearer token, relying on the User Assigned Managed Identity of this VM. |echo Acquiring Bearer Token using User Assigned Managed Identity... diff --git a/supportedBackends/tes/src/test/scala/cromwell/backend/impl/tes/TesRuntimeAttributesSpec.scala b/supportedBackends/tes/src/test/scala/cromwell/backend/impl/tes/TesRuntimeAttributesSpec.scala index d5e30730af9..4197f5da3d3 100644 --- a/supportedBackends/tes/src/test/scala/cromwell/backend/impl/tes/TesRuntimeAttributesSpec.scala +++ b/supportedBackends/tes/src/test/scala/cromwell/backend/impl/tes/TesRuntimeAttributesSpec.scala @@ -73,13 +73,13 @@ class TesRuntimeAttributesSpec extends AnyWordSpecLike with CromwellTimeoutSpec } "validate a valid sasEnvironmentVariable entry" in { - val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "sasEnvironmentVariable" -> WomString("THIS_IS_VALID")) + val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), TesRuntimeAttributes.LocalizedSasKey -> WomString("THIS_IS_VALID")) val expectedRuntimeAttributes = expectedDefaultsPlusUbuntuDocker.copy(localizedSasEnvVar = Some("THIS_IS_VALID")) assertSuccess(runtimeAttributes, expectedRuntimeAttributes) } "fail to validate an invalid sasEnvironmentVariable entry" in { - val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "sasEnvironmentVariable" -> WomString("THIS IS INVALID")) + val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), TesRuntimeAttributes.LocalizedSasKey -> WomString("THIS IS INVALID")) assertFailure(runtimeAttributes, "Value must be a string containing only letters, numbers, and underscores.") }