Search in sources :

Example 11 with NetworkDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.

the class GcpNetworkConnectorTest method testDeleteNetworkWithSubnetsWhenDeletionGoesFine.

@Test
public void testDeleteNetworkWithSubnetsWhenDeletionGoesFine() throws Exception {
    NetworkDeletionRequest networkDeletionRequest = new NetworkDeletionRequest.Builder().withAccountId("account-id").withEnvName("super-env").withRegion("us-west-1").withSubnetIds(Set.of("subnet-1")).build();
    GcpContext gcpContext = mock(GcpContext.class);
    PollTask pollTask = mock(PollTask.class);
    CloudResource cloudResource = mock(CloudResource.class);
    when(contextBuilders.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), any(), anyBoolean())).thenReturn(gcpContext);
    when(statusCheckFactory.newPollResourceTask(any(ResourceChecker.class), any(AuthenticatedContext.class), anyList(), any(ResourceBuilderContext.class), anyBoolean())).thenReturn(pollTask);
    when(syncPollingScheduler.schedule(any(PollTask.class))).thenReturn(new ArrayList());
    when(gcpSubnetResourceBuilder.delete(any(GcpContext.class), any(AuthenticatedContext.class), any(CloudResource.class), any(Network.class))).thenReturn(cloudResource);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(gcpSubnetResourceBuilder, times(1)).delete(any(GcpContext.class), any(AuthenticatedContext.class), any(CloudResource.class), any(Network.class));
}
Also used : PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ArrayList(java.util.ArrayList) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ResourceChecker(com.sequenceiq.cloudbreak.cloud.template.ResourceChecker) Test(org.junit.jupiter.api.Test)

Example 12 with NetworkDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldThrowAnExceptionWhenTheStackDeletionFailed.

@Test(expected = CloudConnectorException.class)
public void testDeleteNetworkWithSubnetsShouldThrowAnExceptionWhenTheStackDeletionFailed() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest(false, false);
    when(azureClient.getResourceGroup(networkDeletionRequest.getResourceGroup())).thenReturn(mock(ResourceGroup.class));
    when(azureClientService.getClient(networkDeletionRequest.getCloudCredential())).thenReturn(azureClient);
    when(azureUtils.convertToCloudConnectorException(any(CloudException.class), anyString())).thenReturn(new CloudConnectorException(""));
    doThrow(createCloudException()).when(azureClient).deleteTemplateDeployment(RESOURCE_GROUP, STACK);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) CloudException(com.microsoft.azure.CloudException) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 13 with NetworkDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldDeleteNothingWhenExistingNetwork.

@Test
public void testDeleteNetworkWithSubnetsShouldDeleteNothingWhenExistingNetwork() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest(true, false);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(azureClient, never()).deleteTemplateDeployment(RESOURCE_GROUP, STACK);
    verify(azureClient, never()).deleteResourceGroup(RESOURCE_GROUP);
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.Test)

Example 14 with NetworkDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldCancelDeploymentIfTransientWhenSingleResourceGroup.

@Test
public void testDeleteNetworkWithSubnetsShouldCancelDeploymentIfTransientWhenSingleResourceGroup() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest(false, true);
    when(azureClientService.getClient(networkDeletionRequest.getCloudCredential())).thenReturn(azureClient);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(azureClient).deleteNetworkInResourceGroup(RESOURCE_GROUP, NETWORK_ID);
    verify(azureClient, never()).deleteResourceGroup(RESOURCE_GROUP);
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.Test)

Example 15 with NetworkDeletionRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldDeleteTheStackAndTheResourceGroupWhenNotExistingNetwork.

@Test
public void testDeleteNetworkWithSubnetsShouldDeleteTheStackAndTheResourceGroupWhenNotExistingNetwork() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest(false, false);
    when(azureClient.getResourceGroup(networkDeletionRequest.getResourceGroup())).thenReturn(mock(ResourceGroup.class));
    when(azureClientService.getClient(networkDeletionRequest.getCloudCredential())).thenReturn(azureClient);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(azureClient).deleteTemplateDeployment(RESOURCE_GROUP, STACK);
    verify(azureClient).deleteResourceGroup(RESOURCE_GROUP);
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Aggregations

NetworkDeletionRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest)15 Test (org.junit.Test)10 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 DeleteStackRequest (com.amazonaws.services.cloudformation.model.DeleteStackRequest)3 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 WaiterTimedOutException (com.amazonaws.waiters.WaiterTimedOutException)1 CloudException (com.microsoft.azure.CloudException)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)1 PollTask (com.sequenceiq.cloudbreak.cloud.task.PollTask)1