Search in sources :

Example 1 with EnvironmentValidationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentValidationDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure.

@Test
void testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure() {
    int numberOfSubnets = 2;
    AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, numberOfSubnets);
    EnvironmentDto environmentDto = new EnvironmentDto();
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(Map.of(networkDto.getSubnetIds().stream().findFirst().get(), new CloudSubnet()));
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateDuringFlow(environmentValidationDto, networkDto, resultBuilder);
    NetworkTestUtils.checkErrorsPresent(resultBuilder, List.of("If networkId (aNetworkId) and resourceGroupName (aResourceGroupId) are specified then" + " subnet ids must be specified and should exist on azure as well. Given subnetids: [\"key1\", \"key0\"], existing ones: [\"key1\"]"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 2 with EnvironmentValidationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentValidationDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndMultipleResourceGroup.

@Test
void testValidateDuringFlowWhenPrivateEndpointAndMultipleResourceGroup() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
    NetworkDto networkDto = getNetworkDto(azureParams);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
    when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
    EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(null, ResourceGroupUsagePattern.USE_MULTIPLE);
    underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
    assertTrue(validationResultBuilder.build().hasError());
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("Private endpoint creation is not supported for multiple resource group deployment model, please use single single " + "resource groups to be able to use private endpoints in Azure!"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 3 with EnvironmentValidationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentValidationDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndNetworkLinkAlreadyExists.

@Test
void testValidateDuringFlowWhenPrivateEndpointAndNetworkLinkAlreadyExists() {
    ValidationResultBuilder envValidationResultBuilder = new ValidationResultBuilder();
    ValidationResultBuilder azureValidationResultBuilder = new ValidationResultBuilder();
    String message = "Network link for the network aNetworkLink already exists for Private DNS Zone " + "privatelink.postgres.database.azure.com in resource group mySingleRg. Please ensure that there is no existing network link and try again!";
    EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
    AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
    NetworkDto networkDto = getNetworkDto(azureParams);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
    when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
    when(azureNetworkLinkService.validateExistingNetworkLink(any(), any(), eq(MY_SINGLE_RG))).thenReturn(azureValidationResultBuilder.error(message).build());
    underTest.validateDuringFlow(environmentValidationDto, networkDto, envValidationResultBuilder);
    assertTrue(envValidationResultBuilder.build().hasError());
    NetworkTestUtils.checkErrorsPresent(envValidationResultBuilder, List.of(message));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 4 with EnvironmentValidationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentValidationDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenEnvironmentIsBeingCreatedThenPrivateEndpointValidationsRun.

@Test
void testValidateDuringFlowWhenEnvironmentIsBeingCreatedThenPrivateEndpointValidationsRun() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
    NetworkDto networkDto = getNetworkDto(azureParams);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
    when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
    EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
    environmentValidationDto.setValidationType(ValidationType.ENVIRONMENT_CREATION);
    underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
    verify(azureNetworkLinkService, atLeastOnce()).validateExistingNetworkLink(any(), any(), any());
    verify(azureCloudSubnetParametersService, atLeastOnce()).isPrivateEndpointNetworkPoliciesDisabled(any());
    assertFalse(validationResultBuilder.build().hasError());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 5 with EnvironmentValidationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentValidationDto in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesEnabled.

@Test
void testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesEnabled() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    AzureParams azureParams = getAzureParams("networkId", "networkResourceGroupName");
    NetworkDto networkDto = NetworkTestUtils.getNetworkDtoBuilder(azureParams, null, null, azureParams.getNetworkId(), null, 1, RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED_PRIVATE_ENDPOINT).build();
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(true));
    when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
    EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
    underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
    assertTrue(validationResultBuilder.build().hasError());
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("It is not possible to create private endpoints for existing network with id 'networkId' in resource group 'networkResourceGroupName': " + "Azure requires at least one subnet with private endpoint network policies (eg. NSGs) disabled.  Please disable private endpoint " + "network policies in at least one of the following subnets and retry: 'subnet-one'. Refer to Microsoft documentation at: " + "https://docs.microsoft.com/en-us/azure/private-link/disable-private-endpoint-network-policy"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)78 Test (org.junit.jupiter.api.Test)72 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)70 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)39 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)34 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)22 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)13 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)10 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)8 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)4 Environment (com.sequenceiq.environment.environment.domain.Environment)4 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)4 EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)3 AwsParams (com.sequenceiq.environment.network.dto.AwsParams)3 Supplier (java.util.function.Supplier)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CloudEncryptionKey (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKey)2 CloudEncryptionKeys (com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys)2