Search in sources :

Example 11 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenNoSecurityGroupAndNoPortAndMultipleCidr.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenNoSecurityGroupAndNoPortAndMultipleCidr(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withNetworkCidrs(List.of(CIDR_1, CIDR_2)).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).doesNotContain("\"PortParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupFamilyParameter\": {");
    assertThat(result).doesNotContain("\"VPCSecurityGroupsParameter\": {");
    assertThat(result).contains("\"DBSecurityGroupNameParameter\": {");
    assertThat(result).contains("\"VPCIdParameter\": {");
    assertThat(result).contains("\"VPCSecurityGroup\": {");
    assertThat(result).contains("\"FromPort\": 5432,");
    assertThat(result).contains("\"ToPort\" : 5432,");
    assertThat(result).doesNotContain("\"FromPort\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).doesNotContain("\"ToPort\" : { \"Ref\": \"PortParameter\" },");
    assertThat(result).contains(String.format("\"CidrIp\" : \"%s\"", CIDR_1));
    assertThat(result).contains(String.format("\"CidrIp\" : \"%s\"", CIDR_2));
    assertThat(result).doesNotContain("\"DBParameterGroup\": {");
    assertThat(result).doesNotContain("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
    assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).doesNotContain("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
    assertThat(result).contains("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
    assertThat(result).doesNotContain("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with RDSModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndWithSslCertificateIdentifier.

@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndWithSslCertificateIdentifier(String templatePath) throws IOException {
    // GIVEN
    String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
    // WHEN
    RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withUseSslEnforcement(true).withSslCertificateIdentifierDefined(true).withTemplate(awsCloudFormationTemplate);
    String result = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
    assertThat(result).doesNotContain("\"PortParameter\": {");
    assertThat(result).contains("\"DBParameterGroupNameParameter\": {");
    assertThat(result).contains("\"DBParameterGroupFamilyParameter\": {");
    assertThat(result).contains("\"SslCertificateIdentifierParameter\": {");
    assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
    assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
    assertThat(result).doesNotContain("\"VPCIdParameter\": {");
    assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
    assertThat(result).doesNotContain("\"FromPort\"");
    assertThat(result).doesNotContain("\"ToPort\"");
    assertThat(result).doesNotContain("\"CidrIp\" :");
    assertThat(result).contains("\"DBParameterGroup\": {");
    assertThat(result).contains("\"Parameters\": { \"rds.force_ssl\": \"1\" },");
    assertThat(result).contains("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
    assertThat(result).contains("\"CACertificateIdentifier\": { \"Ref\": \"SslCertificateIdentifierParameter\" },");
    assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
    assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
    assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
    assertThat(result).contains("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
Also used : RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RDSModelContext (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 CREATE_FAILED (com.amazonaws.services.cloudformation.model.ResourceStatus.CREATE_FAILED)1 Waiter (com.amazonaws.waiters.Waiter)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AwsCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient)1 AwsStackRequestHelper (com.sequenceiq.cloudbreak.cloud.aws.AwsStackRequestHelper)1 CloudFormationStackUtil (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil)1 CloudFormationTemplateBuilder (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder)1 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)1 StackCancellationCheck (com.sequenceiq.cloudbreak.cloud.aws.scheduler.StackCancellationCheck)1 WaiterRunner.run (com.sequenceiq.cloudbreak.cloud.aws.scheduler.WaiterRunner.run)1 AwsCloudFormationErrorMessageProvider (com.sequenceiq.cloudbreak.cloud.aws.util.AwsCloudFormationErrorMessageProvider)1 AwsRdsInstanceView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsRdsInstanceView)1