Search in sources :

Example 11 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestDocumentDB method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "documentdb-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/documentdb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("MasterUserPassword").withParameterValue("Test!1234"));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 12 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestElastiCacheMemcached method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "elasticache-memcached-" + this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/elasticache-memcached.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 13 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestAL2MutablePrivate method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String natStackName = "vpc-nat-gateway-" + this.random8String();
    final String stackName = "al2-mutable-private-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
        try {
            this.createStack(context, natStackName, "vpc/vpc-nat-gateway.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "ec2/al2-mutable-private.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("BackupRetentionPeriod").withParameterValue("0"));
            // TODO how can we check if this stack works?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, natStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 14 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestECSCluster method testDefault.

@Test
public void testDefault() {
    final Context context = new Context();
    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(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, 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("Container instances ready", this.retry(context, callable));
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) 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 15 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestECSCluster method testCostOptimized.

@Test
public void testCostOptimized() {
    final Context context = new Context();
    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(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, stackName, "ecs/cluster-cost-optimized.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("Container instances ready", this.retry(context, callable));
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) 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)

Aggregations

Context (de.widdix.awscftemplates.Context)70 Test (org.junit.Test)70 Parameter (com.amazonaws.services.cloudformation.model.Parameter)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)62 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)2 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)2 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)2 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)2 Session (com.jcraft.jsch.Session)1 Ignore (org.junit.Ignore)1