Search in sources :

Example 1 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestEC2AutoRecovery method test.

@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "ec2-auto-recovery-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(stackName, "ec2/ec2-auto-recovery.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                final String host = this.getStackOutputValue(stackName, "IPAddress");
                this.probeSSH(host, key);
            } finally {
                this.deleteStack(stackName);
            }
        } finally {
            this.deleteStack(vpcStackName);
        }
    } finally {
        this.deleteKey(keyName);
    }
}
Also used : KeyPair(com.amazonaws.services.ec2.model.KeyPair) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 2 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.

the class TestECSCluster method test.

@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "ecs-cluster-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(stackName, "ecs/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                final String cluster = this.getStackOutputValue(stackName, "Cluster");
                final Callable<Boolean> callable = () -> {
                    final ListContainerInstancesResult res1 = this.ecs.listContainerInstances(new ListContainerInstancesRequest().withCluster(cluster));
                    final DescribeContainerInstancesResult res2 = this.ecs.describeContainerInstances(new DescribeContainerInstancesRequest().withCluster(cluster).withContainerInstances(res1.getContainerInstanceArns()));
                    // check container instances
                    if (res2.getContainerInstances().size() != 2) {
                        throw new RuntimeException("2 instances expected, but saw " + res2.getContainerInstances().size());
                    }
                    if (!res2.getContainerInstances().get(0).getStatus().equals("ACTIVE")) {
                        throw new RuntimeException("container 0 status expected ACTIVE, but saw " + res2.getContainerInstances().get(0).getStatus());
                    }
                    if (!res2.getContainerInstances().get(0).getAgentConnected()) {
                        throw new RuntimeException("container 0 agent expected connected, but saw " + res2.getContainerInstances().get(0).getAgentConnected());
                    }
                    if (!res2.getContainerInstances().get(1).getStatus().equals("ACTIVE")) {
                        throw new RuntimeException("container 1 status expected ACTIVE, but saw " + res2.getContainerInstances().get(1).getStatus());
                    }
                    if (!res2.getContainerInstances().get(1).getAgentConnected()) {
                        throw new RuntimeException("container 1 agent expected connected, but saw " + res2.getContainerInstances().get(1).getAgentConnected());
                    }
                    return true;
                };
                Assert.assertTrue(this.retry(callable));
            } finally {
                this.deleteStack(stackName);
            }
        } finally {
            this.deleteStack(vpcStackName);
        }
    } finally {
        this.deleteKey(keyName);
    }
}
Also used : ListContainerInstancesResult(com.amazonaws.services.ecs.model.ListContainerInstancesResult) Parameter(com.amazonaws.services.cloudformation.model.Parameter) DescribeContainerInstancesResult(com.amazonaws.services.ecs.model.DescribeContainerInstancesResult) ListContainerInstancesRequest(com.amazonaws.services.ecs.model.ListContainerInstancesRequest) DescribeContainerInstancesRequest(com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 3 with Parameter

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

the class CFNCreateChangeSetTests method createChangeSetStackParametersFromMap.

@Test
public void createChangeSetStackParametersFromMap() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stack.exists()).thenReturn(true);
    Mockito.when(stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', params: ['foo': 'bar', 'baz': 'true'])\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.eq(Arrays.asList(new Parameter().withParameterKey("foo").withParameterValue("bar"), new Parameter().withParameterKey("baz").withParameterValue("true"))), Mockito.anyCollectionOf(Tag.class), Mockito.anyInt(), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Parameter

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

the class JSONParameterFileParserTests method parseParameters.

@Test
public void parseParameters() throws IOException {
    JSONParameterFileParser parser = new JSONParameterFileParser();
    String json = "[{\"ParameterKey\": \"bar\", \"ParameterValue\": \"foo\"}]";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo"));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 5 with Parameter

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

the class JSONParameterFileParserTests method parseKeyParameters.

@Test
public void parseKeyParameters() throws IOException {
    JSONParameterFileParser parser = new JSONParameterFileParser();
    String json = "[{\"ParameterKey\": \"bar\", \"UsePreviousValue\": true}]";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withUsePreviousValue(true));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Aggregations

Parameter (com.amazonaws.services.cloudformation.model.Parameter)85 Test (org.junit.Test)79 Context (de.widdix.awscftemplates.Context)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)60 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)5 StringInputStream (com.amazonaws.util.StringInputStream)4 ArrayList (java.util.ArrayList)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)3 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)3 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)3 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)3 ParameterProvider (de.taimos.pipeline.aws.cloudformation.ParameterProvider)3 FilePath (hudson.FilePath)3 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 TaskListener (hudson.model.TaskListener)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Change (com.amazonaws.services.cloudformation.model.Change)1