Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WX-1557 Add more tests to the GCP Batch backend #7394

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import _root_.wdl.draft2.model._
import akka.actor.{ActorRef, Props}
import akka.testkit.{ImplicitSender, TestActorRef, TestDuration, TestProbe}
import cats.data.NonEmptyList
import cloud.nio.impl.drs.DrsCloudNioFileProvider.DrsReadInterpreter
import cloud.nio.impl.drs.{DrsCloudNioFileSystemProvider, GoogleOauthDrsCredentials}
import com.google.cloud.NoCredentials
import com.google.cloud.batch.v1.{Job, JobName}
import com.typesafe.config.{Config, ConfigFactory}
import common.collections.EnhancedCollections._
import cromwell.backend.BackendJobExecutionActor.BackendJobExecutionResponse
import cromwell.backend._
Expand Down Expand Up @@ -56,6 +59,7 @@ import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.language.postfixOps
import common.mock.MockSugar
import cromwell.filesystems.drs.DrsPathBuilder
import org.mockito.Mockito._

class GcpBatchAsyncBackendJobExecutionActorSpec
Expand Down Expand Up @@ -396,6 +400,55 @@ class GcpBatchAsyncBackendJobExecutionActorSpec
GcpBatchAsyncBackendJobExecutionActor.groupParametersByGcsBucket(inputs) shouldEqual expected
}

it should "generate a CSV manifest for DRS inputs, ignoring non-DRS inputs" in {
def makeDrsPathBuilder: DrsPathBuilder = {
val drsResolverConfig: Config = ConfigFactory.parseString(
"""resolver {
| url = "http://drshub-url"
|}
|""".stripMargin
)

val fakeCredentials = NoCredentials.getInstance

val drsReadInterpreter: DrsReadInterpreter = (_, _) =>
throw new UnsupportedOperationException(
"PipelinesApiAsyncBackendJobExecutionActorSpec doesn't need to use drs read interpreter."
)

DrsPathBuilder(
new DrsCloudNioFileSystemProvider(drsResolverConfig,
GoogleOauthDrsCredentials(fakeCredentials, 1.minutes),
drsReadInterpreter
),
None
)
}

val mount = GcpBatchWorkingDisk(DiskType.LOCAL, 1)

def makeDrsInput(name: String, drsUri: String, containerPath: String): GcpBatchFileInput = {
val drsPath = makeDrsPathBuilder.build(drsUri).get
val containerRelativePath = DefaultPathBuilder.get(containerPath)
GcpBatchFileInput(name, drsPath, containerRelativePath, mount)
}

val nonDrsInput: GcpBatchFileInput = GcpBatchFileInput("nnn",
DefaultPathBuilder.get("/local/nnn.bai"),
DefaultPathBuilder.get("/path/to/nnn.bai"),
mount
)

val inputs = List(
makeDrsInput("aaa", "drs://drs.example.org/aaa", "path/to/aaa.bai"),
nonDrsInput,
makeDrsInput("bbb", "drs://drs.example.org/bbb", "path/to/bbb.bai")
)

GcpBatchAsyncBackendJobExecutionActor.generateDrsLocalizerManifest(inputs) shouldEqual
"drs://drs.example.org/aaa,/mnt/disks/cromwell_root/path/to/aaa.bai\r\ndrs://drs.example.org/bbb,/mnt/disks/cromwell_root/path/to/bbb.bai\r\n"
}

it should "send proper value for \"number of reference files used gauge\" metric, or don't send anything if reference disks feature is disabled" in {

val expectedInput1 = GcpBatchFileInput(name = "testfile1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ class GcpBatchConfigurationSpec
).root shouldBe "gs://my-cromwell-workflows-bucket"
}

// it should "have correct docker" in {
// val dockerConf = new GcpBatchConfiguration(BackendConfigurationDescriptor(backendConfig, globalConfig), googleConfiguration, batchAttributes).dockerCredentials
// dockerConf shouldBe defined
// dockerConf.get.token shouldBe "dockerToken"
// }
it should "have correct docker" in {
val dockerConf = new GcpBatchConfiguration(
BackendConfigurationDescriptor(backendConfig, globalConfig),
googleConfiguration,
batchAttributes
).dockerCredentials

dockerConf shouldBe defined
dockerConf.get.token shouldBe "dockerToken"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package cromwell.backend.google.batch.models

import cats.data.NonEmptyList
import cromwell.backend.RuntimeAttributeDefinition
import cromwell.backend.google.batch.io.{DiskType, GcpBatchAttachedDisk, GcpBatchWorkingDisk}
import cromwell.backend.google.batch.models.GcpBatchTestConfig._
import cromwell.backend.validation.ContinueOnReturnCodeSet
//import cromwell.backend.google.batch.io.{DiskType, GcpBatchAttachedDisk}
import cromwell.backend.google.batch.io.{DiskType, GcpBatchWorkingDisk}
import cromwell.core.WorkflowOptions
import eu.timepit.refined.refineMV
import org.scalatest.TestSuite
Expand Down Expand Up @@ -48,9 +47,8 @@ final class GcpBatchRuntimeAttributesSpec
}

"fail to validate an invalid Docker entry" in {
pending
val runtimeAttributes = Map("docker" -> WomInteger(1))
assertBatchRuntimeAttributesFailedCreation(runtimeAttributes, "Expecting docker runtime attribute to be String")
assertBatchRuntimeAttributesFailedCreation(runtimeAttributes, "Expecting docker runtime attribute to be a String")
}

"validate a valid failOnStderr entry" in {
Expand Down Expand Up @@ -152,21 +150,31 @@ final class GcpBatchRuntimeAttributesSpec
)
}

// "validate a valid disks entry" in {
// val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "disks" -> WomString("local-disk 20 SSD"))
// val expectedRuntimeAttributes = expectedDefaults.copy(disks = Seq(GcpBatchAttachedDisk.parse("local-disk 20 SSD").get))
// assertBatchRuntimeAttributesSuccessfulCreation(runtimeAttributes, expectedRuntimeAttributes)
// }

// "fail to validate an invalid disks entry" in {
// val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "disks" -> WomInteger(10))
// assertBatchRuntimeAttributesFailedCreation(runtimeAttributes, "Expecting disks runtime attribute to be a comma separated String or Array[String]")
// }

// "fail to validate a valid disks array entry" in {
// val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "disks" -> WomArray(WomArrayType(WomStringType), List(WomString("blah"), WomString("blah blah"))))
// assertBatchRuntimeAttributesFailedCreation(runtimeAttributes, "Disk strings should be of the format 'local-disk SIZE TYPE' or '/mount/point SIZE TYPE'")
// }
"validate a valid disks entry" in {
val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "disks" -> WomString("local-disk 20 SSD"))
val expectedRuntimeAttributes =
expectedDefaults.copy(disks = Seq(GcpBatchAttachedDisk.parse("local-disk 20 SSD").get))
assertBatchRuntimeAttributesSuccessfulCreation(runtimeAttributes, expectedRuntimeAttributes)
}

"fail to validate an invalid disks entry" in {
val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "disks" -> WomInteger(10))
assertBatchRuntimeAttributesFailedCreation(
runtimeAttributes,
"Expecting disks runtime attribute to be a comma separated String or Array[String]"
)
}

"fail to validate a valid disks array entry" in {
val runtimeAttributes =
Map("docker" -> WomString("ubuntu:latest"),
"disks" -> WomArray(WomArrayType(WomStringType), List(WomString("blah"), WomString("blah blah")))
)
assertBatchRuntimeAttributesFailedCreation(
runtimeAttributes,
"Disk strings should be of the format 'local-disk SIZE TYPE' or '/mount/point SIZE TYPE'"
)
}

"validate a valid memory entry" in {
val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest"), "memory" -> WomString("1 GB"))
Expand Down
Loading