use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs.
@Test
public void testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs() {
String primaryCidr = "10.0.0.0/16";
String secondaryCidr = "10.2.0.0/16";
AwsNetwork baseNetwork = new AwsNetwork();
baseNetwork.setSubnetMetas(Collections.emptyMap());
baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
environment.setNetwork(baseNetwork);
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
Network network = new Network(new Subnet(primaryCidr));
NetworkCidr networkCidr = new NetworkCidr(primaryCidr, List.of(primaryCidr, secondaryCidr));
when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(environmentNetworkConverter.convertToNetwork(baseNetwork)).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential())).thenReturn(networkCidr);
BaseNetwork actualNetwork = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
verify(cloudNetworkService, times(1)).retrieveSubnetMetadata(eq(environment), any(NetworkDto.class));
verify(environmentNetworkService, times(1)).getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
Assertions.assertEquals(primaryCidr, actualNetwork.getNetworkCidr());
Assertions.assertEquals(StringUtils.join(networkCidr.getCidrs(), ","), actualNetwork.getNetworkCidrs());
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testGetNetworkCidr.
@Test
public void testGetNetworkCidr() {
String networkId = "vnet-1";
String resourceGroupName = "resourceGroupName";
String cidrBlock = "10.0.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(cidrBlock));
NetworkCidr result = underTest.getNetworkCidr(network, credential);
assertEquals(cidrBlock, result.getCidr());
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testGetNetworkCidrWithDuplicatedCidr.
@Test
public void testGetNetworkCidrWithDuplicatedCidr() {
String existingVpc = "vpc-1";
String cidrBlock = "10.0.0.0/16";
Network network = new Network(null, Map.of(NetworkConstants.VPC_ID, existingVpc, "region", "us-west-2"));
CloudCredential credential = new CloudCredential();
AmazonEc2Client amazonEC2Client = mock(AmazonEc2Client.class);
DescribeVpcsResult describeVpcsResult = describeVpcsResult(cidrBlock, cidrBlock);
describeVpcsResult.getVpcs().get(0).getCidrBlockAssociationSet().add(new VpcCidrBlockAssociation().withCidrBlock(cidrBlock));
when(awsClient.createEc2Client(any(AwsCredentialView.class), eq("us-west-2"))).thenReturn(amazonEC2Client);
when(amazonEC2Client.describeVpcs(new DescribeVpcsRequest().withVpcIds(existingVpc))).thenReturn(describeVpcsResult);
NetworkCidr result = underTest.getNetworkCidr(network, credential);
assertEquals(cidrBlock, result.getCidr());
assertEquals(1, result.getCidrs().size());
assertEquals(cidrBlock, result.getCidrs().get(0));
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testGetNetworkCidrMoreThanOneAssociatedCidrOnOneVpcShouldReturn2Cidr.
@Test
public void testGetNetworkCidrMoreThanOneAssociatedCidrOnOneVpcShouldReturn2Cidr() {
String existingVpc = "vpc-1";
String cidrBlock1 = "10.0.0.0/16";
String cidrBlock2 = "10.23.0.0/16";
Network network = new Network(null, Map.of(NetworkConstants.VPC_ID, existingVpc, "region", "us-west-2"));
CloudCredential credential = new CloudCredential();
AmazonEc2Client amazonEC2Client = mock(AmazonEc2Client.class);
DescribeVpcsResult describeVpcsResult = describeVpcsResult(cidrBlock1, cidrBlock2);
when(awsClient.createEc2Client(any(AwsCredentialView.class), eq("us-west-2"))).thenReturn(amazonEC2Client);
when(amazonEC2Client.describeVpcs(new DescribeVpcsRequest().withVpcIds(existingVpc))).thenReturn(describeVpcsResult);
NetworkCidr result = underTest.getNetworkCidr(network, credential);
assertEquals(cidrBlock1, result.getCidr());
assertTrue(result.getCidrs().contains(cidrBlock1));
assertTrue(result.getCidrs().contains(cidrBlock2));
}
use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testGetNetworkCidr.
@Test
void testGetNetworkCidr() {
Credential credential = mock(Credential.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
Network network = mock(Network.class);
String networkCidr = "10.0.0.0/16";
when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(networkConnector.getNetworkCidr(network, cloudCredential)).thenReturn(new NetworkCidr(networkCidr));
NetworkCidr result = underTest.getNetworkCidr(network, "AWS", credential);
assertEquals(networkCidr, result.getCidr());
}
Aggregations