Search in sources :

Example 41 with ModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestInstanceGroupsWhenRootVolumeSizeIsSuperSmall.

@Test
public void buildTestInstanceGroupsWhenRootVolumeSizeIsSuperSmall() throws IOException {
    // GIVEN
    int rootVolumeSize = Integer.MIN_VALUE;
    Security security = getDefaultCloudStackSecurity();
    List<Group> groups = List.of(createDefaultGroup("master", InstanceGroupType.CORE, rootVolumeSize, security, Optional.empty()), createDefaultGroup("gateway", InstanceGroupType.GATEWAY, rootVolumeSize, security, Optional.empty()));
    CloudStack cloudStack = createDefaultCloudStack(groups, getDefaultCloudStackParameters(), getDefaultCloudStackTags());
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
    assertThat(templateString, containsString(Integer.toString(rootVolumeSize)));
    JsonNode firstBlockDeviceMapping = getJsonNode(JsonUtil.readTree(templateString), "BlockDeviceMappings").get(0);
    String volumeSize = getJsonNode(firstBlockDeviceMapping, "VolumeSize").textValue();
    Assertions.assertThat(Integer.valueOf(volumeSize)).isEqualTo(rootVolumeSize);
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Group(com.sequenceiq.cloudbreak.cloud.model.Group) JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.containsString(org.hamcrest.Matchers.containsString) Security(com.sequenceiq.cloudbreak.cloud.model.Security) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.jupiter.api.Test)

Example 42 with ModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestWithVPCAndRoleWithoutIGWAndPublicIpOnLaunchAndInstanceProfile.

@Test
public void buildTestWithVPCAndRoleWithoutIGWAndPublicIpOnLaunchAndInstanceProfile() {
    CloudStack cloudStack = initCloudStackWithInstanceProfile();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(false).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(false).withEnableInstanceProfile(false).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
    assertThat(templateString, containsString("InstanceProfile"));
    assertThat(templateString, containsString("VPCId"));
    assertThat(templateString, not(containsString("SubnetCIDR")));
    assertThat(templateString, containsString("SubnetId"));
    assertThat(templateString, not(containsString("SubnetConfig")));
    assertThat(templateString, not(containsString("\"AttachGateway\"")));
    assertThat(templateString, not(containsString("\"InternetGateway\"")));
    assertThat(templateString, containsString("AvailabilitySet"));
    assertThat(templateString, containsString("SecurityGroupIngress"));
    assertThat(templateString, not(containsString("EIP")));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.jupiter.api.Test)

Example 43 with ModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestNoOutboundInternetTrafficBothVpcCidrsAndPrefixListsAreGiven.

@Test
public void buildTestNoOutboundInternetTrafficBothVpcCidrsAndPrefixListsAreGiven() {
    // GIVEN
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.DISABLED).withVpcCidrs(List.of("vpccidr1", "vpccidr2")).withPrefixListIds(List.of("prefix1", "prefix2")).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
    assertThat(templateString, containsString("SecurityGroupIngress"));
    assertThat(templateString, stringContainsInOrder("SecurityGroupEgress", "vpccidr1", "vpccidr2", "prefix1", "prefix2"));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 44 with ModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestNoEbsEncryption.

@Test
public void buildTestNoEbsEncryption() {
    // GIVEN
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(templateString).matches(JsonUtil::isValid, "Invalid JSON: " + templateString).doesNotContain("\"Encrypted\"").contains("SecurityGroupIngress").contains("{ \"Ref\" : \"AMI\" }");
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 45 with ModelContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestWithInstanceProfileAndRoleWithoutVPCAndIGWAndPublicIpOnLaunch.

@Test
public void buildTestWithInstanceProfileAndRoleWithoutVPCAndIGWAndPublicIpOnLaunch() {
    CloudStack cloudStack = initCloudStackWithInstanceProfile();
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(false).withExistingIGW(false).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(false).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
    assertThat(templateString, containsString("InstanceProfile"));
    assertThat(templateString, not(containsString("VPCId")));
    assertThat(templateString, not(containsString("SubnetCIDR")));
    assertThat(templateString, containsString("SubnetId"));
    assertThat(templateString, containsString("SubnetConfig"));
    assertThat(templateString, containsString("\"AttachGateway\""));
    assertThat(templateString, containsString("\"InternetGateway\""));
    assertThat(templateString, containsString("AvailabilitySet"));
    assertThat(templateString, containsString("SecurityGroupIngress"));
    assertThat(templateString, not(containsString("EIP")));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.jupiter.api.Test)

Aggregations

ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)47 Matchers.containsString (org.hamcrest.Matchers.containsString)44 Test (org.junit.jupiter.api.Test)43 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)20 Group (com.sequenceiq.cloudbreak.cloud.model.Group)9 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)9 Security (com.sequenceiq.cloudbreak.cloud.model.Security)8 ArrayList (java.util.ArrayList)6 AwsLoadBalancer (com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancer)5 Network (com.sequenceiq.cloudbreak.cloud.model.Network)5 AwsEfsFileSystem (com.sequenceiq.cloudbreak.cloud.aws.common.efs.AwsEfsFileSystem)3 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)3 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)3 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)3 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)2 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2