-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clouddriver): Fixing trigger interaction inside deploy strategy c…
…odepaths
- Loading branch information
1 parent
226e9a7
commit 5afdaa8
Showing
4 changed files
with
177 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,27 @@ | |
|
||
package com.netflix.spinnaker.orca.kato.pipeline | ||
|
||
import com.netflix.spinnaker.orca.pipeline.model.Execution | ||
import com.netflix.spinnaker.orca.pipeline.model.JenkinsTrigger | ||
import com.netflix.spinnaker.orca.pipeline.model.PipelineTrigger | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline | ||
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage | ||
|
||
class ParallelDeployStageSpec extends Specification { | ||
|
||
@Unroll | ||
def "should build contexts corresponding to cluster configuration(s)"() { | ||
given: | ||
def bakeStage = new Stage(Execution.newPipeline("orca"), "deploy", "Deploy!", stageContext) | ||
def pipeline = pipeline { | ||
trigger = new JenkinsTrigger("master", "job", 1, null, [:], new JenkinsTrigger.BuildInfo( | ||
"job", 1, "http://url", [], [], "job", false, "result" | ||
), "[email protected]", [:], []) | ||
application = "orca" | ||
} | ||
def bakeStage = new Stage(pipeline, "deploy", "Deploy!", stageContext) | ||
def builder = new ParallelDeployStage() | ||
|
||
when: | ||
|
@@ -45,6 +56,135 @@ class ParallelDeployStageSpec extends Specification { | |
[account: "prod", restrictedExecutionWindow: [:], cluster: [availabilityZones: ["europe-west1-b": []], cloudProvider: "gce"], type: "createServerGroup", name: "Deploy in europe-west1-b"]] | ||
} | ||
|
||
@Unroll | ||
def "pipeline strategy should #data.scenario"() { | ||
given: | ||
def parentPipeline = pipeline { | ||
trigger = new JenkinsTrigger("master", "job", 1, null, [:], new JenkinsTrigger.BuildInfo( | ||
"job", 1, "http://url", [], [], "job", false, "result" | ||
), "[email protected]", [:], []) | ||
application = "orca" | ||
stage { | ||
name = "parent stage" | ||
type = "createServerGroup" | ||
refId = "parentStage" | ||
context = [ | ||
account: "prod", | ||
availabilityZones: ["us-west-1": []], | ||
cloudProvider: "aws", | ||
restrictedExecutionWindow: [:] | ||
].with { putAll(data.parentStageContext); it } | ||
} | ||
} | ||
|
||
def strategyPipeline = pipeline { | ||
trigger = new PipelineTrigger( | ||
parentPipeline, | ||
parentPipeline.stageByRef("parentStage").id, | ||
"[email protected]", | ||
data.triggerParams.with { putAll([strategy: true, parentStageId: parentPipeline.stageByRef("parentStage").id]); it }, | ||
[] | ||
) | ||
} | ||
|
||
and: | ||
def deployStage = new Stage(strategyPipeline, "deploy", "Deploy!", data.stageContext) | ||
def builder = new ParallelDeployStage() | ||
|
||
when: | ||
def parallelContexts = builder.parallelContexts(deployStage) | ||
|
||
then: | ||
parallelContexts == data.expectedParallelContexts | ||
|
||
where: | ||
data << [ | ||
[ | ||
scenario: "pull contexts from trigger when missing from parent", | ||
parentStageContext: [:], | ||
stageContext: [:], | ||
triggerParams: [ | ||
amiName: "ami-1234" | ||
], | ||
expectedParallelContexts: [ | ||
[ | ||
name: "Deploy in us-west-1", | ||
cluster: [ | ||
account: "prod", | ||
availabilityZones: ["us-west-1": []], | ||
cloudProvider: "aws", | ||
restrictedExecutionWindow: [:], | ||
strategy: "none", | ||
amiName: "ami-1234", | ||
], | ||
type: "createServerGroup", | ||
account: "prod" | ||
] | ||
] | ||
], | ||
[ | ||
scenario: "inherit traffic options from parent", | ||
parentStageContext: [ | ||
amiName: "ami-1234", | ||
trafficOptions: "enable", | ||
suspendedProcesses: [], | ||
], | ||
stageContext: [ | ||
trafficOptions: "inherit" | ||
], | ||
triggerParams: [:], | ||
expectedParallelContexts: [ | ||
[ | ||
name: "Deploy in us-west-1", | ||
cluster: [ | ||
account: "prod", | ||
availabilityZones: ["us-west-1": []], | ||
cloudProvider: "aws", | ||
restrictedExecutionWindow: [:], | ||
strategy: "none", | ||
amiName: "ami-1234", | ||
trafficOptions: "enable", | ||
suspendedProcesses: [], | ||
], | ||
trafficOptions: "inherit", | ||
type: "createServerGroup", | ||
account: "prod" | ||
] | ||
] | ||
], | ||
[ | ||
scenario: "override traffic options in parent", | ||
parentStageContext: [ | ||
amiName: "ami-1234", | ||
trafficOptions: "disable", | ||
suspendedProcesses: ['AddToLoadBalancer'], | ||
], | ||
stageContext: [ | ||
trafficOptions: "enable" | ||
], | ||
triggerParams: [:], | ||
expectedParallelContexts: [ | ||
[ | ||
name: "Deploy in us-west-1", | ||
cluster: [ | ||
account: "prod", | ||
availabilityZones: ["us-west-1": []], | ||
cloudProvider: "aws", | ||
restrictedExecutionWindow: [:], | ||
strategy: "none", | ||
amiName: "ami-1234", | ||
trafficOptions: "disable", | ||
suspendedProcesses: [] | ||
], | ||
account: "prod", | ||
trafficOptions: "enable", | ||
type: "createServerGroup", | ||
] | ||
] | ||
] | ||
] | ||
} | ||
|
||
Map deployStageContext(String account, String cloudProvider, String... availabilityZones) { | ||
def context = ["account": account, restrictedExecutionWindow: [:]] | ||
if (availabilityZones.size() == 1) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ class ExecutionBuilder { | |
@DelegatesTo(value = Execution, strategy = DELEGATE_FIRST) | ||
Closure builder = {}) { | ||
def pipeline = Execution.newPipeline("covfefe") | ||
pipeline.trigger = new ManualTrigger(null, null, [:], [], []) | ||
pipeline.trigger = new ManualTrigger(null, "[email protected]", [:], [], []) | ||
pipeline.buildTime = currentTimeMillis() | ||
|
||
builder.delegate = pipeline | ||
|