Search in sources :

Example 6 with NetworkDeletionRequest

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

the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldNotCancelDeploymentIfNotTransientWhenSingleResourceGroup.

@Test
public void testDeleteNetworkWithSubnetsShouldNotCancelDeploymentIfNotTransientWhenSingleResourceGroup() {
    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);
    verify(azureClient, never()).getTemplateDeployment(RESOURCE_GROUP, STACK);
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.Test)

Example 7 with NetworkDeletionRequest

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

the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsShouldDeleteTheStackAndTheResourceGroup.

@Test
public void testDeleteNetworkWithSubNetsShouldDeleteTheStackAndTheResourceGroup() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
    AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
    when(cfClient.waiters()).thenReturn(cfWaiters);
    when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(true);
    when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(cfClient).deleteStack(any(DeleteStackRequest.class));
    verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
    verify(deletionWaiter, times(1)).run(any());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) DeleteStackRequest(com.amazonaws.services.cloudformation.model.DeleteStackRequest) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.Test)

Example 8 with NetworkDeletionRequest

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

the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed.

@Test(expected = CloudConnectorException.class)
public void testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
    AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
    when(cfClient.waiters()).thenReturn(cfWaiters);
    when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(true);
    when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter);
    doThrow(new WaiterTimedOutException("fail")).when(deletionWaiter).run(any());
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(cfClient).deleteStack(any(DeleteStackRequest.class));
    verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) WaiterTimedOutException(com.amazonaws.waiters.WaiterTimedOutException) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) DeleteStackRequest(com.amazonaws.services.cloudformation.model.DeleteStackRequest) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.Test)

Example 9 with NetworkDeletionRequest

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

the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsWhenCfStackDoesNotExist.

@Test
public void testDeleteNetworkWithSubNetsWhenCfStackDoesNotExist() {
    NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
    AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
    when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(false);
    underTest.deleteNetworkWithSubnets(networkDeletionRequest);
    verify(cfClient, never()).deleteStack(any(DeleteStackRequest.class));
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) DeleteStackRequest(com.amazonaws.services.cloudformation.model.DeleteStackRequest) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) Test(org.junit.Test)

Example 10 with NetworkDeletionRequest

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

the class EnvironmentNetworkServiceTest method testDeleteNetworkShouldDeleteTheNetworkWithResourceGroupWhenUsagePatternMultiple.

@Test
void testDeleteNetworkShouldDeleteTheNetworkWithResourceGroupWhenUsagePatternMultiple() {
    CloudCredential cloudCredential = new CloudCredential("1", "credName", "account");
    EnvironmentDto environmentDto = createEnvironmentDto("resourceGroup");
    when(cloudConnector.networkConnector()).thenReturn(networkConnector);
    when(credentialToCloudCredentialConverter.convert(environmentDto.getCredential())).thenReturn(cloudCredential);
    when(networkCreationRequestFactory.getStackName(any())).thenReturn(STACK_NAME);
    underTest.deleteNetwork(environmentDto);
    ArgumentCaptor<NetworkDeletionRequest> argumentCaptor = ArgumentCaptor.forClass(NetworkDeletionRequest.class);
    verify(networkConnector).deleteNetworkWithSubnets(argumentCaptor.capture());
    assertEquals(STACK_NAME, argumentCaptor.getValue().getStackName());
    assertEquals(cloudCredential, argumentCaptor.getValue().getCloudCredential());
    assertEquals(environmentDto.getLocation().getName(), argumentCaptor.getValue().getRegion());
    assertEquals(environmentDto.getNetwork().getAzure().getResourceGroupName(), argumentCaptor.getValue().getResourceGroup());
    assertFalse(argumentCaptor.getValue().isSingleResourceGroup());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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