Search in sources :

Example 6 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder 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 7 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNoNetworkCidrAndNetworkId.

@Test
void testValidateDuringRequestWhenNoNetworkCidrAndNetworkId() {
    AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateDuringRequest(networkDto, resultBuilder);
    ValidationResult validationResult = resultBuilder.build();
    assertFalse(validationResult.hasError());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkCidrAndNoAzureParams.

@Test
void testValidateDuringRequestWhenNetworkCidrAndNoAzureParams() {
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, null, null, null, "0.0.0.0/0", null);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateDuringRequest(networkDto, resultBuilder);
    ValidationResult validationResult = resultBuilder.build();
    assertFalse(validationResult.hasError(), validationResult.getFormattedErrors());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 9 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotResourceGroupId.

@Test
void testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotResourceGroupId() {
    AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, false);
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("If networkId is specified, then resourceGroupName must be specified too."));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder 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

ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)169 Test (org.junit.jupiter.api.Test)107 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)67 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)62 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)35 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)33 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)33 Test (org.junit.Test)20 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)10 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Credential (com.sequenceiq.environment.credential.domain.Credential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)6 Role (com.amazonaws.services.identitymanagement.model.Role)6 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)6