Skip to content

Commit

Permalink
feat(cloudformation): add stack as output of CFN stage (#2911)
Browse files Browse the repository at this point in the history
The outputs of a CFN stack are available in the stack object, however we
were not exposing them as the result of the CFN stage. This is usefull
if one stack depends on the outputs of another stack, so we can chain
them.

This patch returns the stack object as a result of a successfull stage,
so it's available in the context for later stages.
  • Loading branch information
Xavi León authored and gardleopard committed Jun 17, 2019
1 parent 30a10c1 commit fe0e621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.netflix.spinnaker.orca.clouddriver.tasks.providers.aws.cloudformation;

import com.netflix.spinnaker.orca.ExecutionStatus;
import com.netflix.spinnaker.orca.OverridableTimeoutRetryableTask;
import com.netflix.spinnaker.orca.TaskResult;
import com.netflix.spinnaker.orca.clouddriver.OortService;
Expand Down Expand Up @@ -47,14 +48,14 @@ public TaskResult execute(@Nonnull Stage stage) {
Map task = ((List<Map>) stage.getContext().get("kato.tasks")).iterator().next();
Map result = ((List<Map>) task.get("resultObjects")).iterator().next();
String stackId = (String) result.get("stackId");
Map stack = oortService.getCloudFormationStack(stackId);
Map<String, ?> stack = (Map<String, Object>) oortService.getCloudFormationStack(stackId);
log.info(
"Received cloud formation stackId "
+ stackId
+ " with status "
+ stack.get("stackStatus"));
if (isComplete(stack.get("stackStatus"))) {
return TaskResult.SUCCEEDED;
return TaskResult.builder(ExecutionStatus.SUCCEEDED).outputs(stack).build();
} else if (isInProgress(stack.get("stackStatus"))) {
return TaskResult.RUNNING;
} else if (isFailed(stack.get("stackStatus"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ class WaitForCloudFormationCompletionTaskSpec extends Specification {
'kato.tasks': [[resultObjects: [[stackId: 'stackId']]]]
]
def stage = new Stage(pipeline, 'test', 'test', context)
def stack = [stackStatus: status]
def stack = [stackId: 'stackId', stackStatus: status] as Map

when:
def result = waitForCloudFormationCompletionTask.execute(stage)

then:
1 * oortService.getCloudFormationStack('stackId') >> stack
result.status == expectedResult
result.outputs == stack

where:
status | expectedResult
Expand All @@ -75,6 +76,7 @@ class WaitForCloudFormationCompletionTaskSpec extends Specification {
then:
1 * oortService.getCloudFormationStack('stackId') >> stack
result.status == expectedResult
result.outputs.isEmpty()

where:
status | expectedResult
Expand All @@ -100,6 +102,7 @@ class WaitForCloudFormationCompletionTaskSpec extends Specification {
then:
1 * oortService.getCloudFormationStack('stackId') >> { throw error404 }
result.status == ExecutionStatus.RUNNING
result.outputs.isEmpty()
}
def "should error on unknown stack status"() {
Expand All @@ -114,12 +117,13 @@ class WaitForCloudFormationCompletionTaskSpec extends Specification {
def stack = [stackStatus: 'UNKNOWN']
when:
waitForCloudFormationCompletionTask.execute(stage)
def result = waitForCloudFormationCompletionTask.execute(stage)
then:
1 * oortService.getCloudFormationStack('stackId') >> stack
RuntimeException ex = thrown()
ex.message.startsWith("Unexpected stack status")
result == null
}
def "should error when clouddriver responds with an error other than 404"() {
Expand All @@ -133,12 +137,13 @@ class WaitForCloudFormationCompletionTaskSpec extends Specification {
def error500 = RetrofitError.httpError("url", new Response("url", 500, "reason", [], null), null, null)
when:
waitForCloudFormationCompletionTask.execute(stage)
def result = waitForCloudFormationCompletionTask.execute(stage)
then:
1 * oortService.getCloudFormationStack('stackId') >> { throw error500 }
RuntimeException ex = thrown()
ex.message == "500 reason"
result == null
}
}

0 comments on commit fe0e621

Please sign in to comment.