From 5eb939718c052a44b542c5d6a6afcdcf7dc28d62 Mon Sep 17 00:00:00 2001 From: Jordi Deu-Pons Date: Fri, 19 May 2023 17:41:39 +0200 Subject: [PATCH] Fix invalid machine type setting when no valid machine type is found (#3961) Signed-off-by: Jordi Deu-Pons --- .../batch/GoogleBatchTaskHandler.groovy | 3 -- .../batch/GoogleBatchTaskHandlerTest.groovy | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy b/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy index bb01f29f92..a76a79c322 100644 --- a/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy +++ b/plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchTaskHandler.groovy @@ -228,9 +228,6 @@ class GoogleBatchTaskHandler extends TaskHandler implements FusionAwareTask { if( executor.config.cpuPlatform ) instancePolicy.setMinCpuPlatform( executor.config.cpuPlatform ) - if( task.config.getMachineType() ) - instancePolicy.setMachineType( task.config.getMachineType() ) - machineInfo = findBestMachineType(task.config) if( machineInfo ) instancePolicy.setMachineType(machineInfo.type) diff --git a/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy b/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy index 9c434a3195..d3b47e87c2 100644 --- a/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy +++ b/plugins/nf-google/src/test/nextflow/cloud/google/batch/GoogleBatchTaskHandlerTest.groovy @@ -22,6 +22,8 @@ import com.google.cloud.batch.v1.Volume import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem import nextflow.cloud.google.batch.client.BatchClient import nextflow.cloud.google.batch.client.BatchConfig +import nextflow.cloud.types.CloudMachineInfo +import nextflow.cloud.types.PriceModel import nextflow.executor.Executor import nextflow.executor.res.AcceleratorResource import nextflow.processor.TaskBean @@ -159,7 +161,7 @@ class GoogleBatchTaskHandlerTest extends Specification { def req = handler.newSubmitRequest(task, launcher) then: handler.fusionEnabled() >> false - handler.findBestMachineType(_) >> null + handler.findBestMachineType(_) >> new CloudMachineInfo(type: MACHINE_TYPE, zone: "location", priceModel: PriceModel.spot) and: def taskGroup = req.getTaskGroups(0) @@ -293,4 +295,37 @@ class GoogleBatchTaskHandlerTest extends Specification { and: taskGroup.getTaskSpec().getVolumesList().size()==0 } + + def 'should not set wildcard expressions as machine type'() { + given: + def WORK_DIR = CloudStorageFileSystem.forBucket('foo').getPath('/scratch') + def CONTAINER_IMAGE = 'debian:latest' + def exec = Mock(GoogleBatchExecutor) { + getConfig() >> Mock(BatchConfig) + } + def bean = new TaskBean(workDir: WORK_DIR, inputFiles: [:]) + def task = Mock(TaskRun) { + toTaskBean() >> bean + getHashLog() >> 'abcd1234' + getWorkDir() >> WORK_DIR + getContainer() >> CONTAINER_IMAGE + getConfig() >> Mock(TaskConfig) { + getCpus() >> 2 + getResourceLabels() >> [:] + getMachineType() >> "n1-*,n2-*" + } + } + def handler = Spy(new GoogleBatchTaskHandler(task, exec)) + def env = [FUSION_WORK: '/xyz'] + def launcher = new GoogleBatchLauncherSpecMock('bash .command.run', [], [], env) + + when: + def req = handler.newSubmitRequest(task, launcher) + then: + handler.fusionEnabled() >> false + handler.findBestMachineType(_) >> null + and: + req.getAllocationPolicy().getInstances(0).policy.getMachineType() == "" + + } }