Search in sources :

Example 6 with NetworkCidr

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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NetworkCidr

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());
}
Also used : NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with NetworkCidr

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));
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) VpcCidrBlockAssociation(com.amazonaws.services.ec2.model.VpcCidrBlockAssociation) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Test(org.junit.Test)

Example 9 with NetworkCidr

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));
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Test(org.junit.Test)

Example 10 with NetworkCidr

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());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)17 Network (com.sequenceiq.cloudbreak.cloud.model.Network)14 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)8 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)5 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)5 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)4 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)4 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)4 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)4 Credential (com.sequenceiq.environment.credential.domain.Credential)4 Environment (com.sequenceiq.environment.environment.domain.Environment)4 ArrayList (java.util.ArrayList)4 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3