From a3005f3dab855dc151d00084df4f0eeb3a07700e Mon Sep 17 00:00:00 2001 From: aravindmd Date: Mon, 10 Jun 2019 09:38:58 -0700 Subject: [PATCH] =?UTF-8?q?fix(findImage)=20:=20Fix=20child=20deploy=20to?= =?UTF-8?q?=20use=20correct=20find=20image=20when=20clou=E2=80=A6=20(#2960?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(findImage) : Fix child deploy to use correct find image when cloud providers differ * fixup * adding tests --- .../kato/tasks/DeploymentDetailsAware.groovy | 13 +++- .../kato/tasks/CreateDeployTaskSpec.groovy | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/kato/tasks/DeploymentDetailsAware.groovy b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/kato/tasks/DeploymentDetailsAware.groovy index 93c0e97144..3b321b9bc6 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/kato/tasks/DeploymentDetailsAware.groovy +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/kato/tasks/DeploymentDetailsAware.groovy @@ -81,10 +81,21 @@ trait DeploymentDetailsAware { } } + boolean isCloudProviderEqual(Stage stage, Stage execution){ + if(execution.context.cloudProvider!=null) { + return execution.context.cloudProvider == stage.context.cloudProvider + } + return true + } + List getAncestors(Stage stage, Execution execution) { if (stage?.requisiteStageRefIds) { def previousStages = execution.stages.findAll { - it.refId in stage.requisiteStageRefIds + // Include cloudProvider check to avoid confusion with multi-provider, + // in some cases ancestors can be one of any multi-provider + // Eg parent->aws and child->titus + it.refId in stage.requisiteStageRefIds && isCloudProviderEqual(stage,it) + } def syntheticStages = execution.stages.findAll { it.parentStageId in previousStages*.id diff --git a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/kato/tasks/CreateDeployTaskSpec.groovy b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/kato/tasks/CreateDeployTaskSpec.groovy index ea27e124e0..cdce1f6735 100644 --- a/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/kato/tasks/CreateDeployTaskSpec.groovy +++ b/orca-clouddriver/src/test/groovy/com/netflix/spinnaker/orca/kato/tasks/CreateDeployTaskSpec.groovy @@ -356,4 +356,69 @@ class CreateDeployTaskSpec extends Specification { amiName = "ami-name-from-bake" } + def "find the image from stage matching the cloud provider"() { + given: + stage.context.amiName = null + stage.context.imageId = null + def operations = [] + task.kato = Stub(KatoService) { + requestOperations(*_) >> { + operations.addAll(it[1].flatten()) + Observable.from(taskId) + } + } + + and: + def findImage1 = new Stage(stage.execution, "findImage") + findImage1.id = UUID.randomUUID() + findImage1.refId = "1a" + stage.execution.stages << findImage1 + + def findImageSynthetic1 = new Stage(stage.execution, "findImage", [ + ami: "ami-name-from-findimage", + region: deployRegion, + cloudProvider: "titus", + selectionStrategy:"LARGEST", + imageId:"docker" + ]) + findImageSynthetic1.id = UUID.randomUUID() + findImageSynthetic1.parentStageId = findImage1.id + stage.execution.stages << findImageSynthetic1 + + def findImage2 = new Stage(stage.execution, "findImage") + findImage2.id = UUID.randomUUID() + findImage2.refId = "2a" + stage.execution.stages << findImage2 + + + def findImageSynthetic2 = new Stage(stage.execution, "findImage", [ + ami: "different-image", + region: deployRegion, + cloudProvider: "aws", + selectionStrategy:"LARGEST", + imageId:"ami-name-from-findimage" + ]) + findImageSynthetic2.id = UUID.randomUUID() + findImageSynthetic2.parentStageId = findImage2.id + stage.execution.stages << findImageSynthetic2 + stage.context.cloudProvider = cloudProvider + + and: + findImage2.requisiteStageRefIds = [findImage1.refId] + stage.requisiteStageRefIds = [findImage2.refId] + + when: + task.execute(stage) + + then: + operations.find { + it.containsKey("createServerGroup") + }.createServerGroup.imageId == imageId + + where: + cloudProvider | imageId + "titus" | "docker" + "aws" | "ami-name-from-findimage" + } + }