Skip to content

Commit

Permalink
fix(FindImageFromCluster): only infer regions from deploy for aws
Browse files Browse the repository at this point in the history
  • Loading branch information
asher committed Apr 20, 2019
1 parent 6294310 commit b92672f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ class FindImageFromClusterTask extends AbstractCloudProviderAwareTask implements
def deployRegions = regionCollector.getRegionsFromChildStages(stage)
Set<String> inferredRegions = new HashSet<>()

deployRegions.forEach {
if (!config.regions.contains(it)) {
config.regions.add(it)
inferredRegions.add(it)
log.info("Inferred and added region ($it) from deploy stage to FindImageFromClusterTask (executionId: ${stage.execution.id})")
if (cloudProvider == 'aws') {
deployRegions.forEach {
if (!config.regions.contains(it)) {
config.regions.add(it)
inferredRegions.add(it)
log.info("Inferred and added region ($it) from deploy stage to FindImageFromClusterTask (executionId: ${stage.execution.id})")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ class FindImageFromClusterTaskSpec extends Specification {
['foo-x86_64-201603232351'] | ['foo-x86_64-201603232351'] as Set
}

@Unroll
def "should resolve images via find if not all regions exist in source server group"() {
given:
def pipe = pipeline {
application = "contextAppName" // Should be ignored.
}
def stage = new Stage(pipe, "findImage", [
resolveMissingLocations: true,
cloudProvider : "cloudProvider",
cloudProvider : cloudProvider,
cluster : "foo-test",
account : "test",
selectionStrategy : "LARGEST",
Expand All @@ -204,21 +205,28 @@ class FindImageFromClusterTaskSpec extends Specification {
def result = task.execute(stage)

then:
1 * oortService.getServerGroupSummary("foo", "test", "foo-test", "cloudProvider", location1.value,
1 * oortService.getServerGroupSummary("foo", "test", "foo-test", cloudProvider, location1.value,
"LARGEST", FindImageFromClusterTask.SUMMARY_TYPE, false.toString()) >> oortResponse1
1 * oortService.getServerGroupSummary("foo", "test", "foo-test", "cloudProvider", location2.value,
findCalls * oortService.getServerGroupSummary("foo", "test", "foo-test", cloudProvider, location2.value,
"LARGEST", FindImageFromClusterTask.SUMMARY_TYPE, false.toString()) >> {
throw RetrofitError.httpError("http://clouddriver", new Response("http://clouddriver", 404, 'Not Found', [], new TypedString("{}")), null, Map)
}
1 * oortService.findImage("cloudProvider", "ami-012-name-ebs*", "test", null, null) >> imageSearchResult
findCalls * oortService.findImage(cloudProvider, "ami-012-name-ebs*", "test", null, null) >> imageSearchResult
1 * regionCollector.getRegionsFromChildStages(stage) >> regionCollectorResponse

assertNorth(result.outputs?.deploymentDetails?.find {
it.region == "north"
} as Map, [imageName: "ami-012-name-ebs"])
assertSouth(result.outputs?.deploymentDetails?.find {
it.region == "south"
} as Map, [sourceServerGroup: "foo-test", imageName: "ami-012-name-ebs1", foo: "bar"])

if (cloudProvider == "aws") {
assertSouth(result.outputs?.deploymentDetails?.find {
it.region == "south"
} as Map, [sourceServerGroup: "foo-test", imageName: "ami-012-name-ebs1", foo: "bar"])
} else {
assert !result.outputs?.deploymentDetails?.any {
it.region == "south"
}
}

where:
location1 = new Location(type: Location.Type.REGION, value: "north")
Expand Down Expand Up @@ -250,6 +258,10 @@ class FindImageFromClusterTaskSpec extends Specification {
]
]
]

cloudProvider || findCalls
"aws" || 1
"gcp" || 0
}

def "should resolve images via find if not all regions exist in source server group without build info"() {
Expand Down

0 comments on commit b92672f

Please sign in to comment.