Search in sources :

Example 6 with UpdateStackSetResult

use of com.amazonaws.services.cloudformation.model.UpdateStackSetResult in project pipeline-aws-plugin by jenkinsci.

the class CFNUpdateStackSetStepTest method updateWithRegionBatches.

@Test
public void updateWithRegionBatches() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stackSet.exists()).thenReturn(true);
    String operationId = UUID.randomUUID().toString();
    Mockito.when(stackSet.update(Mockito.anyString(), Mockito.anyString(), Mockito.any(UpdateStackSetRequest.class))).thenReturn(new UpdateStackSetResult().withOperationId(operationId));
    Mockito.when(stackSet.findStackSetInstances()).thenReturn(asList(new StackInstanceSummary().withAccount("a1").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r1"), new StackInstanceSummary().withAccount("a2").withRegion("r2"), new StackInstanceSummary().withAccount("a3").withRegion("r3")));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  cfnUpdateStackSet(stackSet: 'foo'," + "       pollInterval: 27," + "       batchingOptions: [" + "         regions: true" + "       ]" + "    )" + "}\n", true));
    jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class), Mockito.eq(SleepStrategy.EXPONENTIAL_BACKOFF_STRATEGY));
    ArgumentCaptor<UpdateStackSetRequest> requestCapture = ArgumentCaptor.forClass(UpdateStackSetRequest.class);
    Mockito.verify(stackSet, Mockito.times(3)).update(Mockito.anyString(), Mockito.anyString(), requestCapture.capture());
    Map<String, List<String>> capturedRegionAccounts = requestCapture.getAllValues().stream().flatMap(summary -> summary.getRegions().stream().flatMap(region -> summary.getAccounts().stream().map(accountId -> RegionAccountIdTuple.builder().accountId(accountId).region(region).build()))).collect(Collectors.groupingBy(RegionAccountIdTuple::getRegion, Collectors.mapping(RegionAccountIdTuple::getAccountId, Collectors.toList())));
    Assertions.assertThat(capturedRegionAccounts).containsAllEntriesOf(new HashMap<String, List<String>>() {

        {
            put("r1", asList("a1", "a2"));
            put("r2", singletonList("a2"));
            put("r3", singletonList("a3"));
        }
    });
    Mockito.verify(stackSet, Mockito.times(3)).waitForOperationToComplete(Mockito.any(), Mockito.any());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) UpdateStackSetResult(com.amazonaws.services.cloudformation.model.UpdateStackSetResult) Value(lombok.Value) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) Arrays.asList(java.util.Arrays.asList) AwsSyncClientBuilder(com.amazonaws.client.builder.AwsSyncClientBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Duration(java.time.Duration) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Assertions(org.assertj.core.api.Assertions) EnvVars(hudson.EnvVars) Collector(java.util.stream.Collector) StackInstanceSummary(com.amazonaws.services.cloudformation.model.StackInstanceSummary) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Before(org.junit.Before) AWSClientFactory(de.taimos.pipeline.aws.AWSClientFactory) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrintWriter(java.io.PrintWriter) StackSetSummary(com.amazonaws.services.cloudformation.model.StackSetSummary) TaskListener(hudson.model.TaskListener) UpdateStackSetRequest(com.amazonaws.services.cloudformation.model.UpdateStackSetRequest) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Mockito(org.mockito.Mockito) Tag(com.amazonaws.services.cloudformation.model.Tag) List(java.util.List) Rule(org.junit.Rule) Builder(lombok.Builder) StackSetOperationPreferences(com.amazonaws.services.cloudformation.model.StackSetOperationPreferences) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Collections(java.util.Collections) UpdateStackSetRequest(com.amazonaws.services.cloudformation.model.UpdateStackSetRequest) UpdateStackSetResult(com.amazonaws.services.cloudformation.model.UpdateStackSetResult) StackInstanceSummary(com.amazonaws.services.cloudformation.model.StackInstanceSummary) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UpdateStackSetResult (com.amazonaws.services.cloudformation.model.UpdateStackSetResult)6 UpdateStackSetRequest (com.amazonaws.services.cloudformation.model.UpdateStackSetRequest)5 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)4 TaskListener (hudson.model.TaskListener)4 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)4 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Parameter (com.amazonaws.services.cloudformation.model.Parameter)2 StackSetOperationPreferences (com.amazonaws.services.cloudformation.model.StackSetOperationPreferences)2 PrintWriter (java.io.PrintWriter)2 AwsSyncClientBuilder (com.amazonaws.client.builder.AwsSyncClientBuilder)1 LimitExceededException (com.amazonaws.services.cloudformation.model.LimitExceededException)1 OperationInProgressException (com.amazonaws.services.cloudformation.model.OperationInProgressException)1 StackInstanceSummary (com.amazonaws.services.cloudformation.model.StackInstanceSummary)1 StackSetSummary (com.amazonaws.services.cloudformation.model.StackSetSummary)1 StaleRequestException (com.amazonaws.services.cloudformation.model.StaleRequestException)1 Tag (com.amazonaws.services.cloudformation.model.Tag)1 AWSClientFactory (de.taimos.pipeline.aws.AWSClientFactory)1 EnvVars (hudson.EnvVars)1