use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestEbsEncryptionWithDefaultKey.
@Test
public void buildTestEbsEncryptionWithDefaultKey() {
// GIVEN
instance.getTemplate().putParameter(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true);
instance.getTemplate().putParameter(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name());
// 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).contains("\"Encrypted\"").contains("{ \"Ref\" : \"AMI\" }").contains("SecurityGroupIngress").doesNotContain("\"KmsKeyId\"");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestInstanceGroupsWithSpotInstancesWithMaxPrice.
@Test
public void buildTestInstanceGroupsWithSpotInstancesWithMaxPrice() {
// GIVEN
List<Group> groups = new ArrayList<>();
Security security = getDefaultCloudStackSecurity();
groups.add(createDefaultGroup("master", InstanceGroupType.CORE, ROOT_VOLUME_SIZE, security, Optional.empty()));
InstanceTemplate spotInstanceTemplate = createDefaultInstanceTemplate();
spotInstanceTemplate.putParameter(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, 60);
spotInstanceTemplate.putParameter(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE, 0.9);
CloudInstance spotInstance = new CloudInstance("SOME_ID", spotInstanceTemplate, instanceAuthentication, "subnet-1", "az1");
groups.add(new Group("compute", InstanceGroupType.CORE, singletonList(spotInstance), security, spotInstance, instanceAuthentication, instanceAuthentication.getLoginUserName(), "publickey", ROOT_VOLUME_SIZE, Optional.empty(), createGroupNetwork(), emptyMap()));
groups.add(createDefaultGroup("gateway", InstanceGroupType.GATEWAY, ROOT_VOLUME_SIZE, 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
Assert.assertTrue("Invalid JSON: " + templateString, JsonUtil.isValid(templateString));
assertThat(templateString, stringContainsInOrder("OnDemandPercentageAboveBaseCapacity", "40"));
assertThat(templateString, containsString("SecurityGroupIngress"));
assertThat(templateString, stringContainsInOrder("SpotMaxPrice", "0.9"));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestWithVPCAndIGWAndRoleWithoutPublicIpOnLaunchAndInstanceProfile.
@Test
public void buildTestWithVPCAndIGWAndRoleWithoutPublicIpOnLaunchAndInstanceProfile() {
CloudStack cloudStack = initCloudStackWithInstanceProfile();
// WHEN
modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).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")));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestWithVPCAndIGWAndPublicIpOnLaunchWithoutInstanceProfileAndRole.
@Test
public void buildTestWithVPCAndIGWAndPublicIpOnLaunchWithoutInstanceProfileAndRole() {
// WHEN
modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(List.of(existingSubnetCidr)).mapPublicIpOnLaunch(true).withEnableInstanceProfile(false).withInstanceProfileAvailable(false).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
String templateString = cloudFormationTemplateBuilder.build(modelContext);
// THEN
Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
assertThat(templateString, not(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, containsString("EIP"));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderTest method buildTestWithInstanceProfileWithoutVPCAndIGWAndPublicIpOnLaunchAndRole.
@Test
public void buildTestWithInstanceProfileWithoutVPCAndIGWAndPublicIpOnLaunchAndRole() {
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(false).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")));
}
Aggregations