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

fix(findImage) : Fix child deploy to use correct find image when clou… #2960

Merged
merged 5 commits into from
Jun 10, 2019
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 @@ -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"
}

}