use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testGetNetworkCidrWhenNetworkNull.
@Test
void testGetNetworkCidrWhenNetworkNull() {
Credential credential = mock(Credential.class);
NetworkCidr result = underTest.getNetworkCidr(null, "AWS", credential);
assertNull(result);
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.
@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("GCP");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class EnvironmentInitHandlerTest method testInitSuccess.
@Test
void testInitSuccess() {
EnvironmentDto dto = getEnvironmentDto();
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).build();
dto.setNetwork(networkDto);
Event<EnvironmentDto> event = new Event<>(dto);
Environment environment = getEnvironment();
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
String cidr = "10.0.0.0/16";
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToNetwork(environment.getNetwork())).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(), anyString(), any())).thenReturn(new NetworkCidr(cidr));
when(environmentService.findEnvironmentById(dto.getId())).thenReturn(Optional.of(environment));
Map<UmsVirtualGroupRight, String> virtualGroups = Map.of(UmsVirtualGroupRight.HBASE_ADMIN, "apple1", UmsVirtualGroupRight.ENVIRONMENT_ACCESS, "apple2");
when(virtualGroupService.createVirtualGroups(ACCOUNT_ID, CRN)).thenReturn(virtualGroups);
CloudRegions cloudRegions = new CloudRegions(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), "apple", true);
when(environmentService.getRegionsByEnvironment(environment)).thenReturn(cloudRegions);
environmentInitHandler.accept(event);
assertEquals(cidr, environment.getNetwork().getNetworkCidr());
verify(environmentNetworkService, times(1)).getNetworkCidr(eq(network), eq(CloudPlatform.AWS.name()), eq(environment.getCredential()));
verify(environmentService, times(0)).setAdminGroupName(environment, null);
verify(environmentService, times(1)).assignEnvironmentAdminRole(CREATOR, CRN);
verify(environmentService, times(1)).setLocation(environment, environment.getRegionWrapper(), cloudRegions);
verify(environmentService, times(1)).setRegions(environment, environment.getRegionWrapper().getRegions(), cloudRegions);
verify(environmentService, times(1)).save(environment);
verify(eventSender, times(1)).sendEvent(any(), any());
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testGetNetworkCidrMoreThanOne.
@Test
public void testGetNetworkCidrMoreThanOne() {
String networkId = "vnet-1";
String resourceGroupName = "resourceGroupName";
String cidrBlock1 = "10.0.0.0/16";
String cidrBlock2 = "10.23.0.0/16";
Network network = new Network(null, Map.of(AzureUtils.NETWORK_ID, networkId));
CloudCredential credential = new CloudCredential();
com.microsoft.azure.management.network.Network azureNetwork = mock(com.microsoft.azure.management.network.Network.class);
when(azureClientService.getClient(credential)).thenReturn(azureClient);
when(azureUtils.getCustomResourceGroupName(network)).thenReturn(resourceGroupName);
when(azureUtils.getCustomNetworkId(network)).thenReturn(networkId);
when(azureClient.getNetworkByResourceGroup(resourceGroupName, networkId)).thenReturn(azureNetwork);
when(azureNetwork.addressSpaces()).thenReturn(List.of(cidrBlock1, cidrBlock2));
NetworkCidr result = underTest.getNetworkCidr(network, credential);
assertEquals(cidrBlock1, result.getCidr());
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName.
@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName() {
String networkCidr = "0.0.0.0/16";
Set<NetworkSubnetRequest> subnets = new HashSet<>(Arrays.asList(createSubnetRequest(SUBNET_CIDR_0), createSubnetRequest(SUBNET_CIDR_1)));
Deployment templateDeployment = mock(Deployment.class);
ResourceGroup resourceGroup = mock(ResourceGroup.class);
Map<String, Map> outputs = createOutput();
ArrayList<SubnetRequest> subnetRequests = Lists.newArrayList(publicSubnetRequest("10.0.1.0/24", 0), publicSubnetRequest("10.0.1.0/24", 1));
NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
when(resourceGroup.name()).thenReturn(ENV_NAME);
when(azureSubnetRequestProvider.provide(anyString(), anyList(), anyList(), anyBoolean())).thenReturn(subnetRequests);
when(azureUtils.generateResourceGroupNameByNameAndId(anyString(), anyString())).thenReturn(ENV_NAME);
when(azureClientService.getClient(networkCreationRequest.getCloudCredential())).thenReturn(azureClient);
when(azureNetworkTemplateBuilder.build(networkCreationRequest, subnetRequests, resourceGroup.name())).thenReturn(TEMPLATE);
when(azureClient.createTemplateDeployment(ENV_NAME, STACK_NAME, TEMPLATE, PARAMETER)).thenReturn(templateDeployment);
when(azureClient.createResourceGroup(ENV_NAME, REGION.value(), Collections.emptyMap())).thenReturn(resourceGroup);
when(resourceGroup.name()).thenReturn(ENV_NAME);
when(templateDeployment.outputs()).thenReturn(outputs);
CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
assertEquals(ENV_NAME, actual.getNetworkId());
assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_0)));
assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_1)));
assertTrue(actual.getSubnets().size() == 2);
}
Aggregations