Skip to content

Commit

Permalink
fix(findImage) : Fix child deploy to use correct find image when clou… (
Browse files Browse the repository at this point in the history
#2960)

* fix(findImage) : Fix child deploy to use correct find image when cloud providers differ

* fixup

* adding tests
  • Loading branch information
aravindmd committed Jun 10, 2019
1 parent 50360e3 commit a3005f3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stage> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}

0 comments on commit a3005f3

Please sign in to comment.